Skip to content

Commit

Permalink
Fix issue #907 and #888, always filter candidates at Python side, avo…
Browse files Browse the repository at this point in the history
…id acm menu not show completion candidates when candidates return by LSP server much bigger than the limit of acm-backend-lsp-candidates-max-number
  • Loading branch information
manateelazycat committed Apr 21, 2024
1 parent b485bcb commit bc10c15
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ lsp-bridge provides support for more than two language servers for many language
- `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 candidate words in LSP backend, there are three options: "normal", "prefix", "prefixCaseSensitive", and "fuzzy". By default it is normal. It does not filter the candidate words returned by LSP Server
- `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-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

## Add support for new language?
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ lsp-bridge 针对许多语言都提供 2 个以上的语言服务器支持,
- `acm-backend-yas-candidates-number`: yasnippet 显示个数, 默认 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 后端候选词过滤模式, 有 "normal", "prefix", "prefixCaseSensitive", "fuzzy" 三个选项, 默认是 "normal", 不对 LSP Server 返回候选词进行过滤
- `acm-backend-lsp-match-mode`: LSP 后端候选词过滤模式, 有 "prefix", "prefixCaseSensitive", "fuzzy" 三个选项, 默认是 "fuzzy"
- `acm-enable-preview`: 开启 Tab-and-Go completion, 当改变当前候选时, 可以预览候选, 并且后续输入会选择预览候选, 默认关闭

## 添加新的编程语言支持?
Expand Down
15 changes: 9 additions & 6 deletions acm/acm-backend-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@
:type 'boolean
:group 'acm-backend-lsp)

(defcustom acm-backend-lsp-match-mode "normal"
(defcustom acm-backend-lsp-match-mode "fuzzy"
"The match mode to filter completion candidates.
normal: don't filter candidates.
prefix: filter candidates with input prefix, note such as C++, after `std::', candidate's prefix is not `::'
prefixCaseSensitive: filter candidates with input prefix, and case sensitive
fuzzy: fitler candidates with fuzzy algorithm
`prefix': filter candidates with input prefix, note such as C++, after `std::', candidate's prefix is not `::'
`prefixCaseSensitive': filter candidates with input prefix, and case sensitive
`fuzzy': fitler candidates with fuzzy algorithm
Recommand use `normal' that follow LSP server response, emacser's behavior typically does not adapt to LSP protocol."
lsp-bridge still will use `fuzzy' algorithm filter candidates if value is not `prefix' `prefixCaseSensitive' or `fuzzy'.
The lsp-bridge will continuously filter candidates on the Python side.
If not filter and the value of `acm-backend-lsp-candidates-max-number' is far smaller than the number of candidates returned by the LSP server,
it will cause the lsp-bridge to always send the previous batch of candidates which do not match the users input."
:type 'string
:group 'acm-backend-lsp)

Expand Down
9 changes: 6 additions & 3 deletions core/handler/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,23 @@ def process_response(self, response: dict) -> None:
except:
pass

# Try to drop current candidate if it match user rule.
# The lsp-bridge will continuously filter candidates on the Python side.
# If not filter and the value of `acm-backend-lsp-candidates-max-number' is far smaller
# than the number of candidates returned by the LSP server,
# it will cause the lsp-bridge to always send the previous batch of candidates
# which do not match the users input.
if match_mode == "prefix":
if not string_match(label.lower(), self.prefix.lower(), fuzzy=False):
continue
elif match_mode == "prefixCaseSensitive":
if not string_match(label, self.prefix, fuzzy=False):
continue
elif match_mode == "fuzzy":
else:
if not string_match(label.lower(), self.prefix.lower(), fuzzy=True):
continue

annotation = kind if kind != "" else detail


# The key keyword combines the values ​​of 'label' and 'detail'
# to handle different libraries provide the same function.
key = f"{label}_{detail}"
Expand Down

0 comments on commit bc10c15

Please sign in to comment.