Skip to content

Commit

Permalink
Fix issue with complleting idents in the language server
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatskaari committed Oct 9, 2023
1 parent 86d4324 commit 7565012
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tools/build_langserver/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (h *Handler) completeLabel(doc *doc, partial string, line, col int) (*lsp.C
if !strings.HasPrefix(s, partial) {
s = t.Label.String() // Don't abbreviate it if we end up losing part of what's there
}
list.Items = append(list.Items, completionItem(s, partial, line, col))
list.Items = append(list.Items, completionItem(s, line, col))
m[s] = true
}
}
Expand All @@ -51,7 +51,7 @@ func (h *Handler) completeLabel(doc *doc, partial string, line, col int) (*lsp.C
for _, target := range h.allTargets(doc) {
if (label.Name == "all" && !strings.HasPrefix(label.Name, "_")) || strings.HasPrefix(target, label.Name) {
if s := ":" + target; !m[s] {
list.Items = append(list.Items, completionItem(s, partial, line, col))
list.Items = append(list.Items, completionItem(s, line, col))
}
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *Handler) completeString(doc *doc, s string, line, col int) (*lsp.Comple
Items: make([]lsp.CompletionItem, len(matches)),
}
for i, match := range matches {
list.Items[i] = completionItem(match, s, line, col)
list.Items[i] = completionItem(match, line, col)
}
return list, nil
}
Expand All @@ -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)
item.Documentation = f.Stmt.FuncDef.Docstring
item.Kind = lsp.CIKFunction
list.Items = append(list.Items, item)
Expand Down Expand Up @@ -141,13 +141,13 @@ func stringLiteral(s string) string {
return s[1 : len(s)-1]
}

func completionItem(label, prefix string, line, col int) lsp.CompletionItem {
func completionItem(label string, line, col int) lsp.CompletionItem {
return lsp.CompletionItem{
Label: label,
Kind: lsp.CIKValue,
InsertTextFormat: lsp.ITFPlainText,
TextEdit: &lsp.TextEdit{
NewText: strings.TrimPrefix(label, prefix),
NewText: label,
Range: lsp.Range{
Start: lsp.Position{Line: line, Character: col},
End: lsp.Position{Line: line, Character: col},
Expand Down Expand Up @@ -204,7 +204,7 @@ func (h *Handler) completePackages(pkg *pkg, allParts, parts []string, line, col
// Last part, take anything in here with the relevant prefix
for name := range pkg.Subpackages {
if strings.HasPrefix(name, part) {
items = append(items, completionItem(prefix+name, prefix+part, line, col))
items = append(items, completionItem(prefix+name, line, col))
}
}
} else if pkg.Subpackages != nil {
Expand Down

0 comments on commit 7565012

Please sign in to comment.