From 431d63d440c6f6c38a0d01387ca98f904a7e5fe9 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:50:03 +0200 Subject: [PATCH] fix(wireguard): Improvements --- .../wireguard/text-document-completion.go | 4 +-- handlers/wireguard/wg-section.go | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) 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