]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix a bug when response to definitions request is a single location
authorMichal Krzywkowski <k.michal@zoho.com>
Sun, 4 Nov 2018 15:59:05 +0000 (16:59 +0100)
committerMichal Krzywkowski <k.michal@zoho.com>
Sun, 4 Nov 2018 16:12:37 +0000 (17:12 +0100)
It's valid to return just a single Location for a definitions request.

* eglot.el (xref-backend-definitions): Coerce response to a vector.

lisp/progmodes/eglot.el

index 2b683f8874a60056ac85bcc08869fdcf7466ad7b..f11a14e11c5ecc021febf95cc84d48887d368d26 100644 (file)
@@ -1381,17 +1381,20 @@ DUMMY is ignored."
 (cl-defmethod xref-backend-definitions ((_backend (eql eglot)) identifier)
   (let* ((rich-identifier
           (car (member identifier eglot--xref-known-symbols)))
-         (location-or-locations
+         (definitions
           (if rich-identifier
               (get-text-property 0 :locations rich-identifier)
             (jsonrpc-request (eglot--current-server-or-lose)
                              :textDocument/definition
                              (get-text-property
-                              0 :textDocumentPositionParams identifier)))))
+                              0 :textDocumentPositionParams identifier))))
+         (locations
+          (and definitions
+               (if (vectorp definitions) definitions (vector definitions)))))
     (eglot--sort-xrefs
      (mapcar (jsonrpc-lambda (&key uri range)
                (eglot--xref-make identifier uri (plist-get range :start)))
-             location-or-locations))))
+             locations))))
 
 (cl-defmethod xref-backend-references ((_backend (eql eglot)) identifier)
   (unless (eglot--server-capable :referencesProvider)