Assign diagnostics on buffer even if it doesn't have a language

This shouldn't be necessary in practice but makes testing easier.
This commit is contained in:
Nathan Sobo 2022-01-22 09:54:25 -07:00
parent 8bf628c17b
commit 83418204b6
2 changed files with 49 additions and 45 deletions

View file

@ -869,8 +869,8 @@ impl Buffer {
}
let version = version.map(|version| version as usize);
let content = if let Some(version) = version {
let language_server = self.language_server.as_mut().unwrap();
let content =
if let Some((version, language_server)) = version.zip(self.language_server.as_mut()) {
language_server
.pending_snapshots
.retain(|&v, _| v >= version);

View file

@ -627,18 +627,16 @@ impl Project {
(file.path().clone(), file.full_path())
};
// Set the buffer's language
let language = self.languages.select_language(&full_path)?.clone();
// If the buffer has a language, set it and start/assign the language server
if let Some(language) = self.languages.select_language(&full_path) {
buffer.update(cx, |buffer, cx| {
buffer.set_language(Some(language.clone()), cx);
});
// For local worktrees, start a language server if needed.
// Also assign the language server and any previously stored diagnostics to the buffer.
let worktree = worktree.read(cx);
if let Some(local_worktree) = worktree.as_local() {
if let Some(local_worktree) = worktree.read(cx).as_local() {
let worktree_id = local_worktree.id();
let diagnostics = local_worktree.diagnostics_for_path(&path);
let worktree_abs_path = local_worktree.abs_path().clone();
let language_server = match self
@ -648,7 +646,7 @@ impl Project {
hash_map::Entry::Occupied(e) => Some(e.get().clone()),
hash_map::Entry::Vacant(e) => Self::start_language_server(
self.client.clone(),
language,
language.clone(),
&worktree_abs_path,
cx,
)
@ -657,11 +655,17 @@ impl Project {
buffer.update(cx, |buffer, cx| {
buffer.set_language_server(language_server, cx);
if let Some(diagnostics) = diagnostics {
buffer.update_diagnostics(None, diagnostics, cx).log_err();
}
});
}
}
if let Some(local_worktree) = worktree.read(cx).as_local() {
if let Some(diagnostics) = local_worktree.diagnostics_for_path(&path) {
buffer.update(cx, |buffer, cx| {
buffer.update_diagnostics(None, diagnostics, cx).log_err();
});
}
}
None
}