freya_code_editor/languages.rs
1use std::borrow::Cow;
2
3use tree_sitter::Language;
4
5/// A language definition used for syntax highlighting.
6///
7/// Bring your own tree-sitter grammar and its highlights query, so the editor
8/// can highlight any language without the crate depending on specific grammars.
9///
10/// ```no_run
11/// # use freya_code_editor::prelude::EditorLanguage;
12/// let language = EditorLanguage::new(
13/// tree_sitter_rust::LANGUAGE,
14/// tree_sitter_rust::HIGHLIGHTS_QUERY,
15/// );
16/// ```
17#[derive(Clone)]
18pub struct EditorLanguage {
19 pub language: Language,
20 pub highlights_query: Cow<'static, str>,
21}
22
23impl EditorLanguage {
24 pub fn new(
25 language: impl Into<Language>,
26 highlights_query: impl Into<Cow<'static, str>>,
27 ) -> Self {
28 Self {
29 language: language.into(),
30 highlights_query: highlights_query.into(),
31 }
32 }
33}