[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa c4ffabc 083/139: Half-decent completion support
From: |
João Távora |
Subject: |
[elpa] externals/elpa c4ffabc 083/139: Half-decent completion support |
Date: |
Mon, 14 May 2018 09:53:41 -0400 (EDT) |
branch: externals/elpa
commit c4ffabcb5f95d8d2a3676006641362e188df52f8
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Half-decent completion support
* README.md: Update.
* eglot.el (eglot--kind-names): New variable.
(eglot--managed-mode): Handle completion-at-point-functions.
(eglot-completion-at-point): New function.
---
README.md | 3 ++-
eglot.el | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 955ef54..f70d15f 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,8 @@ server. To skip the guess and always be prompted use `C-u M-x
eglot`.
- [x] textDocument/didSave
- [ ] textDocument/codeAction
-- [ ] textDocument/completion (incl. completion/resolve)
+- [x] textDocument/completion
+- [ ] completionItem/resolve
- [x] textDocument/definition
- [ ] textDocument/documentHighlight
- [ ] textDocument/documentSymbol
diff --git a/eglot.el b/eglot.el
index f6bf010..2ab4781 100644
--- a/eglot.el
+++ b/eglot.el
@@ -757,6 +757,13 @@ Meaning only return locally if successful, otherwise exit
non-locally."
"Convert URI to a file path."
(url-filename (url-generic-parse-url (url-unhex-string uri))))
+(defconst eglot--kind-names
+ `((1 . "Text") (2 . "Method") (3 . "Function") (4 . "Constructor")
+ (5 . "Field") (6 . "Variable") (7 . "Class") (8 . "Interface")
+ (9 . "Module") (10 . "Property") (11 . "Unit") (12 . "Value")
+ (13 . "Enum") (14 . "Keyword") (15 . "Snippet") (16 . "Color")
+ (17 . "File") (18 . "Reference")))
+
;;; Minor modes
;;;
@@ -777,10 +784,11 @@ Meaning only return locally if successful, otherwise exit
non-locally."
(add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
(add-hook 'kill-buffer-hook 'eglot--signal-textDocument/didClose nil t)
(add-hook 'before-revert-hook 'eglot--signal-textDocument/didClose nil t)
- ;; (add-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen nil t)
+ ;;(add-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen nil t)
(add-hook 'before-save-hook 'eglot--signal-textDocument/willSave nil t)
(add-hook 'after-save-hook 'eglot--signal-textDocument/didSave nil t)
(add-hook 'xref-backend-functions 'eglot-xref-backend nil t)
+ (add-hook 'completion-at-point-functions #'eglot-completion-at-point nil t)
(flymake-mode 1))
(t
(remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t)
@@ -791,7 +799,8 @@ Meaning only return locally if successful, otherwise exit
non-locally."
;; (remove-hook 'after-revert-hook 'eglot--signal-textDocument/didOpen t)
(remove-hook 'before-save-hook 'eglot--signal-textDocument/willSave t)
(remove-hook 'after-save-hook 'eglot--signal-textDocument/didSave t)
- (remove-hook 'xref-backend-functions 'eglot-xref-backend t))))
+ (remove-hook 'xref-backend-functions 'eglot-xref-backend t)
+ (remove-hook 'completion-at-point-functions #'eglot-completion-at-point
t))))
(define-minor-mode eglot-mode
"Minor mode for all buffers managed by EGLOT in some way." nil
@@ -1353,6 +1362,48 @@ DUMMY is ignored"
: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)
+ (list
+ (if bounds (car bounds) (point))
+ (if bounds (cdr bounds) (point))
+ (completion-table-dynamic
+ (lambda (_ignored)
+ (let* ((resp (eglot--sync-request
+ proc
+ :textDocument/completion
+ (eglot--obj
+ :textDocument
(eglot--current-buffer-TextDocumentIdentifier)
+ :position (eglot--pos-to-lsp-position))))
+ (items (if (vectorp resp) resp
+ (plist-get resp :items))))
+ (eglot--mapply
+ (eglot--lambda (&key insertText label kind detail
+ documentation sortText)
+ (propertize insertText
+ :label label :kind kind :detail detail
+ :documentation documentation :sortText sortText))
+ items))))
+ :annotation-function
+ (lambda (what)
+ (let ((detail (get-text-property 0 :detail what))
+ (kind (get-text-property 0 :kind what)))
+ (format "%s%s"
+ detail
+ (if kind
+ (format " (%s)" (cdr (assoc kind eglot--kind-names)))
+ ""))))
+ :display-sort-function
+ (lambda (items)
+ (sort items (lambda (a b)
+ (string-lessp
+ (get-text-property 0 :sortText a)
+ (get-text-property 0 :sortText b)))))))))
+
;;; Dynamic registration
;;;
- [elpa] externals/elpa 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, (continued)
- [elpa] externals/elpa 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, João Távora, 2018/05/14
- [elpa] externals/elpa 6e76b08 100/139: Support workspace/applyEdit, João Távora, 2018/05/14
- [elpa] externals/elpa 3e0f1c3 122/139: Misc little adjustments for readability, João Távora, 2018/05/14
- [elpa] externals/elpa 9bf3166 136/139: Don't define a menu if nothing to show there for now, João Távora, 2018/05/14
- [elpa] externals/elpa 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/elpa c7bd095 118/139: Improve eglot-eldoc-function, João Távora, 2018/05/14
- [elpa] externals/elpa ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/elpa 8448d9b 133/139: Work with any old directory, no formal project needed, João Távora, 2018/05/14
- [elpa] externals/elpa 589e1ea 138/139: Remove an unused variable, João Távora, 2018/05/14
- [elpa] externals/elpa 571b08f 076/139: Fix the odd bug here and there, João Távora, 2018/05/14
- [elpa] externals/elpa c4ffabc 083/139: Half-decent completion support,
João Távora <=
- [elpa] externals/elpa 71e47d2 102/139: Fix odd bugs and tweak stuff, João Távora, 2018/05/14
- [elpa] externals/elpa ecd334f 101/139: Update README, João Távora, 2018/05/14
- [elpa] externals/elpa dda11dd 095/139: Try to fix some textDocument/completion bugs, João Távora, 2018/05/14
- [elpa] externals/elpa bfd82b5 108/139: Fancier RLS spinner, João Távora, 2018/05/14
- [elpa] externals/elpa c7b9002 116/139: Only call deferred actions after a full message has been received, João Távora, 2018/05/14
- [elpa] externals/elpa dc08e8e 134/139: Fix automatic project creation, João Távora, 2018/05/14
- [elpa] externals/elpa e63dad0 092/139: Simplify mode-line code with a helper., João Távora, 2018/05/14
- [elpa] externals/elpa e964abe 091/139: Get rid of eglot--buffer-open-count, João Távora, 2018/05/14
- [elpa] externals/elpa 37b7329 098/139: Reasonable textDocument/documentHighlight support, João Távora, 2018/05/14
- [elpa] externals/elpa 29f6b4c 129/139: Tweak README.md, João Távora, 2018/05/14