From 3b0bf1954b9bfdd1884541b039ab523b3a345453 Mon Sep 17 00:00:00 2001 From: Ivan Yonchovski Date: Mon, 16 Oct 2023 09:00:07 +0300 Subject: [PATCH] Introduce a function to disable a call for particular method for a server (#4171) 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) ``` --- lsp-mode.el | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lsp-mode.el b/lsp-mode.el index 01da57662b..5a42977276 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -935,7 +935,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" @@ -6433,6 +6433,32 @@ 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) @@ -6440,13 +6466,9 @@ REFERENCES? t when METHOD returns references." (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))))