(defun eglot-completion-at-point ()
"EGLOT's `completion-at-point' function."
- (let ((bounds (bounds-of-thing-at-point 'symbol))
+ (let* ((bounds (bounds-of-thing-at-point 'symbol))
(server (eglot--current-server-or-lose))
(completion-capability (eglot--server-capable :completionProvider))
+ (sort-completions (lambda (completions)
+ (sort completions
+ (lambda (a b)
+ (string-lessp
+ (or (get-text-property 0 :sortText a) "")
+ (or (get-text-property 0 :sortText b) ""))))))
+ (metadata `(metadata . ((display-sort-function . ,sort-completions))))
strings)
(when completion-capability
(list
(or (car bounds) (point))
(or (cdr bounds) (point))
- (completion-table-dynamic
- (lambda (_ignored)
- (let* ((resp (jsonrpc-request server
- :textDocument/completion
- (eglot--CompletionParams)
- :deferred :textDocument/completion
- :cancel-on-input t))
- (items (if (vectorp resp) resp (plist-get resp :items))))
- (setq
- strings
- (mapcar
- (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)))))
+ (lambda (string pred action)
+ (if (eq action 'metadata) metadata
+ (funcall
+ (completion-table-dynamic
+ (lambda (_ignored)
+ (let* ((resp (jsonrpc-request server
+ :textDocument/completion
+ (eglot--CompletionParams)
+ :deferred :textDocument/completion
+ :cancel-on-input t))
+ (items (if (vectorp resp) resp (plist-get resp :items))))
+ (setq
+ strings
+ (mapcar
+ (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)))))
+ string pred action)))
:annotation-function
(lambda (obj)
(eglot--dbind ((CompletionItem) detail kind insertTextFormat)
(and (eql insertTextFormat 2)
(eglot--snippet-expansion-fn)
" (snippet)"))))))
- :display-sort-function
- (lambda (items)
- (sort items (lambda (a b)
- (string-lessp
- (or (get-text-property 0 :sortText a) "")
- (or (get-text-property 0 :sortText b) "")))))
:company-doc-buffer
(lambda (obj)
(let* ((documentation