@@ -10,9 +10,19 @@ use std::{
12use once_cell::sync::{Lazy, OnceCell};
12use once_cell::sync::{Lazy, OnceCell};
13+use serde::{Deserialize, Serialize};
15+#[derive(Serialize, Deserialize)]
16+pub struct Configuration {
17+ language: Vec<LanguageConfiguration>,
14// largely based on tree-sitter/cli/src/loader.rs
20// largely based on tree-sitter/cli/src/loader.rs
21+#[derive(Serialize, Deserialize)]
22+#[serde(rename_all = "kebab-case")]
15pub struct LanguageConfiguration {
23pub struct LanguageConfiguration {
24+ #[serde(rename = "name")]
25+ pub(crate) language_id: Lang,
16 pub scope: String, // source.rust
26 pub scope: String, // source.rust
17 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
27 pub file_types: Vec<String>, // filename ends_with? <Gemfile, rb, etc>
18 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
28 pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
@@ -24,22 +34,29 @@ pub struct LanguageConfiguration {
24 // injection_regex
34 // injection_regex
25 // first_line_regex
35 // first_line_regex
28− pub(crate) language_id: Lang,
29 pub(crate) highlight_config: OnceCell<Option<Arc<HighlightConfiguration>>>,
38 pub(crate) highlight_config: OnceCell<Option<Arc<HighlightConfiguration>>>,
30 // tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583
39 // tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583
40+ #[serde(skip_serializing_if = "Option::is_none")]
31− pub language_server_config: Option<LanguageServerConfiguration>,
41+ pub language_server: Option<LanguageServerConfiguration>,
42+ #[serde(skip_serializing_if = "Option::is_none")]
32− pub indent_config: Option<IndentationConfiguration>,
43+ pub indent: Option<IndentationConfiguration>,
46+#[derive(Serialize, Deserialize)]
47+#[serde(rename_all = "kebab-case")]
35pub struct LanguageServerConfiguration {
48pub struct LanguageServerConfiguration {
36 pub command: String,
49 pub command: String,
51+ #[serde(skip_serializing_if = "Vec::is_empty")]
37 pub args: Vec<String>,
52 pub args: Vec<String>,
55+#[derive(Serialize, Deserialize)]
56+#[serde(rename_all = "kebab-case")]
40pub struct IndentationConfiguration {
57pub struct IndentationConfiguration {
41 pub tab_width: usize,
58 pub tab_width: usize,
42− pub indent_unit: String,
59+ pub unit: String,
45impl LanguageConfiguration {
62impl LanguageConfiguration {
@@ -81,7 +98,7 @@ impl LanguageConfiguration {
84−pub static LOADER: Lazy<Loader> = Lazy::new(Loader::init);
101+pub static LOADER: OnceCell<Loader> = OnceCell::new();
86pub struct Loader {
103pub struct Loader {
87 // highlight_names ?
104 // highlight_names ?
@@ -90,48 +107,13 @@ pub struct Loader {
92impl Loader {
109impl Loader {
93− fn init() -> Self {
110+ pub fn new(config: Configuration) -> Self {
94 let mut loader = Self {
111 let mut loader = Self {
95 language_configs: Vec::new(),
112 language_configs: Vec::new(),
96 language_config_ids_by_file_type: HashMap::new(),
113 language_config_ids_by_file_type: HashMap::new(),
99− // hardcoded from now, might load from toml
101− LanguageConfiguration {
102− scope: "source.rust".to_string(),
103− file_types: vec!["rs".to_string()],
104− language_id: Lang::Rust,
105− highlight_config: OnceCell::new(),
107− path: "../helix-syntax/languages/tree-sitter-rust".into(),
109− language_server_config: Some(LanguageServerConfiguration {
110− command: "rust-analyzer".to_string(),
113− indent_config: Some(IndentationConfiguration {
115− indent_unit: String::from(" "),
118− LanguageConfiguration {
119− scope: "source.toml".to_string(),
120− file_types: vec!["toml".to_string()],
121− language_id: Lang::Toml,
122− highlight_config: OnceCell::new(),
124− path: "../helix-syntax/languages/tree-sitter-toml".into(),
126− language_server_config: None,
127− indent_config: Some(IndentationConfiguration {
129− indent_unit: String::from(" "),
134− for config in configs {
116+ for config in config.language {
135 // get the next id
117 // get the next id
136 let language_id = loader.language_configs.len();
118 let language_id = loader.language_configs.len();