Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate possible code-actions kinds dynamically #871

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ treated as in `eglot-dbind'."

(cl-defgeneric eglot-client-capabilities (server)
"What the EGLOT LSP client supports for SERVER."
(:method (_s)
(:method (server)
(list
:workspace (list
:applyEdit t
Expand Down Expand Up @@ -696,12 +696,9 @@ treated as in `eglot-dbind'."
:codeAction (list
:dynamicRegistration :json-false
:codeActionLiteralSupport
'(:codeActionKind
(:valueSet
["quickfix"
"refactor" "refactor.extract"
"refactor.inline" "refactor.rewrite"
"source" "source.organizeImports"]))
`(:codeActionKind
,`(:valueSet
,(vconcat (eglot--code-action-kinds server))))
:isPreferredSupport t)
:formatting `(:dynamicRegistration :json-false)
:rangeFormatting `(:dynamicRegistration :json-false)
Expand Down Expand Up @@ -758,7 +755,10 @@ treated as in `eglot-dbind'."
:accessor eglot--saved-initargs)
(inferior-process
:documentation "Server subprocess started automatically."
:accessor eglot--inferior-process))
:accessor eglot--inferior-process)
(code-action-kinds
:documentation "List of code-actions the client can request."
:accessor eglot--code-action-kinds))
:documentation
"Represents a server. Wraps a process for LSP communication.")

Expand Down Expand Up @@ -1138,6 +1138,9 @@ This docstring appeases checkdoc, that's all."
(setf (eglot--major-mode server) managed-major-mode)
(setf (eglot--language-id server) language-id)
(setf (eglot--inferior-process server) autostart-inferior-process)
(setf (eglot--code-action-kinds server)
'("quickfix" "refactor" "refactor.extract" "refactor.inline"
"refactor.rewrite" "source" "source.organizeImports"))
(run-hook-with-args 'eglot-server-initialized-hook server)
;; Now start the handshake. To honour `eglot-sync-connect'
;; maybe-sync-maybe-async semantics we use `jsonrpc-async-request'
Expand Down Expand Up @@ -1170,6 +1173,14 @@ This docstring appeases checkdoc, that's all."
(gethash project eglot--servers-by-project))
(setf (eglot--capabilities server) capabilities)
(setf (eglot--server-info server) serverInfo)
(setf (eglot--code-action-kinds server)
(cl-remove-duplicates
(append
(plist-get
(plist-get capabilities :codeActionProvider)
:codeActionKinds)
(eglot--code-action-kinds server))
:test 'equal))
(jsonrpc-notify server :initialized eglot--{})
(dolist (buffer (buffer-list))
(with-current-buffer buffer
Expand Down Expand Up @@ -2829,9 +2840,9 @@ at point. With prefix argument, prompt for ACTION-KIND."
(interactive
`(,@(eglot--region-bounds)
,(and current-prefix-arg
(completing-read "[eglot] Action kind: "
'("quickfix" "refactor.extract" "refactor.inline"
"refactor.rewrite" "source.organizeImports")))))
(completing-read
"[eglot] Action kind: "
(eglot--code-action-kinds (eglot--current-server-or-lose))))))
(unless (eglot--server-capable :codeActionProvider)
(eglot--error "Server can't execute code actions!"))
(let* ((server (eglot--current-server-or-lose))
Expand Down