feat(wireguard): Add smart completion: Provide completions for new peer section

This commit is contained in:
Myzel394 2024-08-21 22:57:42 +02:00
parent abb5572897
commit b7501df447
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185

View File

@ -26,7 +26,20 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
return handlers.GetRootCompletionsForEmptyLine(*p)
}
return handlers.GetCompletionsForSectionEmptyLine(*section)
completions, err := handlers.GetCompletionsForSectionEmptyLine(*section)
// === Smart rules ===
// If previous line is empty too, maybe new section?
if lineNumber >= 1 && p.GetTypeByLine(lineNumber-1) == parser.LineTypeEmpty && len(p.GetBelongingSectionByLine(lineNumber).Properties) > 0 {
rootCompletions, err := handlers.GetRootCompletionsForEmptyLine(*p)
if err == nil {
completions = append(completions, rootCompletions...)
}
}
return completions, err
case parser.LineTypeProperty:
completions, err := handlers.GetCompletionsForSectionPropertyLine(*section, lineNumber, params.Position.Character)