diff --git a/acm/acm-backend-codeium.el b/acm/acm-backend-codeium.el index ce4d4e9111..254e343d61 100644 --- a/acm/acm-backend-codeium.el +++ b/acm/acm-backend-codeium.el @@ -151,9 +151,14 @@ (lisp-data-mode . 60))) (defun acm-backend-codeium-candidates (keyword) - (when (and acm-backend-codeium-items - (>= (length keyword) acm-backend-codeium-candidate-min-length)) - acm-backend-codeium-items)) + (if (and (boundp 'acm-backend-codeium-cache-candiates) + acm-backend-codeium-cache-candiates) + acm-backend-codeium-cache-candiates + (when (and acm-backend-codeium-items + (>= (length keyword) acm-backend-codeium-candidate-min-length)) + (setq-local acm-backend-codeium-cache-candiates acm-backend-codeium-items) + + acm-backend-codeium-items))) (defun acm-backend-codeium-candidate-expand (candidate-info bound-start &optional preview) ;; We need replace whole area with codeium label. @@ -172,7 +177,8 @@ (plist-get candidate :documentation)) (defun acm-backend-codeium-clean () - (setq-local acm-backend-codeium-items nil)) + (setq-local acm-backend-codeium-items nil) + (setq-local acm-backend-codeium-cache-candiates nil)) (provide 'acm-backend-codeium) ;;; acm-backend-codeium.el ends here diff --git a/acm/acm-backend-copilot.el b/acm/acm-backend-copilot.el index 7c7aa72e02..0345a02d40 100644 --- a/acm/acm-backend-copilot.el +++ b/acm/acm-backend-copilot.el @@ -54,7 +54,12 @@ in the proxy plist. For example: (defvar-local acm-backend-copilot-items nil) (defun acm-backend-copilot-candidates (keyword) - acm-backend-copilot-items) + (if (and (boundp 'acm-backend-copilot-cache-candiates) + acm-backend-copilot-cache-candiates) + acm-backend-copilot-cache-candiates + (setq-local acm-backend-copilot-cache-candiates acm-backend-copilot-items) + + acm-backend-copilot-items)) (defun acm-backend-copilot-candidate-expand (candidate-info bound-start &optional preview) ;; We need replace whole area with copilot label. @@ -71,5 +76,9 @@ in the proxy plist. For example: (defun acm-backend-copilot-candidate-doc (candidate) (plist-get candidate :documentation)) +(defun acm-backend-copilot-clean () + (setq-local acm-backend-copilot-items nil) + (setq-local acm-backend-copilot-cache-candiates nil)) + (provide 'acm-backend-copilot) ;;; acm-backend-copilot.el ends here diff --git a/acm/acm-backend-elisp.el b/acm/acm-backend-elisp.el index db94db2d01..384482de1f 100644 --- a/acm/acm-backend-elisp.el +++ b/acm/acm-backend-elisp.el @@ -111,18 +111,24 @@ (defvar acm-backend-elisp-symbols-update-size 0) (defun acm-backend-elisp-candidates (keyword) - (when (and (acm-is-elisp-mode-p) - (>= (length keyword) acm-backend-elisp-candidate-min-length)) - (mapcar - (lambda (elisp-symbol) - (let ((symbol-type (acm-backend-elisp-symbol-type (intern elisp-symbol)))) - (list :key elisp-symbol - :icon symbol-type - :label elisp-symbol - :display-label elisp-symbol - :annotation (capitalize symbol-type) - :backend "elisp"))) - acm-backend-elisp-items))) + (if (and (boundp 'acm-backend-elisp-cache-candiates) + acm-backend-elisp-cache-candiates) + acm-backend-elisp-cache-candiates + (when (and (acm-is-elisp-mode-p) + (>= (length keyword) acm-backend-elisp-candidate-min-length)) + (setq-local acm-backend-elisp-cache-candiates + (mapcar + (lambda (elisp-symbol) + (let ((symbol-type (acm-backend-elisp-symbol-type (intern elisp-symbol)))) + (list :key elisp-symbol + :icon symbol-type + :label elisp-symbol + :display-label elisp-symbol + :annotation (capitalize symbol-type) + :backend "elisp"))) + acm-backend-elisp-items)) + + acm-backend-elisp-cache-candiates))) (defun acm-backend-elisp-candidate-doc (candidate) (let* ((symbol (intern (plist-get candidate :label))) @@ -221,6 +227,10 @@ (append (acm-backend-elisp-local-symbols) (acm-backend-elisp-global-symbols))) +(defun acm-backend-elisp-clean () + (setq-local acm-backend-elisp-items nil) + (setq-local acm-backend-elisp-cache-candiates nil)) + (provide 'acm-backend-elisp) ;;; acm-backend-elisp.el ends here diff --git a/acm/acm-backend-lsp.el b/acm/acm-backend-lsp.el index 083e08de74..5350db7433 100644 --- a/acm/acm-backend-lsp.el +++ b/acm/acm-backend-lsp.el @@ -112,25 +112,29 @@ (defvar-local acm-backend-lsp-fetch-completion-item-ticker nil) (defun acm-backend-lsp-candidates (keyword) - (let* ((candidates (list))) - (when (and - (>= (length keyword) acm-backend-lsp-candidate-min-length) - (boundp 'acm-backend-lsp-items) - acm-backend-lsp-items - (boundp 'acm-backend-lsp-server-names) - acm-backend-lsp-server-names - (hash-table-p acm-backend-lsp-items)) - ;; Sort multi-server items by - (dolist (server-name acm-backend-lsp-server-names) - (when-let* ((server-items (gethash server-name acm-backend-lsp-items))) - (maphash (lambda (k v) - (add-to-list 'candidates v t)) - server-items)))) - - ;; NOTE: - ;; lsp-bridge has sort candidate at Python side, - ;; please do not do secondary sorting here, elisp is very slow. - candidates)) + (if (and (boundp 'acm-backend-lsp-cache-candidates) + acm-backend-lsp-cache-candidates) + acm-backend-lsp-cache-candidates + (let* ((candidates (list))) + (when (and + (>= (length keyword) acm-backend-lsp-candidate-min-length) + (boundp 'acm-backend-lsp-items) + acm-backend-lsp-items + (boundp 'acm-backend-lsp-server-names) + acm-backend-lsp-server-names + (hash-table-p acm-backend-lsp-items)) + (dolist (server-name acm-backend-lsp-server-names) + (when-let* ((server-items (gethash server-name acm-backend-lsp-items))) + (maphash (lambda (k v) + (add-to-list 'candidates v t)) + server-items)))) + + (setq-local acm-backend-lsp-cache-candidates candidates) + + ;; NOTE: + ;; lsp-bridge has sort candidate at Python side, + ;; please do not do secondary sorting here, elisp is very slow. + candidates))) (defun acm-backend-lsp-candidate-expand (candidate-info bound-start &optional preview) (let* ((label (plist-get candidate-info :label)) @@ -266,7 +270,8 @@ Doubles as an indicator of snippet support." (insert new-text)))) (defun acm-backend-lsp-clean () - (setq-local acm-backend-lsp-items (make-hash-table :test 'equal))) + (setq-local acm-backend-lsp-items (make-hash-table :test 'equal)) + (setq-local acm-backend-lsp-cache-candidates nil)) (provide 'acm-backend-lsp) diff --git a/acm/acm-backend-path.el b/acm/acm-backend-path.el index 90681d4c0d..c562b4a5b9 100644 --- a/acm/acm-backend-path.el +++ b/acm/acm-backend-path.el @@ -96,8 +96,13 @@ (defvar-local acm-backend-path-items nil) (defun acm-backend-path-candidates (keyword) - (when acm-enable-path - acm-backend-path-items)) + (if (and (boundp 'acm-backend-path-cache-candiates) + acm-backend-path-cache-candiates) + acm-backend-path-cache-candiates + (when acm-enable-path + (setq-local acm-backend-path-cache-candiates acm-backend-path-items) + + acm-backend-path-items))) (defun acm-backend-path-candidate-expand (candidate-info bound-start &optional preview) (let* ((keyword (acm-get-input-prefix)) @@ -114,6 +119,10 @@ (delete-region bound-start (point)) (insert (concat parent-dir file-name))))) +(defun acm-backend-path-clean () + (setq-local acm-backend-path-items nil) + (setq-local acm-backend-path-cache-candiates nil)) + (provide 'acm-backend-path) ;;; acm-backend-path.el ends here diff --git a/acm/acm-backend-search-file-words.el b/acm/acm-backend-search-file-words.el index b7169a0510..c656b99d18 100644 --- a/acm/acm-backend-search-file-words.el +++ b/acm/acm-backend-search-file-words.el @@ -108,17 +108,24 @@ (defvar acm-backend-search-file-words-bound-regex "^[\"' ]") (defun acm-backend-search-file-words-candidates (keyword) - (when (and acm-enable-search-file-words - (>= (length keyword) acm-backend-search-file-words-candidate-min-length)) - (mapcar - (lambda (candidate-label) - (list :key candidate-label - :icon "search" - :label candidate-label - :display-label candidate-label - :annotation "Search Word" - :backend "search-file-words")) - acm-backend-search-file-words-items))) + (if (and (boundp 'acm-backend-search-file-words-cache-candiates) + acm-backend-search-file-words-cache-candiates) + acm-backend-search-file-words-cache-candiates + + (when (and acm-enable-search-file-words + (>= (length keyword) acm-backend-search-file-words-candidate-min-length)) + (setq-local acm-backend-search-file-words-cache-candiates + (mapcar + (lambda (candidate-label) + (list :key candidate-label + :icon "search" + :label candidate-label + :display-label candidate-label + :annotation "Search Word" + :backend "search-file-words")) + acm-backend-search-file-words-items)) + + acm-backend-search-file-words-cache-candiates))) (defun acm-backend-search-file-words-candidate-expand (candidate-info bound-start &optional preview) (let ((beg (if (acm-is-elisp-mode-p) @@ -147,7 +154,8 @@ ))) (defun acm-backend-search-file-words-clean () - (setq-local acm-backend-search-file-words-items nil)) + (setq-local acm-backend-search-file-words-items nil) + (setq-local acm-backend-search-file-words-cache-candiates nil)) (provide 'acm-backend-search-file-words) diff --git a/acm/acm-backend-search-sdcv-words.el b/acm/acm-backend-search-sdcv-words.el index cb8228b7c2..c318196e85 100644 --- a/acm/acm-backend-search-sdcv-words.el +++ b/acm/acm-backend-search-sdcv-words.el @@ -106,7 +106,12 @@ you need set this value to `/usr/share/stardict/dic/stardict-oxford-gb-formated- (defvar-local acm-backend-search-sdcv-words-items nil) (defun acm-backend-search-sdcv-words-candidates (keyword) - acm-backend-search-sdcv-words-items) + (if (and (boundp 'acm-backend-search-sdcv-words-cache-candiates) + acm-backend-search-sdcv-words-cache-candiates) + acm-backend-search-sdcv-words-cache-candiates + (setq-local acm-backend-search-sdcv-words-cache-candiates acm-backend-search-sdcv-words-items) + + acm-backend-search-sdcv-words-items)) (defun acm-backend-search-sdcv-words-candidate-expand (candidate-info bound-start &optional preview) (if preview @@ -115,7 +120,8 @@ you need set this value to `/usr/share/stardict/dic/stardict-oxford-gb-formated- (insert (plist-get candidate-info :display-label)))) (defun acm-backend-search-sdcv-words-clean () - (setq-local acm-backend-search-sdcv-words-items nil)) + (setq-local acm-backend-search-sdcv-words-items nil) + (setq-local acm-backend-search-sdcv-words-cache-candiates nil)) (provide 'acm-backend-search-sdcv-words) diff --git a/acm/acm-backend-tabnine.el b/acm/acm-backend-tabnine.el index de94654885..61cd6e7acf 100644 --- a/acm/acm-backend-tabnine.el +++ b/acm/acm-backend-tabnine.el @@ -14,8 +14,13 @@ (defvar-local acm-backend-tabnine-items nil) (defun acm-backend-tabnine-candidates (keyword) - (when acm-backend-tabnine-items - acm-backend-tabnine-items)) + (if (and (boundp 'acm-backend-tabnine-cache-candiates) + acm-backend-tabnine-cache-candiates) + acm-backend-tabnine-cache-candiates + (when acm-backend-tabnine-items + (setq-local acm-backend-tabnine-cache-candiates acm-backend-tabnine-items) + + acm-backend-tabnine-items))) (defun acm-backend-tabnine-candidate-expand (candidate-info bound-start &optional preview) ;; Insert TabNine suggestion. @@ -36,7 +41,8 @@ (insert new_suffix)))))) (defun acm-backend-tabnine-clean () - (setq-local acm-backend-tabnine-items nil)) + (setq-local acm-backend-tabnine-items nil) + (setq-local acm-backend-tabnine-cache-candiates nil)) (provide 'acm-backend-tabnine) ;;; acm-backend-tabnine.el ends here diff --git a/acm/acm-backend-tailwind.el b/acm/acm-backend-tailwind.el index a4cba8d1a3..cb7ade206d 100644 --- a/acm/acm-backend-tailwind.el +++ b/acm/acm-backend-tailwind.el @@ -91,15 +91,25 @@ (defvar-local acm-backend-tailwind-items nil) (defun acm-backend-tailwind-candidates (keyword) - (mapcar - (lambda (tailwind-symbol) - (list :key tailwind-symbol - :icon "tailwind" - :label tailwind-symbol - :display-label tailwind-symbol - :annotation "Tailwind" - :backend "tailwind")) - acm-backend-tailwind-items)) + (if (and (boundp 'acm-backend-tailwind-cache-candiates) + acm-backend-tailwind-cache-candiates) + acm-backend-tailwind-cache-candiates + (setq-local acm-backend-tailwind-cache-candiates + (mapcar + (lambda (tailwind-symbol) + (list :key tailwind-symbol + :icon "tailwind" + :label tailwind-symbol + :display-label tailwind-symbol + :annotation "Tailwind" + :backend "tailwind")) + acm-backend-tailwind-items)) + + acm-backend-tailwind-cache-candiates)) + +(defun acm-backend-tailwind-clean () + (setq-local acm-backend-tailwind-items nil) + (setq-local acm-backend-tailwind-cache-candiates nil)) (provide 'acm-backend-tailwind) diff --git a/lsp-bridge.el b/lsp-bridge.el index e6b4d6e6fc..bee485aaff 100644 --- a/lsp-bridge.el +++ b/lsp-bridge.el @@ -1040,12 +1040,14 @@ So we build this macro to restore postion after code format." (defun lsp-bridge-completion--record-items (filename filehost - candidates position + candidates + position server-name completion-trigger-characters server-names) (lsp-bridge--with-file-buffer filename filehost ;; Save completion items. + (setq-local acm-backend-lsp-cache-candidates nil) (setq-local acm-backend-lsp-completion-position position) (setq-local acm-backend-lsp-completion-trigger-characters completion-trigger-characters) (setq-local acm-backend-lsp-server-names server-names) @@ -1434,6 +1436,7 @@ So we build this macro to restore postion after code format." (defun lsp-bridge-elisp-symbols-record (candidates) (setq-local acm-backend-elisp-items candidates) + (setq-local acm-backend-elisp-cache-candiates nil) (lsp-bridge-try-completion)) (defun lsp-bridge-search-words-index-files () @@ -1853,11 +1856,12 @@ Default is `bottom-right', you can choose other value: `top-left', `top-right', (not (file-exists-p (buffer-file-name)))) (save-buffer))) - (setq-local acm-backend-lsp-completion-trigger-characters nil) + (setq-local acm-backend-lsp-cache-candidates nil) (setq-local acm-backend-lsp-completion-position nil) + (setq-local acm-backend-lsp-completion-trigger-characters nil) + (setq-local acm-backend-lsp-server-names nil) (setq-local acm-backend-lsp-filepath (lsp-bridge-get-buffer-truename)) (setq-local acm-backend-lsp-items (make-hash-table :test 'equal)) - (setq-local acm-backend-lsp-server-names nil) (when lsp-bridge-enable-signature-help (acm-run-idle-func lsp-bridge-signature-help-timer lsp-bridge-signature-help-fetch-idle 'lsp-bridge-signature-help-fetch)) @@ -2249,13 +2253,27 @@ We need exclude `markdown-code-fontification:*' buffer in `lsp-bridge-monitor-be (defun lsp-bridge-search-backend--record-items (backend-name items) (pcase backend-name - ("codeium" (setq-local acm-backend-codeium-items items)) - ("copilot" (setq-local acm-backend-copilot-items items)) - ("file-words" (setq-local acm-backend-search-file-words-items items)) - ("sdcv-words" (setq-local acm-backend-search-sdcv-words-items items)) - ("tabnine" (setq-local acm-backend-tabnine-items items)) - ("tailwind-keywords" (setq-local acm-backend-tailwind-items items)) - ("paths" (setq-local acm-backend-path-items items))) + ("codeium" + (setq-local acm-backend-codeium-items items) + (setq-local acm-backend-codeium-cache-candiates nil)) + ("copilot" + (setq-local acm-backend-copilot-items items) + (setq-local acm-backend-copilot-cache-candiates nil)) + ("file-words" + (setq-local acm-backend-search-file-words-items items) + (setq-local acm-backend-search-file-words-cache-candiates nil)) + ("sdcv-words" + (setq-local acm-backend-search-sdcv-words-items items) + (setq-local acm-backend-search-sdcv-words-cache-candiates nil)) + ("tabnine" + (setq-local acm-backend-tabnine-items items) + (setq-local acm-backend-tabnine-cache-candiates nil)) + ("tailwind-keywords" + (setq-local acm-backend-tailwind-items items) + (setq-local acm-backend-tailwind-cache-candiates nil)) + ("paths" + (setq-local acm-backend-path-items items) + (setq-local acm-backend-path-cache-candiates nil))) (lsp-bridge-try-completion))