[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 15040a6 48/62: Improve snippet support
From: |
Stefan Monnier |
Subject: |
[elpa] externals/eglot 15040a6 48/62: Improve snippet support |
Date: |
Sat, 29 Sep 2018 17:13:36 -0400 (EDT) |
branch: externals/eglot
commit 15040a66a588103459c8c06589053bc3d3aa61f3
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Improve snippet support
* eglot.el (eglot-client-capabilities): Don't always declare
snippet support.
(eglot--snippet-expansion-fn): New helper.
(eglot-completion-at-point): Better annotations when snippets
are supported.
---
eglot.el | 60 +++++++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 19 deletions(-)
diff --git a/eglot.el b/eglot.el
index d38e250..3bd342d 100644
--- a/eglot.el
+++ b/eglot.el
@@ -204,7 +204,11 @@ let the buffer grow forever."
:dynamicRegistration :json-false
:willSave t :willSaveWaitUntil t :didSave t)
:completion (list :dynamicRegistration :json-false
- :completionItem `(:snippetSupport t))
+ :completionItem
+ `(:snippetSupport
+ ,(if (eglot--snippet-expansion-fn)
+ t
+ :json-false)))
:hover `(:dynamicRegistration :json-false)
:signatureHelp `(:dynamicRegistration :json-false)
:references `(:dynamicRegistration :json-false)
@@ -698,6 +702,13 @@ If optional MARKER, return a marker instead"
(let ((retval (url-filename (url-generic-parse-url (url-unhex-string uri)))))
(if (eq system-type 'windows-nt) (substring retval 1) retval)))
+(defun eglot--snippet-expansion-fn ()
+ "Compute a function to expand snippets.
+Doubles as an indicator of snippet support."
+ (and (boundp 'yas-minor-mode)
+ (symbol-value 'yas-minor-mode)
+ 'yas-expand-snippet))
+
(defconst eglot--kind-names
`((1 . "Text") (2 . "Method") (3 . "Function") (4 . "Constructor")
(5 . "Field") (6 . "Variable") (7 . "Class") (8 . "Interface")
@@ -1387,25 +1398,36 @@ is not active."
:cancel-on-input t))
(items (if (vectorp resp) resp (plist-get resp :items))))
(mapcar
- (jsonrpc-lambda (&rest all &key label insertText
&allow-other-keys)
- (let ((insert (or insertText (string-trim-left label))))
- (add-text-properties 0 1 all insert)
- (put-text-property 0 1 'eglot--lsp-completion all insert)
- insert))
+ (jsonrpc-lambda (&rest all &key label insertText insertTextFormat
+ &allow-other-keys)
+ (let ((completion
+ (cond ((and (eql insertTextFormat 2)
+ (eglot--snippet-expansion-fn))
+ (string-trim-left label))
+ (t
+ (or insertText (string-trim-left label))))))
+ (add-text-properties 0 1 all completion)
+ (put-text-property 0 1 'eglot--lsp-completion all completion)
+ completion))
items))))
:annotation-function
(lambda (obj)
- (cl-destructuring-bind (&key detail documentation kind
&allow-other-keys)
+ (cl-destructuring-bind (&key detail kind insertTextFormat
+ &allow-other-keys)
(text-properties-at 0 obj)
- (let ((annotation
- (or (and documentation
- (replace-regexp-in-string
- "\n.*" "" (eglot--format-markup documentation)))
- detail
- (cdr (assoc kind eglot--kind-names)))))
+ (let* ((detail (and (stringp detail)
+ (not (string= detail ""))
+ detail))
+ (annotation
+ (or detail
+ (cdr (assoc kind eglot--kind-names)))))
(when annotation
- (concat " " (propertize annotation
- 'face
'font-lock-function-name-face))))))
+ (concat " "
+ (propertize annotation
+ 'face 'font-lock-function-name-face)
+ (and (eql insertTextFormat 2)
+ (eglot--snippet-expansion-fn)
+ " (snippet)"))))))
:display-sort-function
(lambda (items)
(sort items (lambda (a b)
@@ -1434,10 +1456,10 @@ is not active."
insertText
&allow-other-keys)
(text-properties-at 0 obj)
- (when (and (eql insertTextFormat 2)
- (fboundp 'yas-expand-snippet))
- (delete-region (- (point) (length obj)) (point))
- (funcall 'yas-expand-snippet insertText))
+ (when-let ((fn (and (eql insertTextFormat 2)
+ (eglot--snippet-expansion-fn))))
+ (delete-region (car bounds) (point))
+ (funcall fn insertText))
(eglot--signal-textDocument/didChange)
(eglot-eldoc-function)))))))
- [elpa] externals/eglot fd7e587 27/62: Require jsonrpc.el 1.0.2 (GNU ELPA didn't build 1.0.1), (continued)
- [elpa] externals/eglot fd7e587 27/62: Require jsonrpc.el 1.0.2 (GNU ELPA didn't build 1.0.1), Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 99fd6a4 30/62: * eglot.el (eglot-cquery): Capitalize docstring., Stefan Monnier, 2018/09/29
- [elpa] externals/eglot fdd021c 26/62: Close #61: Snappier completions that don't hinder typing, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 22b0c89 41/62: Add kotlin-language-server (#70), Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 3ffea45 44/62: Close #50: Support snippet completions, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot e711bdb 47/62: Add go-langserver (#74), Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 83d7025 36/62: Close #68: Implement asynchronous server connection, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 2355e17 23/62: Per #63: Accept functions as entries in eglot-server-programs, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot c0f9db7 46/62: Per #74: Don't error if server replies with empty hover message, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot be15bb1 43/62: Per #74: Fix eglot-capabilities when querying for multiple features, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 15040a6 48/62: Improve snippet support,
Stefan Monnier <=
- [elpa] externals/eglot d88f6aa 54/62: Close #86: Handle case when :textDocumentSync isn't a number, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 42fffa5 16/62: Close #54: Correctly make LSP positions in narrowed buffers, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot e935718 20/62: Fix placement of diagnostics with same start and end positions, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 88ebed6 17/62: Implement TextDocument/rangeFormatting, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 792dc6b 28/62: * eglot.el (advice-add jsonrpc-request): Add &allow-other-keys, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 21886be 08/62: Close #44: Robustify in the face of manual mode changes, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 6b14711 18/62: * eglot.el (eglot-client-capabilities): Fix a typo., Stefan Monnier, 2018/09/29
- [elpa] externals/eglot 4c019bd 24/62: * eglot.el (eglot-initialization-options): Fix spurious typo., Stefan Monnier, 2018/09/29
- [elpa] externals/eglot a62c2da 25/62: Close #60: Notify server of recent changes before save notification, Stefan Monnier, 2018/09/29
- [elpa] externals/eglot c8191b2 32/62: Improve eglot-execute-command API to ease overriding by servers, Stefan Monnier, 2018/09/29