From 1e22259fd44bd9bca1b45d907beaaa9ac18c8e5e Mon Sep 17 00:00:00 2001 From: Alexandru RADOVICI Date: Mon, 19 May 2025 15:06:32 +0300 Subject: [PATCH 1/2] add the full (rust) compiler error picker preview --- helix-term/src/commands/lsp.rs | 24 ++++++++++++++++++++++-- helix-term/src/ui/picker.rs | 18 +++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 9c55c830c..2e625ce05 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -29,7 +29,7 @@ use helix_view::{ use crate::{ compositor::{self, Compositor}, job::Callback, - ui::{self, overlay::overlaid, FileLocation, Picker, Popup, PromptEvent}, + ui::{self, overlay::overlaid, picker::PathOrId, FileLocation, Picker, Popup, PromptEvent}, }; use std::{cmp::Ordering, collections::HashSet, fmt::Display, future::Future, path::Path}; @@ -295,7 +295,27 @@ fn diag_picker( .immediately_show_diagnostic(doc, view.id); }, ) - .with_preview(move |_editor, diag| location_to_file_location(&diag.location)) + .with_preview(move |_editor, diag| { + // let a: Option<(PathOrId, Option<(usize, usize)>)> = + // location_to_file_location(&diag.location); + // let document = Document::default(editor.config.clone(), editor.syn_loader.clone()); + // editor.document_by_path(path) + match diag.diag.data { + Some(ref data) => Some(( + PathOrId::Document( + data.as_object() + .unwrap() + .get("rendered") + .unwrap() + .as_str() + .unwrap() + .to_string(), + ), + Some((0, 0)), + )), + None => location_to_file_location(&diag.location), + } + }) .truncate_start(false) } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 7abdfce84..607f5d44b 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -42,7 +42,7 @@ use std::{ use crate::ui::{Prompt, PromptEvent}; use helix_core::{ char_idx_at_visual_offset, fuzzy::MATCHER, movement::Direction, - text_annotations::TextAnnotations, unicode::segmentation::UnicodeSegmentation, Position, + text_annotations::TextAnnotations, unicode::segmentation::UnicodeSegmentation, Position, Rope, }; use helix_view::{ editor::Action, @@ -64,6 +64,7 @@ pub const MAX_FILE_SIZE_FOR_PREVIEW: u64 = 10 * 1024 * 1024; pub enum PathOrId<'a> { Id(DocumentId), Path(&'a Path), + Document(String), } impl<'a> From<&'a Path> for PathOrId<'a> { @@ -575,6 +576,21 @@ impl Picker { let (path_or_id, range) = (self.file_fn.as_ref()?)(editor, current)?; match path_or_id { + PathOrId::Document(s) => { + let rope = Rope::from_str(&s); + let document = + Document::from(rope, None, editor.config.clone(), editor.syn_loader.clone()); + let _ = self.preview_cache.insert( + Path::new("/tmp/.helix_error").into(), + CachedPreview::Document(Box::new(document)), + ); + let preview = Preview::Cached( + self.preview_cache + .get(Path::new("/tmp/.helix_error")) + .unwrap(), + ); + Some((preview, range)) + } PathOrId::Path(path) => { if let Some(doc) = editor.document_by_path(path) { return Some((Preview::EditorDocument(doc), range)); From 3bff12f9957bbbedffe57572beb9c56ef922f5f4 Mon Sep 17 00:00:00 2001 From: Alexandru RADOVICI Date: Mon, 19 May 2025 15:31:37 +0300 Subject: [PATCH 2/2] improve render reading --- helix-lsp/src/client.rs | 3 +++ helix-term/src/commands/lsp.rs | 31 ++++++++++++------------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 1894dc5b1..83f71700f 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -683,6 +683,9 @@ impl Client { ]), ..Default::default() }), + /*experimental: Some( + serde_json::from_str("{\"colorDiagnosticOutput\": true}").unwrap(), + ),*/ ..Default::default() }, trace: None, diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 2e625ce05..51094046c 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -295,26 +295,19 @@ fn diag_picker( .immediately_show_diagnostic(doc, view.id); }, ) - .with_preview(move |_editor, diag| { - // let a: Option<(PathOrId, Option<(usize, usize)>)> = - // location_to_file_location(&diag.location); - // let document = Document::default(editor.config.clone(), editor.syn_loader.clone()); - // editor.document_by_path(path) - match diag.diag.data { - Some(ref data) => Some(( - PathOrId::Document( - data.as_object() - .unwrap() - .get("rendered") - .unwrap() - .as_str() - .unwrap() - .to_string(), - ), - Some((0, 0)), - )), - None => location_to_file_location(&diag.location), + .with_preview(move |_editor, diag| match diag.diag.data { + Some(ref data) => { + if let Some(error_string) = data + .as_object() + .and_then(|object| object.get("rendered")) + .and_then(|rendered| rendered.as_str()) + { + Some((PathOrId::Document(error_string.to_string()), Some((0, 0)))) + } else { + location_to_file_location(&diag.location) + } } + None => location_to_file_location(&diag.location), }) .truncate_start(false) }