Skip to content

Commit

Permalink
Add new option acm-backend-lsp-block-kind-list
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Apr 19, 2024
1 parent c59aaf6 commit ac40260
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions acm/acm-backend-lsp.el
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions core/fileaction.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions core/handler/completion.py
Expand Up @@ -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):
Expand Down

0 comments on commit ac40260

Please sign in to comment.