on master help sign in
Show file path only in workspace diagnostic picker
af35c62Gokul Soumya
helix-term/src/commands/lsp.rs+29−13
@@ -9,10 +9,7 @@ use tui::text::{Span, Spans};
9use super::{align_view, push_jump, Align, Context, Editor};
9use super::{align_view, push_jump, Align, Context, Editor};
10
10
11use helix_core::{path, Selection};
11use helix_core::{path, Selection};
12−use helix_view::{
12+use helix_view::{editor::Action, theme::Style};
13− editor::Action,
14− theme::{Modifier, Style},
15−};
16
13
17use crate::{
14use crate::{
18 compositor::{self, Compositor},
15 compositor::{self, Compositor},
@@ -99,9 +96,9 @@ struct PickerDiagnostic {
99}
96}
100
97
101impl ui::menu::Item for PickerDiagnostic {
98impl ui::menu::Item for PickerDiagnostic {
102− type Data = DiagnosticStyles;
99+ type Data = (DiagnosticStyles, DiagnosticsFormat);
103
100
104− fn label(&self, styles: &Self::Data) -> Spans {
101+ fn label(&self, (styles, format): &Self::Data) -> Spans {
105 let mut style = self
102 let mut style = self
106 .diag
103 .diag
107 .severity
104 .severity
@@ -128,13 +125,18 @@ impl ui::menu::Item for PickerDiagnostic {
128 .map(|code| format!(" ({})", code))
125 .map(|code| format!(" ({})", code))
129 .unwrap_or_default();
126 .unwrap_or_default();
130
127
128+ let path = match format {
129+ DiagnosticsFormat::HideSourcePath => String::new(),
130+ DiagnosticsFormat::ShowSourcePath => {
131− let truncated_path = path::get_truncated_path(self.url.path())
131+ let path = path::get_truncated_path(self.url.path())
132− .to_string_lossy()
132+ .to_string_lossy()
133− .into_owned();
133+ .into_owned();
134+ format!("{}: ", path)
135+ }
136+ };
134
137
135 Spans::from(vec![
138 Spans::from(vec![
136− Span::raw(truncated_path),
139+ Span::raw(path),
137− Span::raw(": "),
138 Span::styled(&self.diag.message, style),
140 Span::styled(&self.diag.message, style),
139 Span::styled(code, style),
141 Span::styled(code, style),
140 ])
142 ])
@@ -237,10 +239,17 @@ fn sym_picker(
237 .truncate_start(false)
239 .truncate_start(false)
238}
240}
239
241
242+#[derive(Copy, Clone, PartialEq)]
243+enum DiagnosticsFormat {
244+ ShowSourcePath,
245+ HideSourcePath,
246+}
247+
240fn diag_picker(
248fn diag_picker(
241 cx: &Context,
249 cx: &Context,
242 diagnostics: BTreeMap<lsp::Url, Vec<lsp::Diagnostic>>,
250 diagnostics: BTreeMap<lsp::Url, Vec<lsp::Diagnostic>>,
243 current_path: Option<lsp::Url>,
251 current_path: Option<lsp::Url>,
252+ format: DiagnosticsFormat,
244 offset_encoding: OffsetEncoding,
253 offset_encoding: OffsetEncoding,
245) -> FilePicker<PickerDiagnostic> {
254) -> FilePicker<PickerDiagnostic> {
246 // TODO: drop current_path comparison and instead use workspace: bool flag?
255 // TODO: drop current_path comparison and instead use workspace: bool flag?
@@ -266,7 +275,7 @@ fn diag_picker(
266
275
267 FilePicker::new(
276 FilePicker::new(
268 flat_diag,
277 flat_diag,
269− styles,
278+ (styles, format),
270 move |cx, PickerDiagnostic { url, diag }, action| {
279 move |cx, PickerDiagnostic { url, diag }, action| {
271 if current_path.as_ref() == Some(url) {
280 if current_path.as_ref() == Some(url) {
272 let (view, doc) = current!(cx.editor);
281 let (view, doc) = current!(cx.editor);
@@ -378,6 +387,7 @@ pub fn diagnostics_picker(cx: &mut Context) {
378 cx,
387 cx,
379 [(current_url.clone(), diagnostics)].into(),
388 [(current_url.clone(), diagnostics)].into(),
380 Some(current_url),
389 Some(current_url),
390+ DiagnosticsFormat::HideSourcePath,
381 offset_encoding,
391 offset_encoding,
382 );
392 );
383 cx.push_layer(Box::new(overlayed(picker)));
393 cx.push_layer(Box::new(overlayed(picker)));
@@ -390,7 +400,13 @@ pub fn workspace_diagnostics_picker(cx: &mut Context) {
390 let current_url = doc.url();
400 let current_url = doc.url();
391 let offset_encoding = language_server.offset_encoding();
401 let offset_encoding = language_server.offset_encoding();
392 let diagnostics = cx.editor.diagnostics.clone();
402 let diagnostics = cx.editor.diagnostics.clone();
393− let picker = diag_picker(cx, diagnostics, current_url, offset_encoding);
403+ let picker = diag_picker(
404+ cx,
405+ diagnostics,
406+ current_url,
407+ DiagnosticsFormat::ShowSourcePath,
408+ offset_encoding,
409+ );
394 cx.push_layer(Box::new(overlayed(picker)));
410 cx.push_layer(Box::new(overlayed(picker)));
395}
411}
396
412