on master help sign in
Fix sorting issues of the editor wide diagnostics and apply diagnostics related review suggestions
f9b0865Philipp Mildenberger
helix-term/src/application.rs+11−10
@@ -721,7 +721,7 @@ impl Application {
721 ));
721 ));
722 }
722 }
723 }
723 }
724− Notification::PublishDiagnostics(mut params) => {
724+ Notification::PublishDiagnostics(params) => {
725 let path = match params.uri.to_file_path() {
725 let path = match params.uri.to_file_path() {
726 Ok(path) => path,
726 Ok(path) => path,
727 Err(_) => {
727 Err(_) => {
@@ -841,15 +841,10 @@ impl Application {
841 doc.replace_diagnostics(diagnostics, server_id);
841 doc.replace_diagnostics(diagnostics, server_id);
842 }
842 }
843
843
844− // Sort diagnostics first by severity and then by line numbers.
845− // Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order
846− params
847− .diagnostics
848− .sort_unstable_by_key(|d| (d.severity, d.range.start));
849− let diagnostics = params
844+ let mut diagnostics = params
850 .diagnostics
845 .diagnostics
851 .into_iter()
846 .into_iter()
852− .map(|d| (d, server_id, offset_encoding))
847+ .map(|d| (d, server_id))
853 .collect();
848 .collect();
854
849
855 // Insert the original lsp::Diagnostics here because we may have no open document
850 // Insert the original lsp::Diagnostics here because we may have no open document
@@ -859,10 +854,16 @@ impl Application {
859 Entry::Occupied(o) => {
854 Entry::Occupied(o) => {
860 let current_diagnostics = o.into_mut();
855 let current_diagnostics = o.into_mut();
861 // there may entries of other language servers, which is why we can't overwrite the whole entry
856 // there may entries of other language servers, which is why we can't overwrite the whole entry
862− current_diagnostics.retain(|(_, lsp_id, _)| *lsp_id != server_id);
857+ current_diagnostics.retain(|(_, lsp_id)| *lsp_id != server_id);
863− current_diagnostics.extend(diagnostics);
858+ current_diagnostics.append(&mut diagnostics);
859+ // Sort diagnostics first by severity and then by line numbers.
860+ // Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order
861+ current_diagnostics
862+ .sort_unstable_by_key(|(d, _)| (d.severity, d.range.start));
864 }
863 }
865 Entry::Vacant(v) => {
864 Entry::Vacant(v) => {
865+ diagnostics
866+ .sort_unstable_by_key(|(d, _)| (d.severity, d.range.start));
866 v.insert(diagnostics);
867 v.insert(diagnostics);
867 }
868 }
868 };
869 };
helix-term/src/commands/lsp.rs+10−7
@@ -262,7 +262,7 @@ enum DiagnosticsFormat {
262
262
263fn diag_picker(
263fn diag_picker(
264 cx: &Context,
264 cx: &Context,
265− diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize, OffsetEncoding)>>,
265+ diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
266 current_path: Option<lsp::Url>,
266 current_path: Option<lsp::Url>,
267 format: DiagnosticsFormat,
267 format: DiagnosticsFormat,
268) -> FilePicker<PickerDiagnostic> {
268) -> FilePicker<PickerDiagnostic> {
@@ -272,12 +272,15 @@ fn diag_picker(
272 let mut flat_diag = Vec::new();
272 let mut flat_diag = Vec::new();
273 for (url, diags) in diagnostics {
273 for (url, diags) in diagnostics {
274 flat_diag.reserve(diags.len());
274 flat_diag.reserve(diags.len());
275+
275− for (diag, _, offset_encoding) in diags {
276+ for (diag, ls) in diags {
277+ if let Some(ls) = cx.editor.language_servers.get_by_id(ls) {
276− flat_diag.push(PickerDiagnostic {
278+ flat_diag.push(PickerDiagnostic {
277− url: url.clone(),
279+ url: url.clone(),
278− diag,
280+ diag,
279− offset_encoding,
281+ offset_encoding: ls.offset_encoding(),
280− });
282+ });
283+ }
281 }
284 }
282 }
285 }
283
286
helix-term/src/ui/statusline.rs+1−1
@@ -266,7 +266,7 @@ where
266 .diagnostics
266 .diagnostics
267 .values()
267 .values()
268 .flatten()
268 .flatten()
269− .fold((0, 0), |mut counts, (diag, _, _)| {
269+ .fold((0, 0), |mut counts, (diag, _)| {
270 match diag.severity {
270 match diag.severity {
271 Some(DiagnosticSeverity::WARNING) => counts.0 += 1,
271 Some(DiagnosticSeverity::WARNING) => counts.0 += 1,
272 Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1,
272 Some(DiagnosticSeverity::ERROR) | None => counts.1 += 1,
helix-view/src/editor.rs+1−1
@@ -818,7 +818,7 @@ pub struct Editor {
818 pub macro_recording: Option<(char, Vec<KeyEvent>)>,
818 pub macro_recording: Option<(char, Vec<KeyEvent>)>,
819 pub macro_replaying: Vec<char>,
819 pub macro_replaying: Vec<char>,
820 pub language_servers: helix_lsp::Registry,
820 pub language_servers: helix_lsp::Registry,
821− pub diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize, OffsetEncoding)>>,
821+ pub diagnostics: BTreeMap<lsp::Url, Vec<(lsp::Diagnostic, usize)>>,
822 pub diff_providers: DiffProviderRegistry,
822 pub diff_providers: DiffProviderRegistry,
823
823
824 pub debugger: Option<dap::Client>,
824 pub debugger: Option<dap::Client>,