From 7feb034a8494abbea198fb1071e5b469548d58b5 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 15 Mar 2025 23:04:40 +0100 Subject: [PATCH] fix(server): Overall improvements Signed-off-by: Myzel394 --- server/handlers/ssh_config/analyzer/options.go | 2 +- server/handlers/sshd_config/analyzer/options.go | 2 +- server/handlers/wireguard/analyzer/property.go | 14 ++++++++++++-- server/handlers/wireguard/ast/parser.go | 2 +- .../wireguard/lsp/text-document-completion.go | 3 --- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/server/handlers/ssh_config/analyzer/options.go b/server/handlers/ssh_config/analyzer/options.go index 47d8dc9..802522d 100644 --- a/server/handlers/ssh_config/analyzer/options.go +++ b/server/handlers/ssh_config/analyzer/options.go @@ -49,7 +49,7 @@ func checkOption( if option.Separator == nil || option.Separator.Value.Value == "" { ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ Range: option.Key.LocationRange.ToLSPRange(), - Message: fmt.Sprintf("There should be a separator between an option and its value"), + Message: "There should be a separator between an option and its value", Severity: &common.SeverityError, }) } else { diff --git a/server/handlers/sshd_config/analyzer/options.go b/server/handlers/sshd_config/analyzer/options.go index c18ca4d..d8bd0aa 100644 --- a/server/handlers/sshd_config/analyzer/options.go +++ b/server/handlers/sshd_config/analyzer/options.go @@ -46,7 +46,7 @@ func checkOption( if option.Separator == nil || option.Separator.Value.Value == "" { ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ Range: option.Key.LocationRange.ToLSPRange(), - Message: fmt.Sprintf("There should be a separator between an option and its value"), + Message: "There should be a separator between an option and its value", Severity: &common.SeverityError, }) } else { diff --git a/server/handlers/wireguard/analyzer/property.go b/server/handlers/wireguard/analyzer/property.go index 2a80141..6fc8e48 100644 --- a/server/handlers/wireguard/analyzer/property.go +++ b/server/handlers/wireguard/analyzer/property.go @@ -94,6 +94,12 @@ func analyzeSymmetricPropertiesSet( } } +type key int + +const ( + lineKey key = iota +) + // Strategy // Simply compare the host bits of the IP addresses. // Use a binary tree to store the host bits. @@ -117,7 +123,7 @@ func analyzeDuplicateAllowedIPs( } if ipContext, _ := ipHostSet.ContainsIP(ipAddress); ipContext != nil { - definedLine := (*ipContext).Value("line").(uint32) + definedLine := (*ipContext).Value(lineKey).(uint32) ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ Message: fmt.Sprintf("This IP range is already covered on line %d", definedLine+1), @@ -125,7 +131,11 @@ func analyzeDuplicateAllowedIPs( Range: property.ToLSPRange(), }) } else { - ipContext := context.WithValue(context.Background(), "line", property.Start.Line) + ipContext := context.WithValue( + context.Background(), + lineKey, + property.Start.Line, + ) ipHostSet.AddIP( ipAddress, diff --git a/server/handlers/wireguard/ast/parser.go b/server/handlers/wireguard/ast/parser.go index ebed861..6065b24 100644 --- a/server/handlers/wireguard/ast/parser.go +++ b/server/handlers/wireguard/ast/parser.go @@ -144,7 +144,7 @@ func (c *WGConfig) Parse(input string) []common.LSPError { indexes := linePattern.FindStringSubmatchIndex(line) - if indexes == nil || len(indexes) == 0 { + if len(indexes) == 0 { // Error errors = append(errors, common.LSPError{ Range: common.LocationRange{ diff --git a/server/handlers/wireguard/lsp/text-document-completion.go b/server/handlers/wireguard/lsp/text-document-completion.go index 28fdbfb..37b3ad0 100644 --- a/server/handlers/wireguard/lsp/text-document-completion.go +++ b/server/handlers/wireguard/lsp/text-document-completion.go @@ -3,14 +3,11 @@ package lsp import ( "config-lsp/handlers/wireguard" "config-lsp/handlers/wireguard/handlers" - "regexp" "github.com/tliron/glsp" protocol "github.com/tliron/glsp/protocol_3_16" ) -var headerPattern = regexp.MustCompile(`^\s*\[(\w+)?]?`) - func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionParams) (any, error) { d := wireguard.DocumentParserMap[params.TextDocument.URI]