[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa af14364 093/139: Only request stuff that server sa
From: |
João Távora |
Subject: |
[elpa] externals/elpa af14364 093/139: Only request stuff that server says it's capable of |
Date: |
Mon, 14 May 2018 09:53:43 -0400 (EDT) |
branch: externals/elpa
commit af143643bbdb0764812c7f4a8e342ce5f9b20c7c
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Only request stuff that server says it's capable of
* eglot.el (eglot--server-capable): New helper.
(eglot-xref-backend)
(xref-backend-identifier-completion-table)
(xref-backend-references, xref-backend-apropos)
(eglot-completion-at-point, eglot-eldoc-function): Use it.
---
eglot.el | 98 +++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 53 insertions(+), 45 deletions(-)
diff --git a/eglot.el b/eglot.el
index 02439df..7cc3756 100644
--- a/eglot.el
+++ b/eglot.el
@@ -740,6 +740,10 @@ Meaning only return locally if successful, otherwise exit
non-locally."
(font-lock-ensure)
(buffer-string)))))
+(defun eglot--server-capable (feat)
+ "Determine if current server is capable of FEAT."
+ (plist-get (eglot--capabilities (eglot--current-process-or-lose)) feat))
+
;;; Minor modes
;;;
@@ -1158,7 +1162,9 @@ Calls REPORT-FN maybe if server publishes diagnostics in
time."
;; make the server report new diagnostics.
(eglot--signal-textDocument/didChange))
-(defun eglot-xref-backend () "EGLOT xref backend." 'eglot)
+(defun eglot-xref-backend ()
+ "EGLOT xref backend."
+ (when (eglot--server-capable :definitionProvider) 'eglot))
(defvar eglot--xref-known-symbols nil)
@@ -1179,26 +1185,27 @@ DUMMY is ignored"
(plist-get position :character))))
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
- (let ((proc (eglot--current-process-or-lose))
- (text-id (eglot--current-buffer-TextDocumentIdentifier)))
- (completion-table-with-cache
- (lambda (string)
- (setq eglot--xref-known-symbols
- (eglot--mapply
- (eglot--lambda (&key name kind location containerName)
- (propertize name
- :position (plist-get
- (plist-get location :range)
- :start)
- :locations (list location)
- :textDocument text-id
- :kind kind
- :containerName containerName))
- (eglot--sync-request proc
- :textDocument/documentSymbol
- (eglot--obj
- :textDocument text-id))))
- (all-completions string eglot--xref-known-symbols)))))
+ (when (eglot--server-capable :documentSymbolProvider)
+ (let ((proc (eglot--current-process-or-lose))
+ (text-id (eglot--current-buffer-TextDocumentIdentifier)))
+ (completion-table-with-cache
+ (lambda (string)
+ (setq eglot--xref-known-symbols
+ (eglot--mapply
+ (eglot--lambda (&key name kind location containerName)
+ (propertize name
+ :position (plist-get
+ (plist-get location :range)
+ :start)
+ :locations (list location)
+ :textDocument text-id
+ :kind kind
+ :containerName containerName))
+ (eglot--sync-request proc
+ :textDocument/documentSymbol
+ (eglot--obj
+ :textDocument text-id))))
+ (all-completions string eglot--xref-known-symbols))))))
(cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot)))
(let ((symatpt (symbol-at-point)))
@@ -1226,6 +1233,7 @@ DUMMY is ignored"
location-or-locations)))
(cl-defmethod xref-backend-references ((_backend (eql eglot)) identifier)
+ (unless (eglot--server-capable :referencesProvider) (cl-return nil))
(let* ((identifier (if (get-text-property 0 :position identifier)
identifier
(car (member identifier eglot--xref-known-symbols))))
@@ -1234,8 +1242,7 @@ DUMMY is ignored"
(textDocument
(and identifier (get-text-property 0 :textDocument identifier))))
(unless (and position textDocument)
- (eglot--error "Sorry, can't discover where %s is in the workspace"
- identifier))
+ (eglot--error "Don't know where %s is in the workspace" identifier))
(eglot--mapply
(eglot--lambda (&key uri range)
(eglot--xref-make identifier uri (plist-get range :start)))
@@ -1249,21 +1256,21 @@ DUMMY is ignored"
:context (eglot--obj :includeDeclaration t))))))
(cl-defmethod xref-backend-apropos ((_backend (eql eglot)) pattern)
- (eglot--mapply
- (eglot--lambda (&key name location &allow-other-keys)
- (let ((range (plist-get location :range))
- (uri (plist-get location :uri)))
- (eglot--xref-make name uri (plist-get range :start))))
- (eglot--sync-request (eglot--current-process-or-lose)
- :workspace/symbol
- (eglot--obj :query pattern))))
+ (when (eglot--server-capable :workspaceSymbolProvider)
+ (eglot--mapply
+ (eglot--lambda (&key name location &allow-other-keys)
+ (let ((range (plist-get location :range))
+ (uri (plist-get location :uri)))
+ (eglot--xref-make name uri (plist-get range :start))))
+ (eglot--sync-request (eglot--current-process-or-lose)
+ :workspace/symbol
+ (eglot--obj :query pattern)))))
(defun eglot-completion-at-point ()
"EGLOT's `completion-at-point' function."
(let ((bounds (bounds-of-thing-at-point 'sexp))
(proc (eglot--current-process-or-lose)))
- (when (plist-get (eglot--capabilities proc)
- :completionProvider)
+ (when (eglot--server-capable :completionProvider)
(list
(or (car bounds) (point))
(or (cdr bounds) (point))
@@ -1299,18 +1306,19 @@ DUMMY is ignored"
(defun eglot-eldoc-function ()
"EGLOT's `eldoc-documentation-function' function."
- (eglot--request (eglot--current-process-or-lose)
- :textDocument/hover
- (eglot--obj
- :textDocument (eglot--current-buffer-TextDocumentIdentifier)
- :position (eglot--pos-to-lsp-position))
- :success-fn (eglot--lambda (&key contents _range)
- (eldoc-message
- (mapconcat #'eglot--format-markup
- (if (vectorp contents)
- contents
- (list contents))
- "\n"))))
+ (when (eglot--server-capable :hoverProvider)
+ (eglot--request (eglot--current-process-or-lose)
+ :textDocument/hover
+ (eglot--obj
+ :textDocument
(eglot--current-buffer-TextDocumentIdentifier)
+ :position (eglot--pos-to-lsp-position))
+ :success-fn (eglot--lambda (&key contents _range)
+ (eldoc-message
+ (mapconcat #'eglot--format-markup
+ (if (vectorp contents)
+ contents
+ (list contents))
+ "\n")))))
nil)
- [elpa] externals/elpa e7ffc31 067/139: Make reported capabilities into its own function, (continued)
- [elpa] externals/elpa e7ffc31 067/139: Make reported capabilities into its own function, João Távora, 2018/05/14
- [elpa] externals/elpa c2862f4 063/139: Don't auto-reconnect if last attempt lasted less than 3 seconds, João Távora, 2018/05/14
- [elpa] externals/elpa e86f9b4 073/139: New helper eglot--sync-request, João Távora, 2018/05/14
- [elpa] externals/elpa 95187cf 058/139: Connect to LSP server via TCP, João Távora, 2018/05/14
- [elpa] externals/elpa f8bfb7e 064/139: Handle requests from server correctly, João Távora, 2018/05/14
- [elpa] externals/elpa 8160cd4 071/139: Handle dynamic registration in general (but nothing specific yet), João Távora, 2018/05/14
- [elpa] externals/elpa 9ff97a6 079/139: Increase request timeout length to 10 seconds, João Távora, 2018/05/14
- [elpa] externals/elpa 193c57d 075/139: Half-decent xref support, João Távora, 2018/05/14
- [elpa] externals/elpa d254f97 082/139: Solve another textDocument/didChange bug, João Távora, 2018/05/14
- [elpa] externals/elpa a7ddce6 080/139: Support javascript's javascript-typescript-langserver, João Távora, 2018/05/14
- [elpa] externals/elpa af14364 093/139: Only request stuff that server says it's capable of,
João Távora <=
- [elpa] externals/elpa d33a9b5 103/139: Simplify eglot--signal-textDocument/didChange, João Távora, 2018/05/14
- [elpa] externals/elpa 56c2e1d 104/139: Get rid of eglot-mode, João Távora, 2018/05/14
- [elpa] externals/elpa bbc64b4 087/139: Clean up client capabilities, João Távora, 2018/05/14
- [elpa] externals/elpa 23b79e0 111/139: Shorten summary line to appease package-lint.el, João Távora, 2018/05/14
- [elpa] externals/elpa 24466a9 096/139: When killing server, always wait 3 seconds, João Távora, 2018/05/14
- [elpa] externals/elpa 3a6c637 099/139: Support textDocument/rename, João Távora, 2018/05/14
- [elpa] externals/elpa 458bc69 110/139: More correctly setup rust-mode-related autoloads, João Távora, 2018/05/14
- [elpa] externals/elpa 3dcbc30 109/139: Add minimal headers, commentary and autoloads, João Távora, 2018/05/14
- [elpa] externals/elpa 581608f 115/139: Resist server failure during synchronous requests, João Távora, 2018/05/14
- [elpa] externals/elpa 41f5922 137/139: Now send willSaveWaitUntil, João Távora, 2018/05/14