From 4982564292381e08f0d9fae083a113a225596837 Mon Sep 17 00:00:00 2001 From: Ivan Yonchovski Date: Fri, 22 Oct 2021 21:11:31 +0300 Subject: [PATCH] Implement support for textDocument/linkedEditingRange Fixes #2449 --- CHANGELOG.org | 2 ++ clients/lsp-xml.el | 2 +- lsp-iedit.el | 27 ++++++++++++++++++++++++--- lsp-mode.el | 4 ++-- lsp-protocol.el | 1 + 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index f0e86b4bfff..c4708e8c95d 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -1,5 +1,7 @@ * Changelog ** Unreleased 8.0.1 + * Added support for ~textDocument/linkedEditingRange~ via + ~lsp-iedit-linked-ranges~ and ~lsp-evil-multiedit-ranges~ (see [[https://github.com/emacs-lsp/lsp-mode/pull/3166][#3166]]) * Add [[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme][GraphQL Language Server]] for autocomplete graphql query * Added ~lsp-auto-touch-files~. When it is non-nil it will auto-create the file on the disk before sending ~textDocument/didOpen~. diff --git a/clients/lsp-xml.el b/clients/lsp-xml.el index 23f02ffa60b..209fa09edcb 100644 --- a/clients/lsp-xml.el +++ b/clients/lsp-xml.el @@ -189,7 +189,7 @@ Newlines and excess whitespace are removed." ("xml.catalogs" lsp-xml-catalogs) ("xml.trace.server" lsp-xml-trace-server))) -(defconst lsp-xml-jar-version "0.13.1") +(defconst lsp-xml-jar-version "0.18.0") (defconst lsp-xml-jar-name (format "org.eclipse.lemminx-%s-uber.jar" lsp-xml-jar-version)) diff --git a/lsp-iedit.el b/lsp-iedit.el index ff1af0daa10..9548b1addb1 100644 --- a/lsp-iedit.el +++ b/lsp-iedit.el @@ -76,11 +76,23 @@ See also `lsp-enable-symbol-highlighting'." (let ((highlights (lsp-request "textDocument/documentHighlight" (lsp--text-document-position-params))) (-compare-fn (-lambda ((&Location :range (&Range :start l-start :end l-end)) - (&Location :range (&Range :start r-start :end r-end))) - (and (lsp--position-equal l-start r-start) - (lsp--position-equal l-end r-end))))) + (&Location :range (&Range :start r-start :end r-end))) + (and (lsp--position-equal l-start r-start) + (lsp--position-equal l-end r-end))))) (lsp-iedit--on-ranges (mapcar #'lsp:document-highlight-range (-distinct highlights))))) +;;;###autoload +(defun lsp-iedit-linked-ranges () + "Start an `iedit' for `textDocument/linkedEditingRange'" + (interactive) + (unless (lsp-feature? "textDocument/linkedEditingRange") + (user-error "`textDocument/linkedEditingRange' is not supported by current server")) + + (-> (lsp-request "textDocument/linkedEditingRange" (lsp--text-document-position-params)) + (lsp:linked-editing-ranges-ranges) + (or (user-error "No editing ranges found")) + (lsp-iedit--on-ranges))) + ;;;###autoload (defun lsp-evil-multiedit-highlights () "Start an `evil-multiedit' operation on the documentHighlights at point. @@ -95,6 +107,15 @@ See also `lsp-enable-symbol-highlighting'." (lsp-iedit-highlights) (evil-multiedit-state)) +(defun lsp-evil-multiedit-ranges () + "Start an `evil-multiedit' for `textDocument/linkedEditingRange'" + (interactive) + (require 'evil-multiedit) + (when (fboundp 'ahs-clear) (ahs-clear)) + (setq evil-multiedit--dont-recall t) + (lsp-iedit-linked-ranges) + (evil-multiedit-state)) + (lsp-consistency-check lsp-iedit) (provide 'lsp-iedit) diff --git a/lsp-mode.el b/lsp-mode.el index cd27692c95c..0f056d1b3ec 100644 --- a/lsp-mode.el +++ b/lsp-mode.el @@ -835,6 +835,7 @@ directory") ("textDocument/formatting" :capability :documentFormattingProvider) ("textDocument/hover" :capability :hoverProvider) ("textDocument/implementation" :capability :implementationProvider) + ("textDocument/linkedEditingRange" :capability :linkedEditingRangeProvider) ("textDocument/onTypeFormatting" :capability :documentOnTypeFormattingProvider) ("textDocument/prepareRename" :check-command (lambda (workspace) @@ -3451,8 +3452,7 @@ disappearing, unset all the variables related to it." (publishDiagnostics . ((relatedInformation . t) (tagSupport . ((valueSet . [1 2]))) (versionSupport . t))) - (moniker . nil) - (linkedEditingRange . nil))) + (linkedEditingRange . ((dynamicRegistration . t))))) (window . ((workDoneProgress . t) (showMessage . nil) (showDocument . nil)))) diff --git a/lsp-protocol.el b/lsp-protocol.el index 87c5b0a0e9a..713e8347b55 100644 --- a/lsp-protocol.el +++ b/lsp-protocol.el @@ -604,6 +604,7 @@ See `-let' for a description of the destructuring mechanism." (FormattingOptions (:tabSize :insertSpaces) (:trimTrailingWhitespace :insertFinalNewline :trimFinalNewlines)) (HoverCapabilities nil (:contentFormat :dynamicRegistration)) (ImplementationCapabilities nil (:dynamicRegistration :linkSupport)) + (LinkedEditingRanges (:ranges) (:wordPattern)) (Location (:range :uri) nil) (MarkedString (:language :value) nil) (MarkupContent (:kind :value) nil)