diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index afb3b3a56..18397d796 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -707,6 +707,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 99a6d62f9..b27b89344 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,20 @@ 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| 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) } diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 3f3aaba2b..d8211d805 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));