Skip to content

Commit

Permalink
feat(doc-values): Check if value starts with a prefix before suggesti…
Browse files Browse the repository at this point in the history
…ng prefix completions
  • Loading branch information
Myzel394 committed Sep 17, 2024
1 parent 06182dd commit 590786e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions doc-values/value-prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ func (v PrefixWithMeaningValue) FetchCompletions(line string, cursor uint32) []p
textFormat := protocol.InsertTextFormatPlainText
kind := protocol.CompletionItemKindText

prefixCompletions := utils.Map(v.Prefixes, func(prefix Prefix) protocol.CompletionItem {
return protocol.CompletionItem{
Label: prefix.Prefix,
Detail: &prefix.Meaning,
InsertTextFormat: &textFormat,
Kind: &kind,
// Check if the line starts with a prefix
startsWithPrefix := false
for _, prefix := range v.Prefixes {
if strings.HasPrefix(line, prefix.Prefix) {
startsWithPrefix = true
break
}
})
}

var prefixCompletions []protocol.CompletionItem
if !startsWithPrefix {
prefixCompletions = utils.Map(v.Prefixes, func(prefix Prefix) protocol.CompletionItem {
return protocol.CompletionItem{
Label: prefix.Prefix,
Detail: &prefix.Meaning,
InsertTextFormat: &textFormat,
Kind: &kind,
}
})
}

return append(prefixCompletions, v.SubValue.FetchCompletions(line, cursor)...)
}
Expand Down

0 comments on commit 590786e

Please sign in to comment.