diff --git a/README.md b/README.md index 6412c1505d..46d710f990 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ lsp-bridge provides support for more than two language servers for many language - `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 +- `acm-backend-lsp-block-kind-list`: Filters certain types of LSP completion candidates. By default, it's a empty list. When the value is set to `'(Snippet Enum)`, this means that Snippet and Enum completions will not be shown. - `acm-backend-elisp-candidate-min-length`: The minimum characters to trigger elisp completion, default is 0 - `acm-backend-yas-candidate-min-length`: The minimum characters to trigger yasnippet completion, default is 0 - `acm-backend-search-file-words-candidate-min-length`: The minimum characters to trigger search file words completion, default is 0 diff --git a/README.zh-CN.md b/README.zh-CN.md index c08ebbc802..04925055c1 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -323,6 +323,7 @@ lsp-bridge 针对许多语言都提供 2 个以上的语言服务器支持, - `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 +- `acm-backend-lsp-block-kind-list`: 过滤某些类型的 LSP 候选词, 默认是列表, 当值为 `'("Snippet" "Enum")` 的时候, 意味着 Snippet Enum 这两种类型的补全不会显示 - `acm-backend-elisp-candidate-min-length`: Elisp 补全最小的触发字符数, 默认是 0 - `acm-backend-yas-candidate-min-length`: YaSnippet 补全最小的触发字符数, 默认是 0 - `acm-backend-search-file-words-candidate-min-length`: Search Words 补全最小的触发字符数, 默认是 0 diff --git a/acm/acm-backend-lsp.el b/acm/acm-backend-lsp.el index 4d8d5dc6bf..09195d3787 100644 --- a/acm/acm-backend-lsp.el +++ b/acm/acm-backend-lsp.el @@ -123,6 +123,20 @@ Recommand use `normal' that follow LSP server response, emacser's behavior typic (defvar acm-backend-lsp-fetch-completion-item-func nil) (defvar-local acm-backend-lsp-fetch-completion-item-ticker nil) +(defvar-local acm-backend-lsp-block-kind-list nil + "You can customize this option to filter certain types of completion candidates. + +This variable is a list type. + +Below is available types: + +`Text' `Method' `Function' `Constructor' `Field' +`Variable' `Class' `Interface' `Module' `Property' +`Unit' `Value' `Enum' `Keyword' `Snippet' `Color' +`File' `Reference' `Folder' `EnumMember' `Constant' +`Struct' `Event' `Operator' `TypeParameter' +") + (defun acm-backend-lsp-candidates (keyword) (let ((match-candidates (acm-with-cache-candidates diff --git a/core/fileaction.py b/core/fileaction.py index 1847c334b0..381635b8c7 100755 --- a/core/fileaction.py +++ b/core/fileaction.py @@ -108,6 +108,7 @@ def __init__(self, filepath, single_server_info, single_server, multi_servers_in "acm-backend-lsp-candidate-max-length", "lsp-bridge-diagnostic-max-number" ]) + self.completion_block_kind_list = None self.insert_spaces = not self.insert_spaces self.set_lsp_server() @@ -202,6 +203,11 @@ def change_file(self, start, end, range_length, change_text, position, before_ch self.last_change_file_time = time.time() # Send textDocument/completion 100ms later. + if self.completion_block_kind_list is None: + (self.completion_block_kind_list, ) = get_emacs_vars(["acm-backend-lsp-block-kind-list"]) + if isinstance(self.completion_block_kind_list, list): + self.completion_block_kind_list = list(map(lambda x: x.lower(), self.completion_block_kind_list)) + delay = 0 if is_running_in_server() else 0.1 self.try_completion_timer = threading.Timer(delay, lambda : self.try_completion(position, before_char, prefix, self.version)) self.try_completion_timer.start() diff --git a/core/handler/completion.py b/core/handler/completion.py index b1785df2ea..5ae571febd 100644 --- a/core/handler/completion.py +++ b/core/handler/completion.py @@ -119,6 +119,13 @@ def process_response(self, response: dict) -> None: label = item["label"] detail = item.get("detail", "") + # Filter candidate that kind match acm-backend-lsp-block-kind-list. + try: + if self.file_action.completion_block_kind_list is not False and kind in self.file_action.completion_block_kind_list: + continue + except: + pass + # Try to drop current candidate if it match user rule. if match_mode == "prefix": if not string_match(label.lower(), self.prefix.lower(), fuzzy=False):