Skip to content

Commit

Permalink
improve import autocomplete
Browse files Browse the repository at this point in the history
trigger autocomplete without requiring for the min chars to be
typed (aka like we already do for method call).
  • Loading branch information
ananthakumaran committed Mar 30, 2018
1 parent 0db094b commit 098dfc2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tide.el
Expand Up @@ -1202,7 +1202,14 @@ in the file that are similar to the error at point."
(string-equal modifier-b "declare"))))

(defun tide-completion-prefix ()
(company-grab-symbol-cons "\\." 1))
(if (and (tide-in-string-p)
(looking-back
(rx (or (and "import" (1+ space) (or ?\" ?') (0+ (not (any ?\" ?'))))
(and "from" (1+ space) (or ?\" ?') (0+ (not (any ?\" ?'))))
(and "import(" (or ?\" ?') (0+ (not (any ?\" ?'))))
(and "require(" (or ?\" ?') (0+ (not (any ?\" ?'))))))))
(cons (company-grab (rx (or ?/ ?\" ?') (group (0+ (not (any ?\" ?'))))) 1) t)
(company-grab-symbol-cons "\\." 1)))

(defun tide-member-completion-p (prefix)
(save-excursion
Expand All @@ -1227,10 +1234,10 @@ in the file that are similar to the error at point."
filtered))))

(defun tide-command:completions (prefix cb)
(let* ((file-location
`(:file ,(tide-buffer-file-name) :line ,(tide-line-number-at-pos) :offset ,(- (tide-current-offset) (length prefix)) :includeExternalModuleExports ,tide-completion-enable-autoimport-suggestions :includeInsertTextCompletions t)))
(when (not (tide-member-completion-p prefix))
(setq file-location (plist-put file-location :prefix prefix)))
(let ((file-location
`(:file ,(tide-buffer-file-name) :line ,(tide-line-number-at-pos) :offset ,(- (tide-current-offset) (length prefix)) :includeExternalModuleExports ,tide-completion-enable-autoimport-suggestions :includeInsertTextCompletions t)))
(when (and (not (tide-in-string-p)) (not (tide-member-completion-p prefix)))
(setq file-location (-concat file-location `(:prefix ,prefix))))
(tide-send-command
"completions"
file-location
Expand Down

0 comments on commit 098dfc2

Please sign in to comment.