From 4d7203d70a0d82b0b7cb7a942dbc8c31c37e1b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Dzivjak?= Date: Sat, 25 Nov 2023 14:17:16 +0100 Subject: [PATCH] render lens symbol in gutter --- helix-core/src/lib.rs | 2 +- helix-lsp/src/client.rs | 23 ------------- helix-term/src/commands.rs | 2 +- helix-term/src/commands/lsp.rs | 48 ++++------------------------ helix-term/src/keymap/default.rs | 2 +- helix-view/src/gutter.rs | 12 +++++-- helix-view/src/view.rs | 2 ++ runtime/themes/dracula_at_night.toml | 2 ++ theme.toml | 2 +- 9 files changed, 25 insertions(+), 70 deletions(-) diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index 0acdb238054ce..ae3f73a087d73 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -68,5 +68,5 @@ pub use syntax::Syntax; pub use diagnostic::Diagnostic; -pub use line_ending::{LineEnding, NATIVE_LINE_ENDING}; +pub use line_ending::{line_end_char_index, LineEnding, NATIVE_LINE_ENDING}; pub use transaction::{Assoc, Change, ChangeSet, Deletion, Operation, Transaction}; diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 730492e95d7e1..8742f42828569 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -1562,27 +1562,4 @@ impl Client { Some(self.call::(params)) } - - pub fn code_lens_resolve( - &self, - code_lens: lsp::CodeLens, - ) -> Option>>> { - let capabilities = self.capabilities.get().unwrap(); - - // Return early if the server does not support resolving code lens. - match capabilities.code_lens_provider { - Some(lsp::CodeLensOptions { - resolve_provider: Some(true), - .. - }) => (), - _ => return None, - } - - let request = self.call::(code_lens); - Some(async move { - let json = request.await?; - let response: Option = serde_json::from_value(json)?; - Ok(response) - }) - } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index e4f093d0bbc89..153dac883a6df 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -398,7 +398,7 @@ impl MappableCommand { paste_before, "Paste before selection", paste_clipboard_after, "Paste clipboard after selections", code_lens_under_cursor, "Show code lenses under cursor", - code_lenses_picker, "Show code lense picker", + request_code_lenses, "Show code lense picker", paste_clipboard_before, "Paste clipboard before selections", paste_primary_clipboard_after, "Paste primary clipboard after selections", paste_primary_clipboard_before, "Paste primary clipboard before selections", diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 13b913e865ba8..98aa55d810681 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1708,17 +1708,7 @@ pub fn code_lens_under_cursor(cx: &mut Context) { // TODO: fix the check cl.range.start.line == pos.line }) - .map(|cl| { - // if cl.command.is_none() { - // if let Some(req) = language_server.code_lens_resolve(cl.clone()) { - // if let Some(code_lens) = block_on(req).ok().unwrap() { - // log::info!("code_lense: resolved {:?} into {:?}", cl, code_lens); - // return map_code_lens(doc, &code_lens); - // } - // } - // } - map_code_lens(doc_text, cl, offset_encoding, language_server.id()) - }) + .map(|cl| map_code_lens(doc_text, cl, offset_encoding, language_server.id())) .collect(); if lenses.is_empty() { @@ -1764,7 +1754,9 @@ pub fn code_lens_under_cursor(cx: &mut Context) { }; } -pub fn code_lenses_picker(cx: &mut Context) { +// TODO: should be run the same way as diagnostic - shouldn't require manual +// trigger to set lenses. +pub fn request_code_lenses(cx: &mut Context) { let doc = doc!(cx.editor); let language_server = @@ -1787,6 +1779,8 @@ pub fn code_lenses_picker(cx: &mut Context) { request, move |editor, compositor, lenses: Option>| { if let Some(lenses) = lenses { + log::error!("lenses got: {:?}", lenses); + let doc = doc_mut!(editor, &doc_id); let doc_text = doc.text(); if let Some(current_url) = doc.url() { @@ -1797,36 +1791,8 @@ pub fn code_lenses_picker(cx: &mut Context) { .iter() .map(|l| map_code_lens(doc_text, l, offset_enc, language_server_id)) .collect(); - log::error!("lenses got: {:?}", lenses); - doc.set_code_lens(lenses.clone()); - let picker = Picker::new(lenses, (), |cx, meta, _action| { - let doc = doc!(cx.editor); - let language_server = language_server_with_feature!( - cx.editor, - doc, - LanguageServerFeature::CodeLens - ); - if let Some(cmd) = meta.command.clone() { - let future = match language_server.command(cmd) { - Some(future) => future, - None => { - cx.editor.set_error( - "Language server does not support executing commands", - ); - return; - } - }; - tokio::spawn(async move { - let res = future.await; - - if let Err(e) = res { - log::error!("execute LSP command: {}", e); - } - }); - } - }); - compositor.push(Box::new(picker)); + doc.set_code_lens(lenses.clone()); } else { editor.set_status("no lens found"); } diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 9363d64582e4b..7c9bbc85958c2 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -225,7 +225,7 @@ pub fn default() -> HashMap { "a" => code_action, "'" => last_picker, "l" => code_lens_under_cursor, - "L" => code_lenses_picker, + "L" => request_code_lenses, "g" => { "Debug (experimental)" sticky=true "l" => dap_launch, "r" => dap_restart, diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index ebdac9e2371ac..c79595dd3d107 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -57,6 +57,7 @@ pub fn diagnostic<'doc>( let info = theme.get("info"); let hint = theme.get("hint"); let diagnostics = &doc.diagnostics; + let lenses = &doc.code_lens; Box::new( move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| { @@ -73,7 +74,7 @@ pub fn diagnostic<'doc>( .language_servers_with_feature(LanguageServerFeature::Diagnostics) .any(|ls| ls.id() == d.language_server_id) }); - diagnostics_on_line.max_by_key(|d| d.severity).map(|d| { + if let Some(style) = diagnostics_on_line.max_by_key(|d| d.severity).map(|d| { write!(out, "●").ok(); match d.severity { Some(Severity::Error) => error, @@ -81,7 +82,14 @@ pub fn diagnostic<'doc>( Some(Severity::Info) => info, Some(Severity::Hint) => hint, } - }) + }) { + return Some(style); + }; + if let Some(_) = lenses.iter().find(|l| l.line == line) { + write!(out, "▶").ok(); + return Some(info); + } + None }, ) } diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e5e2641a8c5c7..12c4aa98bb0c3 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -451,6 +451,8 @@ impl View { add_annotations(other_inlay_hints, other_style); add_annotations(padding_after_inlay_hints, None); + // TODO: lens line annotation + text_annotations } diff --git a/runtime/themes/dracula_at_night.toml b/runtime/themes/dracula_at_night.toml index b2e3b9a9fc110..733adc7c93d35 100644 --- a/runtime/themes/dracula_at_night.toml +++ b/runtime/themes/dracula_at_night.toml @@ -58,6 +58,8 @@ "markup.quote" = { fg = "yellow", modifiers = ["italic"] } "markup.raw" = { fg = "foreground" } +"code_lens" = { underline = { color = "purple", style = "curl" } } + [palette] background = "#0e1419" background_dark = "#21222c" diff --git a/theme.toml b/theme.toml index d9f0326ac90b8..ac18b953c83fd 100644 --- a/theme.toml +++ b/theme.toml @@ -81,7 +81,7 @@ label = "honey" "diagnostic.warning" = { underline = { color = "lightning", style = "curl" } } "diagnostic.error" = { underline = { color = "apricot", style = "curl" } } -"code_lens" = { modifiers = ["underline"] } +"code_lens" = { underline = { color = "delta", style = "curl" } } warning = "lightning" error = "apricot"