Skip to content

Commit

Permalink
cache results
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Aug 1, 2024
1 parent 5b063f5 commit de380fd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/langserver/handlers/snippets/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ type DocumentationModel struct {
Value string `json:"value"`
}

var templateCandidates []lsp.CompletionItem

func TemplateCandidates(editRange lsp.Range) []lsp.CompletionItem {
if len(templateCandidates) != 0 {
return templateCandidates
}
templates := make([]CompletionModel, 0)
data, err := templateJSON.ReadFile("templates.json")
if err != nil {
Expand All @@ -37,9 +42,8 @@ func TemplateCandidates(editRange lsp.Range) []lsp.CompletionItem {
return nil
}

candidates := make([]lsp.CompletionItem, 0)
for _, template := range templates {
candidates = append(candidates, lsp.CompletionItem{
templateCandidates = append(templateCandidates, lsp.CompletionItem{
Label: template.Label,
Kind: lsp.SnippetCompletion,
Detail: "Code Sample",
Expand All @@ -56,5 +60,5 @@ func TemplateCandidates(editRange lsp.Range) []lsp.CompletionItem {
},
})
}
return candidates
return templateCandidates
}

0 comments on commit de380fd

Please sign in to comment.