diff --git a/rc/lsp.kak b/rc/lsp.kak index 92d80b2d..b19d6f7e 100644 --- a/rc/lsp.kak +++ b/rc/lsp.kak @@ -196,10 +196,16 @@ define-command -hidden lsp-menu -params 1.. -docstring "Like menu but with promp cases= completion= nl=$(printf '\n.'); nl=${nl%.} + priority=1 while [ $# -gt 0 ]; do title=$1; shift command=$1; shift - completion="${completion}${title}${nl}" + if $kak_opt_lsp_have_kakoune_feature_completion_priority; then + completion="${completion}$(printf %s "${title}" | sed 's/\\|/\\|/g')|$priority${nl}" + priority=$((priority + 1)) + else + completion="${completion}${title}${nl}" + fi cases="${cases} $(shellquote "$title" s/¶/¶¶/g)) printf '%s\\n' $(shellquote "$command" s/¶/¶¶/g) @@ -214,9 +220,9 @@ define-command -hidden lsp-menu -params 1.. -docstring "Like menu but with promp ¶ §" "$cases" printf ' %s' "$on_abort" - printf ' -menu -shell-script-candidates %%§ + printf ' -menu %s -shell-script-candidates %%§ printf %%s %s - §\n' "$(shellquote "$completion")" + §\n' "$($kak_opt_lsp_have_kakoune_feature_completion_priority && printf %s -priority)" "$(shellquote "$completion")" } } catch %{ evaluate-commands %sh{ @@ -359,6 +365,13 @@ ${lsp_draft}\"\"\" } }} +declare-option -hidden bool lsp_have_kakoune_feature_completion_priority +declare-option -hidden completions lsp_have_kakoune_feature_completion_priority_tmp +try %{ + set-option global lsp_have_kakoune_feature_completion_priority_tmp 1.1@0 insert_text|on_select|menu|1 + set-option global lsp_have_kakoune_feature_completion_priority true +} + define-command -hidden lsp-completion -docstring "Request completions for the main cursor position" %{ try %{ # Fail if preceding character is a whitespace (by default; the trigger could be customized). diff --git a/src/language_features/code_action.rs b/src/language_features/code_action.rs index 0ff1479d..769f736b 100644 --- a/src/language_features/code_action.rs +++ b/src/language_features/code_action.rs @@ -144,7 +144,7 @@ fn editor_code_actions( return; } - let actions: Vec<_> = results + let mut actions: Vec<_> = results .into_iter() .flat_map(|(server_name, cmd)| { let cmd: Vec<_> = cmd @@ -222,6 +222,25 @@ fn editor_code_actions( return; } + actions.sort_by_key(|(_server, ca)| { + // TODO Group by server? + let empty = CodeActionKind::EMPTY; + let kind = match ca { + CodeActionOrCommand::Command(_) => &empty, + CodeActionOrCommand::CodeAction(action) => action.kind.as_ref().unwrap_or(&empty), + }; + // TODO These loosely follow what VSCode does, we should be more accurate. + match kind.as_str() { + "quickfix" => 0, + "refactor" => 1, + "refactor.extract" => 2, + "refactor.inline" => 3, + "refactor.rewrite" => 4, + "source" => 5, + "source.organizeImports" => 6, + _ => 7, + } + }); let titles_and_commands = actions .iter() .map(|(server_name, c)| {