Skip to content

Commit

Permalink
lsp-completion: Fix triggerKind on manual invokation
Browse files Browse the repository at this point in the history
  • Loading branch information
gexplorer committed May 12, 2021
1 parent 2cfc735 commit 214d1de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cask
Expand Up @@ -25,4 +25,5 @@
(depends-on "espuds")
(depends-on "ecukes")
(depends-on "undercover")
(depends-on "deferred"))
(depends-on "deferred")
(depends-on "el-mock"))
8 changes: 5 additions & 3 deletions lsp-completion.el
Expand Up @@ -370,10 +370,12 @@ The MARKERS and PREFIX value will be attached to each candidate."

(defun lsp-completion--get-context (trigger-characters)
"Get completion context with provided TRIGGER-CHARACTERS."
(let* (trigger-char
(let* ((triggered-by-char (equal last-command 'self-insert-command))
(trigger-char (if triggered-by-char
(lsp-completion--looking-back-trigger-characterp
trigger-characters)))
(trigger-kind (cond
((setq trigger-char (lsp-completion--looking-back-trigger-characterp
trigger-characters))
(trigger-char
lsp/completion-trigger-kind-trigger-character)
((equal (cl-second lsp-completion--cache) :incomplete)
lsp/completion-trigger-kind-trigger-for-incomplete-completions)
Expand Down
12 changes: 12 additions & 0 deletions test/lsp-completion-test.el
Expand Up @@ -26,6 +26,7 @@

(require 'lsp-completion)
(require 'ert)
(require 'el-mock)

(ert-deftest lsp-completion-test-candidate-kind ()
(should (eq (lsp-completion--candidate-kind
Expand Down Expand Up @@ -79,5 +80,16 @@
'("F" "daFo" "safo")
'("F" "daFo" "safo"))))

(ert-deftest lsp-completion-test-get-context ()
(cl-labels ((do-test (command)
(let ((last-command command))
(hash-table-values (lsp-completion--get-context '("_"))))))
(mocklet ((lsp-completion--looking-back-trigger-characterp))
(should (equal (do-test 'next-line) '(1)))
(should (equal (do-test 'self-insert-command) '(1))))
(mocklet ((lsp-completion--looking-back-trigger-characterp => "_"))
(should (equal (do-test 'next-line) '(1)))
(should (equal (do-test 'self-insert-command) '(2 "_"))))))

(provide 'lsp-completion-test)
;;; lsp-completion-test.el ends here

0 comments on commit 214d1de

Please sign in to comment.