Skip to content

Commit a9a5b73

Browse files
committed
fix(cache): handle edge cases and array index overflows
1 parent a5180a7 commit a9a5b73

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cache/cache.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func Get(prompt string, suffix string) ([]lsp.CompletionItem, bool) {
4949
clonedData := make([]lsp.CompletionItem, len(value.Data))
5050
for i, item := range value.Data {
5151
clonedItem := item
52-
clonedItem.InsertText = item.InsertText[len(prompt)-len(value.Prompt):]
52+
start := max(len(prompt)-len(value.Prompt), 0)
53+
end := min(len(item.InsertText)-(len(suffix)-len(value.Suffix)), len(item.InsertText))
54+
clonedItem.InsertText = item.InsertText[start:end]
5355
clonedData[i] = clonedItem
5456
}
5557
return clonedData, true

0 commit comments

Comments
 (0)