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

fix: lsp--find-workspaces-for workspace/executeCommand respects the target command #4494

Open
wants to merge 3 commits 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
36 changes: 23 additions & 13 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,13 @@ directory")
("textDocument/typeDefinition" :capability :typeDefinitionProvider)
("textDocument/typeHierarchy" :capability :typeHierarchyProvider)
("textDocument/diagnostic" :capability :diagnosticProvider)
("workspace/executeCommand" :capability :executeCommandProvider)
("workspace/executeCommand"
:capability :executeCommandProvider
:check-message (lambda (workspace msg)
(-let* (((&plist :method :params) msg)
((&plist :command) params))
(with-lsp-workspace workspace
(lsp-can-execute-command? command)))))
("workspace/symbol" :capability :workspaceSymbolProvider))

"Map methods to requirements.
Expand Down Expand Up @@ -6640,14 +6646,15 @@ REFERENCES? t when METHOD returns references."
(evil-set-command-property 'lsp-find-references :jump t)
(evil-set-command-property 'lsp-find-type-definition :jump t))

(defun lsp--workspace-method-supported? (check-command method capability workspace)
(defun lsp--workspace-method-supported? (check-command method check-message msg capability workspace)
(with-lsp-workspace workspace
(if check-command
(funcall check-command workspace)
(or
(when capability (lsp--capability capability))
(lsp--registered-capability method)
(and (not capability) (not check-command))))))
(cond
(check-command (funcall check-command workspace))
(check-message (funcall check-message workspace msg))
(t (or
(when capability (lsp--capability capability))
(lsp--registered-capability method)
(and (not capability) (not check-command)))))))

(defun lsp-disable-method-for-server (method server-id)
"Disable METHOD for SERVER-ID."
Expand All @@ -6662,20 +6669,23 @@ REFERENCES? t when METHOD returns references."
(eq server-id))
(lsp--workspace-method-supported? check-command
method
nil
nil
capability
workspace))))))
(alist-get method lsp-method-requirements nil nil 'string=)))

(defun lsp--find-workspaces-for (msg-or-method)
"Find all workspaces in the current project that can handle MSG."
(let ((method (if (stringp msg-or-method)
msg-or-method
(plist-get msg-or-method :method))))

(-let (((method . msg) (if (stringp msg-or-method)
(cons msg-or-method `(:method ,msg-or-method))
(cons (plist-get msg-or-method :method) msg-or-method))))
(-if-let (reqs (cdr (assoc method lsp-method-requirements)))
(-let (((&plist :capability :check-command) reqs))
(-let (((&plist :capability :check-command :check-message) reqs))
(-filter
(-partial #'lsp--workspace-method-supported?
check-command method capability)
check-command method check-message msg capability)
(lsp-workspaces)))
(lsp-workspaces))))

Expand Down
Loading