Skip to content

Commit

Permalink
Issue diagnostics, even if empty. (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem authored Jul 27, 2023
1 parent b6646a8 commit de3d87d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
11 changes: 5 additions & 6 deletions lsp/nls/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ pub fn handle_save(server: &mut Server, params: DidChangeTextDocumentParams) ->
parse_and_typecheck(server, file_id)?;

for f in &invalid {
if let Err(e) = typecheck(server, *f) {
server.issue_diagnostics(*f, e);
}
let errors = typecheck(server, *f).err().unwrap_or_default();
server.issue_diagnostics(*f, errors);
}
Trace::reply(id);
Ok(())
Expand Down Expand Up @@ -105,15 +104,15 @@ fn parse_and_typecheck(server: &mut Server, file_id: FileId) -> Result<()> {
Ok(errs) => (errs.inner(), false),
Err(errs) => (errs, true),
};
let diags = parse_errs.into_diagnostics(server.cache.files_mut(), None);
server.issue_diagnostics(file_id, diags);
let mut diags = parse_errs.into_diagnostics(server.cache.files_mut(), None);

if !fatal {
trace!("Parsed, checking types");
if let Err(e) = typecheck(server, file_id) {
server.issue_diagnostics(file_id, e);
diags.extend_from_slice(&e);
}
}
server.issue_diagnostics(file_id, diags);

Ok(())
}
20 changes: 10 additions & 10 deletions lsp/nls/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ impl Server {
.flat_map(|d| lsp_types::Diagnostic::from_codespan(d, self.cache.files_mut()))
.collect();

if !diagnostics.is_empty() {
self.notify(lsp_server::Notification::new(
"textDocument/publishDiagnostics".into(),
PublishDiagnosticsParams {
uri,
diagnostics,
version: None,
},
));
}
// Issue diagnostics even if they're empty (empty diagnostics are how the editor knows
// that any previous errors were resolved).
self.notify(lsp_server::Notification::new(
"textDocument/publishDiagnostics".into(),
PublishDiagnosticsParams {
uri,
diagnostics,
version: None,
},
));
}
}

0 comments on commit de3d87d

Please sign in to comment.