From 098dfc2e7196a5495c2b9e67baef2b4b3ec11ec6 Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Fri, 30 Mar 2018 19:01:00 +0530 Subject: [PATCH] improve import autocomplete trigger autocomplete without requiring for the min chars to be typed (aka like we already do for method call). --- tide.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tide.el b/tide.el index 5d8ba39..dc4e5da 100644 --- a/tide.el +++ b/tide.el @@ -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 @@ -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