From de380fd6c3cc1c0df5b2c07c15e81f820f34ab1e Mon Sep 17 00:00:00 2001 From: Heng Lu Date: Thu, 1 Aug 2024 15:15:23 +0800 Subject: [PATCH] cache results --- internal/langserver/handlers/snippets/templates.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/langserver/handlers/snippets/templates.go b/internal/langserver/handlers/snippets/templates.go index 08b99b03..eba20d07 100644 --- a/internal/langserver/handlers/snippets/templates.go +++ b/internal/langserver/handlers/snippets/templates.go @@ -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 { @@ -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", @@ -56,5 +60,5 @@ func TemplateCandidates(editRange lsp.Range) []lsp.CompletionItem { }, }) } - return candidates + return templateCandidates }