Completions bug fixes and switch to a better html lsp

This commit is contained in:
2026-01-10 19:24:38 +00:00
parent b20702928a
commit 78bf2d666d
3 changed files with 12 additions and 8 deletions

View File

@@ -72,7 +72,7 @@ The following lsp's are supported and can be installed anywhere in your `$PATH`<
* [fish-lsp](https://github.com/ndonfris/fish-lsp)
* [gopls](https://pkg.go.dev/golang.org/x/tools/gopls)
* [haskell-language-server](https://github.com/haskell/haskell-language-server)
* [emmet-ls](https://github.com/aca/emmet-ls) *Autocompletion for emmet works but doesn't show popup correctly for now, use ctrl+\\ to run after writing emmet code*
* [emmet-language-server](https://github.com/olrtg/emmet-language-server)
* [typescript-language-server](https://github.com/typescript-language-server/typescript-language-server)
* [lua-language-server](https://github.com/LuaLS/lua-language-server)
* [pyright-langserver](https://github.com/microsoft/pyright)

View File

@@ -75,9 +75,9 @@ static const std::unordered_map<uint8_t, LSP> kLsps = {
nullptr,
}}},
{10,
{"emmet-ls",
{"emmet-language-server",
{
"emmet-ls",
"emmet-language-server",
"--stdio",
nullptr,
}}},

View File

@@ -52,11 +52,11 @@ void completion_filter(Editor *editor) {
void completion_request(Editor *editor) {
Coord hook = editor->cursor;
word_boundaries(editor, editor->cursor, &hook.col, nullptr, nullptr, nullptr);
editor->completion.hook = hook;
editor->completion.active = true;
editor->completion.items.clear();
editor->completion.visible.clear();
editor->completion.select = 0;
editor->completion.hook = hook;
LSPPending *pending = new LSPPending();
pending->editor = editor;
pending->method = "textDocument/completion";
@@ -94,6 +94,7 @@ void completion_request(Editor *editor) {
}
}
session.items.reserve(items_json.size() + 1);
session.visible.reserve(items_json.size() + 1);
for (auto &item_json : items_json) {
CompletionItem item;
item.original = item_json;
@@ -190,8 +191,8 @@ void completion_request(Editor *editor) {
if (c.is_string() && c.get<std::string>().size() == 1)
item.end_chars.push_back(c.get<std::string>()[0]);
session.items.push_back(std::move(item));
session.visible.push_back(session.items.size() - 1);
}
completion_filter(editor);
session.box.hidden = false;
session.box.render_update();
};
@@ -268,7 +269,7 @@ void handle_completion(Editor *editor, KeyEvent event) {
completion_request(editor);
}
} else if (ch == CTRL('\\')) {
if (editor->completion.active) {
if (editor->completion.active && editor->completion.visible.size()) {
complete_accept(editor);
} else {
editor->completion.trigger = 1;
@@ -280,7 +281,7 @@ void handle_completion(Editor *editor, KeyEvent event) {
} else if (ch == CTRL('o')) {
if (editor->completion.active)
complete_prev(editor);
} else if (ch == 0x7F || ch == 0x08) {
} else if (ch == 0x7F || ch == 0x08 || ch == CTRL('W')) {
if (editor->completion.active) {
if (editor->completion.complete) {
if (editor->cursor <= editor->completion.hook)
@@ -288,7 +289,10 @@ void handle_completion(Editor *editor, KeyEvent event) {
else
completion_filter(editor);
} else {
completion_request(editor);
if (editor->cursor <= editor->completion.hook)
editor->completion.active = false;
else
completion_request(editor);
}
}
} else {