Skip to content

Commit

Permalink
Introduce a function to disable a call for particular method for a se…
Browse files Browse the repository at this point in the history
…rver

Typically this can be used when there are more than one servers and the user
wants particular calls to be disabled for one of them.

Example usage:

```
(lsp-disable-method-for-server "textDocument/hover" 'jdtls)
```
  • Loading branch information
yyoncho committed Sep 14, 2023
1 parent 266945b commit ec9905e
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ Changes take effect only when a new session is started."
We want to try the last workspace first when jumping into a library
directory")

(defconst lsp-method-requirements
(defvar lsp-method-requirements
'(("textDocument/callHierarchy" :capability :callHierarchyProvider)
("textDocument/codeAction" :capability :codeActionProvider)
("codeAction/resolve"
Expand Down Expand Up @@ -6432,20 +6432,42 @@ 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)
(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))))))

(defun lsp-disable-method-for-server (method server-id)
"Disable METHOD for SERVER-ID."
(cl-callf
(lambda (reqs)
(-let (((&plist :check-command :capability) reqs))
(list :check-command
(lambda (workspace)
(unless (-> workspace
lsp--workspace-client
lsp--client-server-id
(eq server-id))
(lsp--workspace-method-supported? check-command
method
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))))
(-if-let (reqs (cdr (assoc method lsp-method-requirements)))
(-let (((&plist :capability :check-command) reqs))
(--filter
(with-lsp-workspace it
(or
(when check-command (funcall check-command it))
(when capability (lsp--capability capability))
(lsp--registered-capability method)
(and (not capability) (not check-command))))
(-filter
(-partial #'lsp--workspace-method-supported?
check-command method capability)
(lsp-workspaces)))
(lsp-workspaces))))

Expand Down

0 comments on commit ec9905e

Please sign in to comment.