Make language's language server config non-optional

This commit is contained in:
Max Brunsfeld 2022-03-28 18:14:49 -07:00
parent 4d456d3847
commit a8600e76a3
8 changed files with 34 additions and 52 deletions

View File

@ -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()),

View File

@ -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<String>,
pub language_server: Option<LanguageServerConfig>,
#[serde(default)]
pub language_server: LanguageServerConfig,
}
impl Default for LanguageConfig {
@ -251,20 +252,12 @@ impl LanguageRegistry {
cx: &mut MutableAppContext,
) -> Option<Task<Result<lsp::LanguageServer>>> {
#[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<String>> {
self.config
.language_server
.as_ref()
.map(|config| &config.disk_based_diagnostic_sources)
pub fn disk_based_diagnostic_sources(&self) -> &HashSet<String> {
&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) {

View File

@ -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()),

View File

@ -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()),

View File

@ -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,

View File

@ -9,6 +9,3 @@ brackets = [
{ start = "\"", end = "\"", close = true, newline = false },
{ start = "/*", end = " */", close = true, newline = false },
]
[language_server]
disk_based_diagnostic_sources = []

View File

@ -6,6 +6,3 @@ brackets = [
{ start = "[", end = "]", close = true, newline = true },
{ start = "\"", end = "\"", close = true, newline = false },
]
[language_server]
disk_based_diagnostic_sources = []

View File

@ -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)));
}