in internal/langserver/handlers/snippets/templates.go [31:82]
func TemplateCandidates(editRange lsp.Range) []lsp.CompletionItem {
if len(templateCandidates) != 0 {
for i := range templateCandidates {
templateCandidates[i].TextEdit.Range = editRange
}
return templateCandidates
}
templates := make([]CompletionModel, 0)
data, err := templateJSON.ReadFile("templates.json")
if err != nil {
return nil
}
err = json.Unmarshal(data, &templates)
if err != nil {
return nil
}
for _, template := range templates {
event := lsp.TelemetryEvent{
Version: lsp.TelemetryFormatVersion,
Name: "textDocument/completion",
Properties: map[string]interface{}{
"kind": "template",
"label": template.Label,
},
}
data, _ := json.Marshal(event)
templateCandidates = append(templateCandidates, lsp.CompletionItem{
Label: template.Label,
Kind: lsp.SnippetCompletion,
Detail: "Code Sample",
Documentation: lsp.MarkupContent{
Kind: "markdown",
Value: template.Documentation.Value,
},
SortText: template.SortText,
InsertTextFormat: lsp.SnippetTextFormat,
InsertTextMode: lsp.AdjustIndentation,
TextEdit: &lsp.TextEdit{
Range: editRange,
NewText: template.TextEdit.NewText,
},
Command: &lsp.Command{
Title: "",
Command: "azapi.telemetry",
Arguments: []json.RawMessage{data},
},
})
}
return templateCandidates
}