From a8600e76a3de34968ed27c984ed32c4f17427f46 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 28 Mar 2022 18:14:49 -0700 Subject: [PATCH] Make language's language server config non-optional --- crates/editor/src/editor.rs | 4 ++-- crates/language/src/language.rs | 24 +++++++----------------- crates/language/src/tests.rs | 1 - crates/project/src/project.rs | 24 +++++++++--------------- crates/server/src/rpc.rs | 22 +++++++++++----------- crates/zed/languages/c/config.toml | 3 --- crates/zed/languages/json/config.toml | 3 --- crates/zed/src/language.rs | 5 +++++ 8 files changed, 34 insertions(+), 52 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index f861b6ac60..dac7adfdf8 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8889,7 +8889,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -8979,7 +8979,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index bdc2e120df..5b917c0fdf 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -51,7 +51,7 @@ lazy_static! { brackets: Default::default(), autoclose_before: Default::default(), line_comment: None, - language_server: None, + language_server: Default::default(), }, None, )); @@ -113,7 +113,8 @@ pub struct LanguageConfig { #[serde(default)] pub autoclose_before: String, pub line_comment: Option, - pub language_server: Option, + #[serde(default)] + pub language_server: LanguageServerConfig, } impl Default for LanguageConfig { @@ -251,20 +252,12 @@ impl LanguageRegistry { cx: &mut MutableAppContext, ) -> Option>> { #[cfg(any(test, feature = "test-support"))] - if language - .config - .language_server - .as_ref() - .and_then(|config| config.fake_config.as_ref()) - .is_some() - { + if language.config.language_server.fake_config.is_some() { let language = language.clone(); return Some(cx.spawn(|mut cx| async move { let fake_config = language .config .language_server - .as_ref() - .unwrap() .fake_config .as_ref() .unwrap(); @@ -478,18 +471,15 @@ impl Language { self.config.line_comment.as_deref() } - pub fn disk_based_diagnostic_sources(&self) -> Option<&HashSet> { - self.config - .language_server - .as_ref() - .map(|config| &config.disk_based_diagnostic_sources) + pub fn disk_based_diagnostic_sources(&self) -> &HashSet { + &self.config.language_server.disk_based_diagnostic_sources } pub fn disk_based_diagnostics_progress_token(&self) -> Option<&String> { self.config .language_server + .disk_based_diagnostics_progress_token .as_ref() - .and_then(|config| config.disk_based_diagnostics_progress_token.as_ref()) } pub fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams) { diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 98ecf63a46..8af4ff247e 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -869,7 +869,6 @@ fn rust_lang() -> Language { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: None, ..Default::default() }, Some(tree_sitter_rust::language()), diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 404d867069..1a41475909 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -1599,14 +1599,8 @@ impl Project { ), ); } - self.update_diagnostics( - params, - language - .disk_based_diagnostic_sources() - .unwrap_or(&Default::default()), - cx, - ) - .log_err(); + self.update_diagnostics(params, language.disk_based_diagnostic_sources(), cx) + .log_err(); if disk_diagnostics_token.is_none() { self.disk_based_diagnostics_finished(cx); self.broadcast_language_server_update( @@ -4697,7 +4691,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(rust_lsp_config), + language_server: rust_lsp_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -4706,7 +4700,7 @@ mod tests { LanguageConfig { name: "JSON".into(), path_suffixes: vec!["json".to_string()], - language_server: Some(json_lsp_config), + language_server: json_lsp_config, ..Default::default() }, None, @@ -4906,7 +4900,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -5023,7 +5017,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(lsp_config), + language_server: lsp_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -5394,7 +5388,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(lsp_config), + language_server: lsp_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -5744,7 +5738,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -6680,7 +6674,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 374aaf6a7e..b329839de2 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -2050,7 +2050,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -2279,7 +2279,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -2474,7 +2474,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -2589,7 +2589,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -2732,7 +2732,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -2972,7 +2972,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -3119,7 +3119,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -3252,7 +3252,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -3349,7 +3349,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -3585,7 +3585,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, Some(tree_sitter_rust::language()), @@ -5456,7 +5456,7 @@ mod tests { LanguageConfig { name: "Rust".into(), path_suffixes: vec!["rs".to_string()], - language_server: Some(language_server_config), + language_server: language_server_config, ..Default::default() }, None, diff --git a/crates/zed/languages/c/config.toml b/crates/zed/languages/c/config.toml index aeee919ac6..b7e1f07443 100644 --- a/crates/zed/languages/c/config.toml +++ b/crates/zed/languages/c/config.toml @@ -9,6 +9,3 @@ brackets = [ { start = "\"", end = "\"", close = true, newline = false }, { start = "/*", end = " */", close = true, newline = false }, ] - -[language_server] -disk_based_diagnostic_sources = [] \ No newline at end of file diff --git a/crates/zed/languages/json/config.toml b/crates/zed/languages/json/config.toml index 27d1193b0d..ad87dcf633 100644 --- a/crates/zed/languages/json/config.toml +++ b/crates/zed/languages/json/config.toml @@ -6,6 +6,3 @@ brackets = [ { start = "[", end = "]", close = true, newline = true }, { start = "\"", end = "\"", close = true, newline = false }, ] - -[language_server] -disk_based_diagnostic_sources = [] \ No newline at end of file diff --git a/crates/zed/src/language.rs b/crates/zed/src/language.rs index 166ec2a839..fbf413c644 100644 --- a/crates/zed/src/language.rs +++ b/crates/zed/src/language.rs @@ -555,6 +555,11 @@ pub fn build_language_registry(login_shell_env_loaded: Task<()>) -> LanguageRegi tree_sitter_rust::language(), Some(Arc::new(RustLspAdapter)), ), + ( + "typescript", + tree_sitter_typescript::language_typescript(), + None, // + ), ] { languages.add(Arc::new(language(name, grammar, lsp_adapter))); }