From af35c624070e3db5746c35601e98f346d91df280 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Tue, 5 Jul 2022 18:31:25 +0530 Subject: [PATCH] Show file path only in workspace diagnostic picker --- helix-term/src/commands/lsp.rs | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index a73148cc3..630c47e13 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -9,10 +9,7 @@ use tui::text::{Span, Spans}; use super::{align_view, push_jump, Align, Context, Editor}; use helix_core::{path, Selection}; -use helix_view::{ - editor::Action, - theme::{Modifier, Style}, -}; +use helix_view::{editor::Action, theme::Style}; use crate::{ compositor::{self, Compositor}, @@ -99,9 +96,9 @@ struct PickerDiagnostic { } impl ui::menu::Item for PickerDiagnostic { - type Data = DiagnosticStyles; + type Data = (DiagnosticStyles, DiagnosticsFormat); - fn label(&self, styles: &Self::Data) -> Spans { + fn label(&self, (styles, format): &Self::Data) -> Spans { let mut style = self .diag .severity @@ -128,13 +125,18 @@ impl ui::menu::Item for PickerDiagnostic { .map(|code| format!(" ({})", code)) .unwrap_or_default(); - let truncated_path = path::get_truncated_path(self.url.path()) - .to_string_lossy() - .into_owned(); + let path = match format { + DiagnosticsFormat::HideSourcePath => String::new(), + DiagnosticsFormat::ShowSourcePath => { + let path = path::get_truncated_path(self.url.path()) + .to_string_lossy() + .into_owned(); + format!("{}: ", path) + } + }; Spans::from(vec![ - Span::raw(truncated_path), - Span::raw(": "), + Span::raw(path), Span::styled(&self.diag.message, style), Span::styled(code, style), ]) @@ -237,10 +239,17 @@ fn sym_picker( .truncate_start(false) } +#[derive(Copy, Clone, PartialEq)] +enum DiagnosticsFormat { + ShowSourcePath, + HideSourcePath, +} + fn diag_picker( cx: &Context, diagnostics: BTreeMap>, current_path: Option, + format: DiagnosticsFormat, offset_encoding: OffsetEncoding, ) -> FilePicker { // TODO: drop current_path comparison and instead use workspace: bool flag? @@ -266,7 +275,7 @@ fn diag_picker( FilePicker::new( flat_diag, - styles, + (styles, format), move |cx, PickerDiagnostic { url, diag }, action| { if current_path.as_ref() == Some(url) { let (view, doc) = current!(cx.editor); @@ -378,6 +387,7 @@ pub fn diagnostics_picker(cx: &mut Context) { cx, [(current_url.clone(), diagnostics)].into(), Some(current_url), + DiagnosticsFormat::HideSourcePath, offset_encoding, ); cx.push_layer(Box::new(overlayed(picker))); @@ -390,7 +400,13 @@ pub fn workspace_diagnostics_picker(cx: &mut Context) { let current_url = doc.url(); let offset_encoding = language_server.offset_encoding(); let diagnostics = cx.editor.diagnostics.clone(); - let picker = diag_picker(cx, diagnostics, current_url, offset_encoding); + let picker = diag_picker( + cx, + diagnostics, + current_url, + DiagnosticsFormat::ShowSourcePath, + offset_encoding, + ); cx.push_layer(Box::new(overlayed(picker))); }