Skip to content

Commit

Permalink
Add new option acm-backend-lsp-frontend-filter-p
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed May 6, 2024
1 parent 7caac7c commit 6802f79
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ lsp-bridge provides support for more than two language servers for many language
- `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-candidate-match-function`: lsp-bridge frontend filter algorithm for candidates, options include `'regexp-quote`, `'orderless-flex`, `'orderless-literal`, `'orderless-prefixes`, `'orderless-regexp`, `'orderless-initialism`, default is `nil`, meaning the default only performs backend filtering (refer to `acm-backend-lsp-match-mode`), and does not perform frontend filtering. orderless-* started algorithms require additional installation of [orderless](https://github.com/oantolin/orderless)
- `acm-candidate-match-function`: lsp-bridge frontend filter algorithm for candidates, options include `'regexp-quote`, `'orderless-flex`, `'orderless-literal`, `'orderless-prefixes`, `'orderless-regexp`, `'orderless-initialism`, default is `regexp-quote`, orderless-* started algorithms require additional installation of [orderless](https://github.com/oantolin/orderless)
- `acm-completion-backend-merge-order`: Customize the order of the completion backends, default order is: first part of mode candidate, first part of template candidates, tabnine/copilot/codeium, second part of template candidates, second part of mode candidates, set `acm-completion-mode-candidates-merge-order` customize mode candidates order
- `acm-completion-mode-candidates-merge-order`: Customize the order of the mode candidates, the display order for mode candidates, default order: Elisp、 LSP、 Jupyter、 Ctags、 Citre、 ROAM、 Word、 Telegra
- `acm-backend-lsp-candidate-min-length`: The minimum characters to trigger lsp completion, default is 0
Expand All @@ -333,12 +333,13 @@ lsp-bridge provides support for more than two language servers for many language
- `acm-backend-search-file-words-enable-fuzzy-match`: Search Words completion candidate fuzzy match, disable by default
- `acm-backend-search-file-words-enable-fuzzy-match-threshold`: Search Words completion candidate fuzzy match threshold, Filter out words with a ratio lower than the threshold, default is 50
- `acm-backend-codeium-candidate-min-length`: The minimum characters to trigger codeium completion, default is 0
- `acm-backend-lsp-enable-auto-import`: automatic insert import code, enable by default
- `acm-backend-lsp-enable-auto-import`: Automatic insert import code, enable by default
- `acm-backend-lsp-candidate-max-length`: Maximum length of LSP candidate, some language, such as Java, argument list is very long, you can increase the value of this option to see clear argument list
- `acm-backend-yas-candidates-number`: yasnippet display number, 2 by default
- `acm-backend-citre-keyword-complete`: Completion is performed according to the keywords of each mode defined by `acm-backend-citre-keywords-alist`, which takes effect only after citre is enabled.
- `acm-backend-search-sdcv-words-dictionary`: StarDict dictionary for word completion, default is `kdic-ec-11w`, you can replace it with StarDict dictionary path, example, if you have dictionary `/usr/share/stardict/dic/stardict-oxford-gb-formated-2.4.2/oxford-gb-formated.ifo`, you need set this value to `/usr/share/stardict/dic/stardict-oxford-gb-formated-2.4.2/oxford-gb-formated`, not include `.ifo` extension.
- `acm-backend-lsp-match-mode`: The filtering mode for candidates in LSP backend, there are three options: "prefix", "prefixCaseSensitive", and "fuzzy". By default it is "fuzzy"
- `acm-backend-lsp-frontend-filter-p`: Since LSP candidates have been filtered in the Python backend, it's not necessary to perform an additional filter on the frontend (refer to option `acm-candidate-match-function`), disable by default, when set to `t`, this option will call the `acm-candidate-match-function` function on the frontend to filter LSP candidates again
- `acm-backend-lsp-show-progress`: show working progress, disable by default
- `acm-enable-preview`: enable Tab-and-Go completion, commands like acm-select-* will select and preview other candidate and further input will then commit this candidate, disable by default

Expand Down
3 changes: 2 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ lsp-bridge 针对许多语言都提供 2 个以上的语言服务器支持,
- `acm-enable-yas`: yasnippet 补全, 默认打开
- `acm-enable-citre`: [citre(ctags)](https://github.com/universal-ctags/citre) 补全, 默认关闭
- `acm-doc-frame-max-lines`: 帮助窗口的最大行数, 默认是 20
- `acm-candidate-match-function`: lsp-bridge 前端对补全候选词的过滤算法, 选项有 `'regexp-quote`, `'orderless-flex`, `'orderless-literal`, `'orderless-prefixes`, `'orderless-regexp`, `'orderless-initialism`, 默认为 `nil`, 意味着默认只进行后端过滤(参考 `acm-backend-lsp-match-mode`), 不进行前端过滤, orderless-\* 开头的算法需要额外安装 [orderless](https://github.com/oantolin/orderless)
- `acm-candidate-match-function`: lsp-bridge 前端对补全候选词的过滤算法, 选项有 `'regexp-quote`, `'orderless-flex`, `'orderless-literal`, `'orderless-prefixes`, `'orderless-regexp`, `'orderless-initialism`, 默认为 `regexp-quote`, orderless-\* 开头的算法需要额外安装 [orderless](https://github.com/oantolin/orderless)
- `acm-completion-backend-merge-order`: 补全后端的显示顺序, 默认是按照模式补全前半部分、 模板补全前半部分、 TabNine/Copilot/Codeium、 模板补全后半部分、 模式补全后半部分的顺序显示, 你可以根据你的需求调整补全后端的显示顺序, 如果要自定义模式补全的顺序, 请自定义 `acm-completion-mode-candidates-merge-order`
- `acm-completion-mode-candidates-merge-order`: 模式补全的显示顺序, 默认是按照 Elisp、 LSP、 Jupyter、 Ctags、 Citre、 ROAM、 单词、 Telegra 的顺序显示, 你可以根据你的需求调整模式补全的显示顺序
- `acm-backend-lsp-candidate-min-length`: LSP 补全最小的触发字符数, 默认是 0
Expand All @@ -337,6 +337,7 @@ lsp-bridge 针对许多语言都提供 2 个以上的语言服务器支持,
- `acm-backend-citre-keyword-complete`: 根据`acm-backend-citre-keywords-alist`定义的各个模式的关键字进行补全, 需要使能 citre 后才生效
- `acm-backend-search-sdcv-words-dictionary`: 用于单词补全的 StarDict 词典, 默认是 `kdic-ec-11w`, 可以自定义为其他 StarDict 词典, 如果你的系统存在词典 `/usr/share/stardict/dic/stardict-oxford-gb-formated-2.4.2/oxford-gb-formated.ifo`, 你需要设置这个选项为 `/usr/share/stardict/dic/stardict-oxford-gb-formated-2.4.2/oxford-gb-formated`, 不需要包括 `.ifo` 扩展
- `acm-backend-lsp-match-mode`: lsp-bridge 后端对补全候选词的过滤算法, 选项有 "prefix", "prefixCaseSensitive", "fuzzy", 默认是 "fuzzy"
- `acm-backend-lsp-frontend-filter-p`: 因为 LSP 候选词已经在 Python 后端进行了过滤, 所以没有必要在前端再进行一次过滤(参考选项 acm-candidate-match-function), 默认为 nil, 该选项设置为 t 的时候会调用 `acm-candidate-match-function` 函数在前端对 LSP 候选词进行二次过滤
- `acm-backend-lsp-show-progress`: 是否显示 LSP Server 工作进度, 默认关闭
- `acm-enable-preview`: 开启 Tab-and-Go completion, 当改变当前候选时, 可以预览候选, 并且后续输入会选择预览候选, 默认关闭

Expand Down
28 changes: 21 additions & 7 deletions acm/acm-backend-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,23 @@ it will cause the lsp-bridge to always send the previous batch of candidates whi
:type 'string
:group 'acm-backend-lsp)

(defcustom acm-backend-lsp-frontend-filter-p nil
"Because LSP candidates has filtered at Python backend.
So don't need filter candidates again when show candidates in acm menu.
Anyway, if want use `acm-candidate-fuzzy-search' filter again in acm menu, turn on this option."
:type 'string
:group 'acm-backend-lsp)

(defcustom acm-backend-lsp-show-progress nil
"Show message from 'Work Done Progress' message.
Default is nil."
:type 'boolean
:group 'acm-backend-lsp)


(defvar acm-backend-lsp-fetch-completion-item-func nil)
(defvar-local acm-backend-lsp-fetch-completion-item-ticker nil)

Expand Down Expand Up @@ -170,13 +180,17 @@ Below is available types:
;; please do not do secondary sorting here, elisp is very slow.
candidates))))

;; When some LSP server very slow and other completion backend is fast,
;; acm menu will render all backend candidates.
;; Then old LSP candidates won't match `prefix' if new candidates haven't return.
;; So we need filter old LSP candidates with `prefix' if `prefix' is not empty.
(if (string-equal keyword "")
match-candidates
(seq-filter (lambda (c) (acm-candidate-fuzzy-search keyword (plist-get c :label))) match-candidates))))
;; Show candidates
(cond
;; Don't filter candidates is prefix is empty.
((string-equal keyword "")
match-candidates)
;; Fitler candidates when `acm-backend-lsp-frontend-filter-p' is non-nil.
(acm-backend-lsp-frontend-filter-p
(seq-filter (lambda (c) (acm-candidate-fuzzy-search keyword (plist-get c :label))) match-candidates))
;; Don't filter candidates default, because LSP candidates has filtered at Python backend.
(t
match-candidates))))

(defun acm-backend-lsp-candidate-expand (candidate-info bound-start &optional preview)
(let* ((label (plist-get candidate-info :label))
Expand Down
2 changes: 1 addition & 1 deletion acm/acm.el
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
:type 'boolean
:group 'acm)

(defcustom acm-candidate-match-function nil
(defcustom acm-candidate-match-function 'regexp-quote
"acm candidate match function."
:type '(choice
(const nil)
Expand Down

0 comments on commit 6802f79

Please sign in to comment.