|
|
@ -1,12 +1,11 @@
|
|
|
|
use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction};
|
|
|
|
use crate::{regex::Regex, Change, Rope, RopeSlice, Transaction};
|
|
|
|
pub use helix_syntax::{get_language, get_language_name, Lang};
|
|
|
|
pub use helix_syntax::{get_language, get_language_name, Lang};
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
borrow::Cow,
|
|
|
|
borrow::Cow,
|
|
|
|
cell::RefCell,
|
|
|
|
cell::RefCell,
|
|
|
|
collections::{HashMap, HashSet},
|
|
|
|
collections::{HashMap, HashSet},
|
|
|
|
|
|
|
|
fmt,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
sync::Arc,
|
|
|
|
sync::Arc,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -14,15 +13,13 @@ use std::{
|
|
|
|
use once_cell::sync::{Lazy, OnceCell};
|
|
|
|
use once_cell::sync::{Lazy, OnceCell};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
pub struct Configuration {
|
|
|
|
pub struct Configuration {
|
|
|
|
pub language: Vec<LanguageConfiguration>,
|
|
|
|
pub language: Vec<LanguageConfiguration>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// largely based on tree-sitter/cli/src/loader.rs
|
|
|
|
// largely based on tree-sitter/cli/src/loader.rs
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct LanguageConfiguration {
|
|
|
|
pub struct LanguageConfiguration {
|
|
|
|
#[serde(rename = "name")]
|
|
|
|
#[serde(rename = "name")]
|
|
|
@ -50,8 +47,7 @@ pub struct LanguageConfiguration {
|
|
|
|
pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
|
|
|
|
pub(crate) indent_query: OnceCell<Option<IndentQuery>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct LanguageServerConfiguration {
|
|
|
|
pub struct LanguageServerConfiguration {
|
|
|
|
pub command: String,
|
|
|
|
pub command: String,
|
|
|
@ -60,16 +56,14 @@ pub struct LanguageServerConfiguration {
|
|
|
|
pub args: Vec<String>,
|
|
|
|
pub args: Vec<String>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct IndentationConfiguration {
|
|
|
|
pub struct IndentationConfiguration {
|
|
|
|
pub tab_width: usize,
|
|
|
|
pub tab_width: usize,
|
|
|
|
pub unit: String,
|
|
|
|
pub unit: String,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
#[serde(rename_all = "kebab-case")]
|
|
|
|
pub struct IndentQuery {
|
|
|
|
pub struct IndentQuery {
|
|
|
|
#[serde(default)]
|
|
|
|
#[serde(default)]
|
|
|
@ -196,7 +190,7 @@ impl LanguageConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
pub static LOADER: OnceCell<Loader> = OnceCell::new();
|
|
|
|
pub static LOADER: OnceCell<Loader> = OnceCell::new();
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Loader {
|
|
|
|
pub struct Loader {
|
|
|
|
// highlight_names ?
|
|
|
|
// highlight_names ?
|
|
|
|
language_configs: Vec<Arc<LanguageConfiguration>>,
|
|
|
|
language_configs: Vec<Arc<LanguageConfiguration>>,
|
|
|
@ -264,10 +258,9 @@ pub struct TsParser {
|
|
|
|
cursors: Vec<QueryCursor>,
|
|
|
|
cursors: Vec<QueryCursor>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
|
|
|
|
impl fmt::Debug for TsParser {
|
|
|
|
impl fmt::Debug for TsParser {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("TsParser").finish_non_exhaustive()
|
|
|
|
f.debug_struct("TsParser").finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -279,7 +272,7 @@ thread_local! {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Syntax {
|
|
|
|
pub struct Syntax {
|
|
|
|
config: Arc<HighlightConfiguration>,
|
|
|
|
config: Arc<HighlightConfiguration>,
|
|
|
|
|
|
|
|
|
|
|
@ -460,7 +453,7 @@ impl Syntax {
|
|
|
|
// buffer_range_for_scope_at_pos
|
|
|
|
// buffer_range_for_scope_at_pos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LanguageLayer {
|
|
|
|
pub struct LanguageLayer {
|
|
|
|
// mode
|
|
|
|
// mode
|
|
|
|
// grammar
|
|
|
|
// grammar
|
|
|
@ -769,7 +762,7 @@ pub enum HighlightEvent {
|
|
|
|
/// Contains the data neeeded to higlight code written in a particular language.
|
|
|
|
/// Contains the data neeeded to higlight code written in a particular language.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This struct is immutable and can be shared between threads.
|
|
|
|
/// This struct is immutable and can be shared between threads.
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct HighlightConfiguration {
|
|
|
|
pub struct HighlightConfiguration {
|
|
|
|
pub language: Grammar,
|
|
|
|
pub language: Grammar,
|
|
|
|
pub query: Query,
|
|
|
|
pub query: Query,
|
|
|
@ -800,7 +793,7 @@ struct LocalScope<'a> {
|
|
|
|
local_defs: Vec<LocalDef<'a>>,
|
|
|
|
local_defs: Vec<LocalDef<'a>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "debug", derive(Debug))]
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct HighlightIter<'a, 'tree: 'a, F>
|
|
|
|
struct HighlightIter<'a, 'tree: 'a, F>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
|
|
|
|
F: FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
|
|
|
@ -826,10 +819,9 @@ struct HighlightIterLayer<'a, 'tree: 'a> {
|
|
|
|
depth: usize,
|
|
|
|
depth: usize,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "debug")]
|
|
|
|
|
|
|
|
impl<'a, 'tree: 'a> fmt::Debug for HighlightIterLayer<'a, 'tree> {
|
|
|
|
impl<'a, 'tree: 'a> fmt::Debug for HighlightIterLayer<'a, 'tree> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("HighlightIterLayer").finish_non_exhaustive()
|
|
|
|
f.debug_struct("HighlightIterLayer").finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|