emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 0e5e08d 51/69: Support goto-{declaration, impleme


From: João Távora
Subject: [elpa] externals/eglot 0e5e08d 51/69: Support goto-{declaration, implementation, typeDefinition}
Date: Sun, 20 Oct 2019 08:21:51 -0400 (EDT)

branch: externals/eglot
commit 0e5e08d29899b7724a78c70a90a17a1c3ac6444b
Author: Felicián Németh <address@hidden>
Commit: João Távora <address@hidden>

    Support goto-{declaration, implementation, typeDefinition}
    
    Closes #302.
    
    * eglot.el (eglot--xref-definitions-method): New variable.
    (xref-backend-definitions): Use it.
    (eglot-find-declaration, eglot-find-implementation,
    eglot-find-typeDefinition): New functions.
    
    * README.md (Language features): Add new capabilities.
    
    * eglot.el (eglot-client-capabilities): Add new capabilities.
    (eglot-ignored-server-capabilites): Add new capability.
---
 README.md |  7 ++++---
 eglot.el  | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 0987c40..820deee 100644
--- a/README.md
+++ b/README.md
@@ -241,7 +241,7 @@ provide enhanced code analysis via `xref-find-definitions`,
 To "unmanage" these buffers, shutdown the server with `M-x
 eglot-shutdown`.
 
-# Supported Protocol features (3.6)
+# Supported Protocol features
 
 ## General
 - [x] initialize
@@ -288,8 +288,9 @@ eglot-shutdown`.
 - [x] textDocument/hover
 - [x] textDocument/signatureHelp (fancy stuff with Python's [pyls][pyls])
 - [x] textDocument/definition
-- [ ] textDocument/typeDefinition (3.6.0)
-- [ ] textDocument/implementation (3.6.0)
+- [x] textDocument/typeDefinition (3.6.0)
+- [x] textDocument/implementation (3.6.0)
+- [x] textDocument/declaration (3.14)
 - [x] textDocument/references
 - [x] textDocument/documentHighlight
 - [x] textDocument/documentSymbol
diff --git a/eglot.el b/eglot.el
index 1dc5711..e3ead96 100644
--- a/eglot.el
+++ b/eglot.el
@@ -491,6 +491,9 @@ treated as in `eglot-dbind'."
                                          (:labelOffsetSupport t)))
              :references         `(:dynamicRegistration :json-false)
              :definition         `(:dynamicRegistration :json-false)
+             :declaration        `(:dynamicRegistration :json-false)
+             :implementation     `(:dynamicRegistration :json-false)
+             :typeDefinition     `(:dynamicRegistration :json-false)
              :documentSymbol     (list
                                   :dynamicRegistration :json-false
                                   :symbolKind `(:valueSet
@@ -1090,6 +1093,7 @@ under cursor."
            (const :tag "Go to definition" :definitionProvider)
            (const :tag "Go to type definition" :typeDefinitionProvider)
            (const :tag "Go to implementation" :implementationProvider)
+           (const :tag "Go to declaration" :implementationProvider)
            (const :tag "Find references" :referencesProvider)
            (const :tag "Highlight symbols automatically" 
:documentHighlightProvider)
            (const :tag "List symbols in buffer" :documentSymbolProvider)
@@ -1796,6 +1800,36 @@ Try to visit the target file for a richer summary line."
                 :textDocumentPositionParams
                 (eglot--TextDocumentPositionParams))))
 
+(defvar eglot--xref-definitions-method :textDocument/definition
+  "The LSP method to map xref-find-definitions call.")
+
+(defun eglot-find-declaration ()
+  "Find the declaration for the identifier at point.
+See `xref-find-definitions' and `xref-prompt-for-identifier'."
+  (interactive)
+  (eglot--find-location 'declaration))
+
+(defun eglot-find-implementation ()
+  "Find the implementation for the identifier at point.
+See `xref-find-definitions' and `xref-prompt-for-identifier'."
+  (interactive)
+  (eglot--find-location 'implementation))
+
+(defun eglot-find-typeDefinition ()
+  "Find the type definition for the identifier at point.
+See `xref-find-definitions' and `xref-prompt-for-identifier'."
+  (interactive)
+  (eglot--find-location 'typeDefinition))
+
+(defun eglot--find-location (kind)
+  (let* ((method-name (symbol-name kind))
+         (method (intern (concat ":textDocument/" method-name)))
+         (capability (intern (concat ":" method-name "Provider"))))
+    (if (eglot--server-capable capability)
+        (let ((eglot--xref-definitions-method method))
+          (call-interactively #'xref-find-definitions))
+      (eglot--error "Server is not a %sProvider" method-name))))
+
 (cl-defmethod xref-backend-definitions ((_backend (eql eglot)) identifier)
   (let* ((rich-identifier
           (car (member identifier eglot--xref-known-symbols)))
@@ -1803,7 +1837,7 @@ Try to visit the target file for a richer summary line."
           (if rich-identifier
               (get-text-property 0 :locations rich-identifier)
             (jsonrpc-request (eglot--current-server-or-lose)
-                             :textDocument/definition
+                             eglot--xref-definitions-method
                              (get-text-property
                               0 :textDocumentPositionParams identifier))))
          (locations



reply via email to

[Prev in Thread] Current Thread [Next in Thread]