Skip to content

Commit

Permalink
Add acm-backend-lsp-match-mode option.
Browse files Browse the repository at this point in the history
  • Loading branch information
manateelazycat committed Nov 30, 2023
1 parent 4752531 commit c6761b1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,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, and fuzzy. By default it is normal. It does not filter the candidate words returned by LSP Server
- `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

## Customize language server configuration
Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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", "fuzzy" 三个选项, 默认是 "normal", 不对 LSP Server 返回候选词进行过滤
- `acm-enable-preview`: 开启 Tab-and-Go completion, 当改变当前候选时, 可以预览候选, 并且后续输入会选择预览候选, 默认关闭

## 自定义语言服务器配置
Expand Down
11 changes: 11 additions & 0 deletions acm/acm-backend-lsp.el
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@
:type 'boolean
:group 'acm-backend-lsp)

(defcustom acm-backend-lsp-match-mode "normal"
"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 `::'
fuzzy: fitler candidates with fuzzy algorithm
Recommand use `normal' that follow LSP server response, emacser's behavior typically does not adapt to LSP protocol."
:type 'string
: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
2 changes: 2 additions & 0 deletions core/fileaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ def __init__(self, filepath, single_server_info, single_server, multi_servers_in

(self.enable_auto_import,
self.completion_items_limit,
self.completion_match_mode,
self.insert_spaces,
self.enable_push_diagnostics,
self.push_diagnostic_idle,
self.display_label_max_length,
self.diagnostics_max_number) = get_emacs_vars([
"acm-backend-lsp-enable-auto-import",
"acm-backend-lsp-candidates-max-number",
"acm-backend-lsp-match-mode",
"indent-tabs-mode",
"lsp-bridge-enable-diagnostics",
"lsp-bridge-diagnostic-fetch-idle",
Expand Down
23 changes: 9 additions & 14 deletions core/handler/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ def compare_candidates(self, x, y):
# Sort by length.
return -1 if len(x_label) < len(y_label) else (1 if len(x_label) > len(y_label) else 0)

def get_fuzzy_option(self):
for server in self.file_action.get_match_lsp_servers("completion"):
if server.server_name.endswith("#" + self.method_server_name):
return server.server_info.get("incomplete-fuzzy-match")

return False

def get_display_new_text(self):
for server in self.file_action.get_match_lsp_servers("completion"):
if server.server_info.get("displayNewText", False):
Expand Down Expand Up @@ -114,8 +107,8 @@ def process_response(self, response: dict) -> None:
items = {}

if response is not None:
# Get value of 'incomplete-fuzzy-match' from lsp server config file.
fuzzy = self.get_fuzzy_option()
# Get match mode to filter candidates.
match_mode = self.file_action.completion_match_mode

# Some LSP server, such as Wen, need assign textEdit/newText to displayLabel.
display_new_text = self.get_display_new_text()
Expand All @@ -125,11 +118,13 @@ def process_response(self, response: dict) -> None:
label = item["label"]
detail = item.get("detail", "")

# NOTE:
# If lsp server contain 'incomplete-fuzzy-match' option and it's True, we filter 'label' with fuzzy algorithm.
# Otherwise, don't filter 'label' with 'prefix', such as we input "std::" in c++, all candidate's prefix is not "::"
if fuzzy and not string_match(label.lower(), self.prefix.lower(), fuzzy=fuzzy):
continue
# 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):
continue
elif match_mode == "fuzzy":
if not string_match(label.lower(), self.prefix.lower(), fuzzy=True):
continue

annotation = kind if kind != "" else detail

Expand Down
1 change: 0 additions & 1 deletion langserver/jedi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"name": "jedi",
"languageId": "python",
"command": ["jedi-language-server"],
"incomplete-fuzzy-match": true,
"settings": {}
}
1 change: 0 additions & 1 deletion langserver/pylsp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"name": "pylsp",
"languageId": "python",
"command": ["pylsp"],
"incomplete-fuzzy-match": true,
"settings": {}
}
8 changes: 4 additions & 4 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -2534,18 +2534,18 @@ We need exclude `markdown-code-fontification:*' buffer in `lsp-bridge-monitor-be

(defcustom lsp-bridge-remote-python-command
"python3"
"python command on remote host")
"Python command on remote host.")

(defcustom lsp-bridge-remote-python-file
"~/lsp-bridge/lsp_bridge.py"
"full path of lsp_bridge.py file on remote host")
"Full path of lsp_bridge.py file on remote host.")

(defcustom lsp-bridge-remote-log
"~/lsp-bridge/lbr_log.txt"
"full path of log file on remote host")
"Full path of log file on remote host.")

(defcustom lsp-bridge-remote-start-automatically nil
"whether start remote lsp-bridge.py automatically")
"Whether start remote lsp-bridge.py automatically.")

(defun lsp-bridge-sync-tramp-remote ()
(interactive)
Expand Down

0 comments on commit c6761b1

Please sign in to comment.