Skip to content

Commit

Permalink
Use flag-lines after for inlay code lenses
Browse files Browse the repository at this point in the history
Closes #727
  • Loading branch information
krobelus committed Feb 27, 2024
1 parent 8fda0d7 commit 053dde5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased

Breaking changes:
- New default server for Nix, [`nil`](https://github.com/oxalica/nil), replacing `rnix-lsp`.
- Inlay code lenses (used by OCaml and Haskell language servers) are now shown after the referenced line. This requires Kakoune version >= 2024.
- `lsp_hover_max_lines` now more directly controls the lines of information in the hover box.
- `lsp_hover_max_lines` has been deprecated for `lsp_hover_max_info_lines`. `lsp_hover_max_lines` now defaults to `-1` and when it is `-1` `lsp_hover_max_info_lines` is used to control lines of information in the hover box.

Expand Down
4 changes: 2 additions & 2 deletions rc/lsp.kak
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ declare-option -hidden int lsp_timestamp -1
declare-option -hidden range-specs lsp_references
declare-option -hidden range-specs lsp_semantic_tokens
declare-option -hidden range-specs lsp_inlay_hints
declare-option -hidden range-specs lsp_inlay_code_lenses
declare-option -hidden line-specs lsp_inlay_code_lenses
declare-option -hidden line-specs lsp_code_lenses 0 '0| '
declare-option -hidden str lsp_project_root

Expand Down Expand Up @@ -2310,7 +2310,7 @@ define-command lsp-inlay-hints-disable -params 1 -docstring "lsp-inlay-hints-dis
} -shell-script-candidates %{ printf '%s\n' buffer global window }

define-command lsp-inlay-code-lenses-enable -params 1 -docstring "lsp-inlay-code-lenses-enable <scope>: enable inlay code lenses for <scope>" %{
add-highlighter "%arg{1}/lsp_inlay_code_lenses" replace-ranges lsp_inlay_code_lenses
add-highlighter "%arg{1}/lsp_inlay_code_lenses" flag-lines -after Default lsp_inlay_code_lenses
} -shell-script-candidates %{ printf '%s\n' buffer global window }

define-command lsp-inlay-code-lenses-disable -params 1 -docstring "lsp-inlay-code-lenses-disable <scope>: disable inlay code lenses for <scope>" %{
Expand Down
7 changes: 3 additions & 4 deletions src/language_features/code_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,21 @@ fn editor_code_lens(
}
};
let version = document.version;
let range_specs = lenses
let line_specs = lenses
.iter()
.map(|(server_name, lens)| {
let server = &ctx.language_servers[server_name];
let label = lens.command.as_ref().map_or("", |v| &v.title);
let position =
lsp_position_to_kakoune(&lens.range.start, &document.text, server.offset_encoding);
let line = position.line;
let column = position.column;
lazy_static! {
static ref CODE_LENS_INDICATOR: &'static str =
wcwidth::expected_width_or_fallback("🔎", 2, "[L]");
}

editor_quote(&format!(
"{line}.{column}+0|{{InlayCodeLens}}[{} {}] ",
"{line}|{{InlayCodeLens}}[{} {}] ",
*CODE_LENS_INDICATOR,
escape_tuple_element(&escape_kakoune_markup(label))
))
Expand All @@ -92,7 +91,7 @@ fn editor_code_lens(
let line_flags = gather_line_flags(ctx, buffile).0;
let command = formatdoc!(
"evaluate-commands \"set-option buffer lsp_diagnostic_lines {version} {line_flags} '0|%opt[lsp_diagnostic_line_error_sign]'\"
set-option buffer lsp_inlay_code_lenses {version} {range_specs}",
set-option buffer lsp_inlay_code_lenses {version} {line_specs}",
);
let command = format!(
"evaluate-commands -buffer {} %§{}§",
Expand Down

0 comments on commit 053dde5

Please sign in to comment.