Skip to content

Commit

Permalink
Make sure template and tabnine candidates always show in first page o…
Browse files Browse the repository at this point in the history
…f completion menu.
  • Loading branch information
manateelazycat committed Mar 3, 2023
1 parent c804673 commit 6096e31
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -141,7 +141,6 @@ It should be noted that there are three scan modes of lsp-bridge:
* `acm-enable-yas`: yasnippet completion, enable by default
* `acm-enable-citre`: Integration with [citre(ctags)](https://github.com/universal-ctags/citre). Enable this to add citre (ctags) backend (disabled by default)
* `acm-doc-frame-max-lines`: Max line number of help documentation, default is 20
* `acm-snippet-insert-index`: The display position of snippet candidate in the complementary menu
* `acm-candidate-match-function`: The complete menu matching algorithm, the algorithm prefix of orderless-* needs to be installed additional [orderless](https://github.com/oantolin/orderless)
* `acm-backend-lsp-candidate-min-length`: The minimum characters to trigger completion, default is 0
* `acm-backend-lsp-enable-auto-import`: automatic insert import code, enable by default
Expand Down
1 change: 0 additions & 1 deletion README.zh-CN.md
Expand Up @@ -139,7 +139,6 @@ lsp-bridge 开箱即用, 安装好语言对应的[LSP 服务器](https://githu
* `acm-enable-yas`: yasnippet 补全,默认打开
* `acm-enable-citre`: [citre(ctags)](https://github.com/universal-ctags/citre) 补全,默认关闭
* `acm-doc-frame-max-lines`: 帮助窗口的最大行数, 默认是 20
* `acm-snippet-insert-index`: 代码模板候选词在补全菜单中的显示位置
* `acm-candidate-match-function`: 补全菜单匹配算法, orderless-* 开头的算法需要额外安装 [orderless](https://github.com/oantolin/orderless)
* `acm-backend-lsp-candidate-min-length`: LSP 补全最小的触发字符数, 默认是 0
* `acm-backend-lsp-enable-auto-import`: 支持自动导入, 默认打开
Expand Down
53 changes: 38 additions & 15 deletions acm/acm.el
Expand Up @@ -151,11 +151,6 @@
:type 'boolean
:group 'acm)

(defcustom acm-snippet-insert-index 8
"Insert index of snippet candidate of menu."
:type 'integer
:group 'acm)

(defcustom acm-candidate-match-function 'regexp-quote
"acm candidate match function."
:type '(choice (const regexp-quote)
Expand Down Expand Up @@ -345,12 +340,20 @@ Only calculate template candidate when type last character."
(backward-char (length keyword))
(acm-char-before)))
(candidates (list))
(mode-candidates-min-index 2)
(template-candidates-min-index 2)
lsp-candidates
path-candidates
yas-candidates
tabnine-candidates
tempel-candidates
mode-candidates
mode-first-part-candidates
mode-second-part-candidates
mode-candidates-split-index
template-candidates
template-first-part-candidates
template-second-part-candidates
citre-candidates)
(when acm-enable-tabnine
(setq tabnine-candidates (acm-backend-tabnine-candidates keyword)))
Expand Down Expand Up @@ -402,16 +405,36 @@ Only calculate template candidate when type last character."
(acm-cancel-timer acm-template-candidate-timer)
(setq acm-template-candidate-timer (run-with-timer 0.2 nil #'acm-template-candidate-update)))))

;; Insert snippet candidates in first page of menu.
(setq candidates
(if (> (length mode-candidates) acm-snippet-insert-index)
(append (cl-subseq mode-candidates 0 acm-snippet-insert-index)
yas-candidates
tempel-candidates
(cl-subseq mode-candidates acm-snippet-insert-index)
tabnine-candidates)
(append mode-candidates yas-candidates tempel-candidates tabnine-candidates)
))))
;; Build template candidates.
;; And make sure show part of template candidates in first completion menu.
(setq template-candidates (append yas-candidates tempel-candidates))
(if (> (length template-candidates) template-candidates-min-index)
(progn
(setq template-first-part-candidates (cl-subseq template-candidates 0 template-candidates-min-index))
(setq template-second-part-candidates (cl-subseq template-candidates template-candidates-min-index)))
(setq template-first-part-candidates template-candidates)
(setq template-second-part-candidates nil))

;; Make sure show part of TabNine candidates in first completion menu.
(setq mode-candidates-split-index
(max (- acm-menu-length (+ (length template-first-part-candidates) (length tabnine-candidates)))
mode-candidates-min-index))

;; Build mode candidates.
(if (> (length mode-candidates) mode-candidates-split-index)
(progn
(setq mode-first-part-candidates (cl-subseq mode-candidates 0 mode-candidates-split-index))
(setq mode-second-part-candidates (cl-subseq mode-candidates mode-candidates-split-index)))
(setq mode-first-part-candidates mode-candidates)
(setq mode-second-part-candidates nil))

;; Build all backend candidates.
(setq candidates (append mode-first-part-candidates
template-first-part-candidates
tabnine-candidates
template-second-part-candidates
mode-second-part-candidates)
)))

;; Return candidates.
(if acm-filter-overlay
Expand Down

0 comments on commit 6096e31

Please sign in to comment.