diff --git a/handlers/wireguard/text-document-completion.go b/handlers/wireguard/text-document-completion.go index ffb8102..a8c39c8 100644 --- a/handlers/wireguard/text-document-completion.go +++ b/handlers/wireguard/text-document-completion.go @@ -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 } diff --git a/handlers/wireguard/wg-section.go b/handlers/wireguard/wg-section.go index 4eb8c68..0670127 100644 --- a/handlers/wireguard/wg-section.go +++ b/handlers/wireguard/wg-section.go @@ -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
.+?)\]\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