fix(wireguard): Improvements

This commit is contained in:
Myzel394 2024-08-16 11:50:03 +02:00
parent 0d2c986ddd
commit 431d63d440
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 25 additions and 4 deletions

View File

@ -31,11 +31,11 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
completions, err := section.getCompletionsForPropertyLine(lineNumber, params.Position.Character)
if err != nil {
if completions == nil && err != nil {
switch err.(type) {
// Ignore
case propertyNotFullyTypedError:
break
return section.getCompletionsForEmptyLine()
default:
return nil, err
}

View File

@ -132,7 +132,23 @@ func (p wireguardSection) getCompletionsForPropertyLine(
}
if property.Separator == nil {
return getSeparatorCompletion(*property, character)
if p.Name != nil {
switch *p.Name {
case "Interface":
if _, found := interfaceOptions[property.Key.Name]; found {
return getSeparatorCompletion(*property, character)
}
case "Peer":
if _, found := peerOptions[property.Key.Name]; found {
return getSeparatorCompletion(*property, character)
}
}
// Get empty line completions
return nil, propertyNotFullyTypedError{}
}
return nil, propertyNotFoundError{}
}
var option docvalues.Value
@ -161,7 +177,12 @@ func (p wireguardSection) getCompletionsForPropertyLine(
var validHeaderPattern = regexp.MustCompile(`^\s*\[(?P<header>.+?)\]\s*$`)
func createWireguardSection(startLine uint32, endLine uint32, headerLine string, props wireguardProperties) wireguardSection {
func createWireguardSection(
startLine uint32,
endLine uint32,
headerLine string,
props wireguardProperties,
) wireguardSection {
match := validHeaderPattern.FindStringSubmatch(headerLine)
var header string