Skip to content

Commit

Permalink
lsp-completion: Fix triggerKind on manual invokation (#2864)
Browse files Browse the repository at this point in the history
* lsp-completion: Fix triggerKind on manual invokation

* Create single download modal in Execution
  • Loading branch information
gexplorer committed May 14, 2021
1 parent 71eadde commit e9d5cea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 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 (when 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
22 changes: 22 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,26 @@
'("F" "daFo" "safo")
'("F" "daFo" "safo"))))

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

(provide 'lsp-completion-test)
;;; lsp-completion-test.el ends here
2 changes: 1 addition & 1 deletion test/windows-bootstrap.el
Expand Up @@ -30,7 +30,7 @@

(let* ((package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")))
(pkgs '(dash f lv ht spinner markdown-mode deferred)))
(pkgs '(dash f lv ht spinner markdown-mode deferred el-mock)))
(package-initialize)
(package-refresh-contents)

Expand Down

0 comments on commit e9d5cea

Please sign in to comment.