From bdf57d5d4e888a6a7b4066b87497da8a8d9e36de Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Sun, 31 Jan 2021 17:28:49 -0800 Subject: [PATCH] Support activeparameter property for signatureinformation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit SignatureInformation.activeParameter is new in version 3.16.0 of the protocol. When non-nil, it is used in place of SignatureHelp.activeParameter. The latter was deemed insufficient in languages where multiple signatures for the same function may exist with arbitrary order of parameters, like Python. Co-authored-by: João Távora * eglot.el (eglot--lsp-interface-alist): Add SignatureInformation.activeParameter. * eglot.el (eglot--sig-info): Prioritize SignatureInformation.activeParameter over SignatureHelp.activeParameter. GitHub-reference: close https://github.com/joaotavora/eglot/issues/605 --- lisp/progmodes/eglot.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 51ed1c49a96..27094a2bd50 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -276,7 +276,7 @@ let the buffer grow forever." (ShowMessageParams (:type :message)) (ShowMessageRequestParams (:type :message) (:actions)) (SignatureHelp (:signatures) (:activeSignature :activeParameter)) - (SignatureInformation (:label) (:documentation :parameters)) + (SignatureInformation (:label) (:documentation :parameters :activeParameter)) (SymbolInformation (:name :kind :location) (:deprecated :containerName)) (DocumentSymbol (:name :range :selectionRange :kind) @@ -2265,14 +2265,15 @@ is not active." (if (vectorp contents) contents (list contents)) "\n"))) (when (or heading (cl-plusp (length body))) (concat heading body)))) -(defun eglot--sig-info (sigs active-sig active-param) +(defun eglot--sig-info (sigs active-sig sig-help-active-param) (cl-loop for (sig . moresigs) on (append sigs nil) for i from 0 concat - (eglot--dbind ((SignatureInformation) label documentation parameters) sig + (eglot--dbind ((SignatureInformation) label documentation parameters activeParameter) sig (with-temp-buffer (save-excursion (insert label)) - (let (params-start params-end) + (let ((active-param (or activeParameter sig-help-active-param)) + params-start params-end) ;; Ad-hoc attempt to parse label as () (when (looking-at "\\([^(]+\\)(\\([^)]+\\))") (setq params-start (match-beginning 2) params-end (match-end 2)) -- 2.39.5