Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with completing idents in the language server #2917

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/build_langserver/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (h *Handler) completeIdent(doc *doc, s string, line, col int) (*lsp.Complet
list := &lsp.CompletionList{}
for name, f := range h.builtins {
if strings.HasPrefix(name, s) {
item := completionItem(name, s, line, col)
item := completionItem(name, "", line, col)
Copy link
Member Author

@Tatskaari Tatskaari Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're completing "check_" to "check_config", name would be "check_config", and s would have been "check_". We would then produce a replacement from "check_" to "config", rather than to the full "check_config" because we strip this prefix. I think this prefix is for when we complete labels within a package. We would have a list of completions with just the target name, and the prefix would be the //foo: bit.

The prefix would be //foo: but the completion list would contain just the label name, i.e. "bar" (as opposed to "//foo:bar". We then produce an edit for the column after the : to insert just the name rather than replacing the full label. This is not the case for idents though. I have tested completing member functions too, and they work just fine.

item.Documentation = f.Stmt.FuncDef.Docstring
item.Kind = lsp.CIKFunction
list.Items = append(list.Items, item)
Expand Down
4 changes: 2 additions & 2 deletions tools/build_langserver/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func TestCompletionFunction(t *testing.T) {
Label: "plugin_repo",
Kind: lsp.CIKFunction,
InsertTextFormat: lsp.ITFPlainText,
TextEdit: textEdit("in_repo", 0, 4),
TextEdit: textEdit("plugin_repo", 0, 4),
Documentation: h.builtins["plugin_repo"].Stmt.FuncDef.Docstring,
}},
}, completions)
Expand Down Expand Up @@ -491,7 +491,7 @@ func TestCompletionPartialFunction(t *testing.T) {
Label: "plugin_repo",
Kind: lsp.CIKFunction,
InsertTextFormat: lsp.ITFPlainText,
TextEdit: textEdit("po", 0, 9),
TextEdit: textEdit("plugin_repo", 0, 9),
Documentation: h.builtins["plugin_repo"].Stmt.FuncDef.Docstring,
}},
}, completions)
Expand Down
Loading