Use the 'jsonc' language id for all JSON files
This way, comments are allowed by the language server.
This commit is contained in:
parent
3a28f09979
commit
f52050a9ec
3 changed files with 29 additions and 4 deletions
|
@ -102,6 +102,10 @@ pub trait LspAdapter: 'static + Send + Sync {
|
||||||
fn disk_based_diagnostics_progress_token(&self) -> Option<&'static str> {
|
fn disk_based_diagnostics_progress_token(&self) -> Option<&'static str> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id_for_language(&self, _name: &str) -> Option<String> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -1132,7 +1132,19 @@ impl Project {
|
||||||
if file.is_local() {
|
if file.is_local() {
|
||||||
let uri = lsp::Url::from_file_path(file.abs_path(cx)).unwrap();
|
let uri = lsp::Url::from_file_path(file.abs_path(cx)).unwrap();
|
||||||
let initial_snapshot = buffer.text_snapshot();
|
let initial_snapshot = buffer.text_snapshot();
|
||||||
let language_server = self.language_server_for_buffer(buffer, cx).cloned();
|
|
||||||
|
let mut language_server = None;
|
||||||
|
let mut language_id = None;
|
||||||
|
if let Some(language) = buffer.language() {
|
||||||
|
let worktree_id = file.worktree_id(cx);
|
||||||
|
if let Some(adapter) = language.lsp_adapter() {
|
||||||
|
language_id = adapter.id_for_language(language.name().as_ref());
|
||||||
|
language_server = self
|
||||||
|
.language_servers
|
||||||
|
.get(&(worktree_id, adapter.name()))
|
||||||
|
.cloned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(local_worktree) = file.worktree.read(cx).as_local() {
|
if let Some(local_worktree) = file.worktree.read(cx).as_local() {
|
||||||
if let Some(diagnostics) = local_worktree.diagnostics_for_path(file.path()) {
|
if let Some(diagnostics) = local_worktree.diagnostics_for_path(file.path()) {
|
||||||
|
@ -1147,7 +1159,7 @@ impl Project {
|
||||||
lsp::DidOpenTextDocumentParams {
|
lsp::DidOpenTextDocumentParams {
|
||||||
text_document: lsp::TextDocumentItem::new(
|
text_document: lsp::TextDocumentItem::new(
|
||||||
uri,
|
uri,
|
||||||
Default::default(),
|
language_id.unwrap_or_default(),
|
||||||
0,
|
0,
|
||||||
initial_snapshot.text(),
|
initial_snapshot.text(),
|
||||||
),
|
),
|
||||||
|
@ -1437,7 +1449,7 @@ impl Project {
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.language_servers
|
this.language_servers
|
||||||
.insert(key.clone(), (adapter, language_server.clone()));
|
.insert(key.clone(), (adapter.clone(), language_server.clone()));
|
||||||
this.language_server_statuses.insert(
|
this.language_server_statuses.insert(
|
||||||
server_id,
|
server_id,
|
||||||
LanguageServerStatus {
|
LanguageServerStatus {
|
||||||
|
@ -1494,12 +1506,13 @@ impl Project {
|
||||||
.or_insert_with(|| vec![(0, buffer.text_snapshot())]);
|
.or_insert_with(|| vec![(0, buffer.text_snapshot())]);
|
||||||
let (version, initial_snapshot) = versions.last().unwrap();
|
let (version, initial_snapshot) = versions.last().unwrap();
|
||||||
let uri = lsp::Url::from_file_path(file.abs_path(cx)).unwrap();
|
let uri = lsp::Url::from_file_path(file.abs_path(cx)).unwrap();
|
||||||
|
let language_id = adapter.id_for_language(language.name().as_ref());
|
||||||
language_server
|
language_server
|
||||||
.notify::<lsp::notification::DidOpenTextDocument>(
|
.notify::<lsp::notification::DidOpenTextDocument>(
|
||||||
lsp::DidOpenTextDocumentParams {
|
lsp::DidOpenTextDocumentParams {
|
||||||
text_document: lsp::TextDocumentItem::new(
|
text_document: lsp::TextDocumentItem::new(
|
||||||
uri,
|
uri,
|
||||||
Default::default(),
|
language_id.unwrap_or_default(),
|
||||||
*version,
|
*version,
|
||||||
initial_snapshot.text(),
|
initial_snapshot.text(),
|
||||||
),
|
),
|
||||||
|
|
|
@ -127,4 +127,12 @@ impl LspAdapter for JsonLspAdapter {
|
||||||
"provideFormatter": true
|
"provideFormatter": true
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn id_for_language(&self, name: &str) -> Option<String> {
|
||||||
|
if name == "JSON" {
|
||||||
|
Some("jsonc".into())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue