]> git.eshelyaron.com Git - emacs.git/commitdiff
Support completioncontext to help servers like ccls
authorJoão Távora <joaotavora@gmail.com>
Sun, 2 Dec 2018 10:54:09 +0000 (10:54 +0000)
committerJoão Távora <joaotavora@gmail.com>
Sun, 2 Dec 2018 11:00:12 +0000 (11:00 +0000)
* eglot.el (eglot-client-capabilities): Annouce
textDocument/completion/contextSupport.
(eglot--CompletionParams): New helper.
(eglot-completion-at-point): Use it.

GitHub-reference: close https://github.com/joaotavora/eglot/issues/173

lisp/progmodes/eglot.el

index b240e0e860b21bff291e5ea625ae412a9081197a..ac10b434c7e91d0696cb70d09ffd96e56af202c7 100644 (file)
@@ -374,7 +374,8 @@ treated as in `eglot-dbind'."
                                     `(:snippetSupport
                                       ,(if (eglot--snippet-expansion-fn)
                                            t
-                                         :json-false)))
+                                         :json-false))
+                                    :contextSupport t)
              :hover              `(:dynamicRegistration :json-false)
              :signatureHelp      `(:dynamicRegistration :json-false)
              :references         `(:dynamicRegistration :json-false)
@@ -1374,6 +1375,19 @@ THINGS are either registrations or unregisterations."
   (list :textDocument (eglot--TextDocumentIdentifier)
         :position (eglot--pos-to-lsp-position)))
 
+(defun eglot--CompletionParams ()
+  (append
+   (eglot--TextDocumentPositionParams)
+   `(:context
+     ,(if-let (trigger (and (eq last-command 'self-insert-command)
+                            (characterp last-input-event)
+                            (cl-find last-input-event
+                                     (eglot--server-capable :completionProvider
+                                                            :triggerCharacters)
+                                     :key (lambda (str) (aref str 0))
+                                     :test #'char-equal)))
+          `(:triggerKind 2 :triggerCharacter ,trigger) `(:triggerKind 1)))))
+
 (defvar-local eglot--recent-changes nil
   "Recent buffer changes as collected by `eglot--before-change'.")
 
@@ -1693,7 +1707,7 @@ is not active."
         (lambda (_ignored)
           (let* ((resp (jsonrpc-request server
                                         :textDocument/completion
-                                        (eglot--TextDocumentPositionParams)
+                                        (eglot--CompletionParams)
                                         :deferred :textDocument/completion
                                         :cancel-on-input t))
                  (items (if (vectorp resp) resp (plist-get resp :items))))