From 1c5de6c3e189f799b040ffa9ca4464cc5dc1d40c Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Thu, 3 Oct 2024 23:15:25 +0200 Subject: [PATCH] fix(ssh_config): Properly separate values and options analyzer --- .../ssh_config/analyzer/dependents_test.go | 45 +++++++++++++++++++ .../handlers/ssh_config/analyzer/options.go | 7 +-- .../ssh_config/analyzer/options_test.go | 10 ++--- server/handlers/ssh_config/analyzer/values.go | 19 +------- 4 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 server/handlers/ssh_config/analyzer/dependents_test.go diff --git a/server/handlers/ssh_config/analyzer/dependents_test.go b/server/handlers/ssh_config/analyzer/dependents_test.go new file mode 100644 index 0000000..d573d4f --- /dev/null +++ b/server/handlers/ssh_config/analyzer/dependents_test.go @@ -0,0 +1,45 @@ +package analyzer + +import ( + testutils_test "config-lsp/handlers/ssh_config/test_utils" + "testing" + + protocol "github.com/tliron/glsp/protocol_3_16" +) + +func TestSimpleDependentExample( + t *testing.T, +) { + d := testutils_test.DocumentFromInput(t, ` +CanonicalDomains test.com +`) + ctx := &analyzerContext{ + document: d, + diagnostics: make([]protocol.Diagnostic, 0), + } + + analyzeDependents(ctx) + + if !(len(ctx.diagnostics) == 1) { + t.Errorf("Expected 1 error, got %v", len(ctx.diagnostics)) + } +} + +func TestSimpleDependentExistsExample( + t *testing.T, +) { + d := testutils_test.DocumentFromInput(t, ` +CanonicalizeHostname yes +CanonicalDomains test.com +`) + ctx := &analyzerContext{ + document: d, + diagnostics: make([]protocol.Diagnostic, 0), + } + + analyzeDependents(ctx) + + if len(ctx.diagnostics) > 0 { + t.Errorf("Expected no errors, got %v", len(ctx.diagnostics)) + } +} diff --git a/server/handlers/ssh_config/analyzer/options.go b/server/handlers/ssh_config/analyzer/options.go index 5161592..34dc670 100644 --- a/server/handlers/ssh_config/analyzer/options.go +++ b/server/handlers/ssh_config/analyzer/options.go @@ -43,12 +43,7 @@ func checkOption( _, found := fields.Options[option.Key.Key] if !found { - ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ - Range: option.Key.LocationRange.ToLSPRange(), - Message: fmt.Sprintf("Unknown option: %s", option.Key.Key), - Severity: &common.SeverityError, - }) - + // Diagnostics will be handled by `values.go` return } diff --git a/server/handlers/ssh_config/analyzer/options_test.go b/server/handlers/ssh_config/analyzer/options_test.go index a7855eb..e7a1301 100644 --- a/server/handlers/ssh_config/analyzer/options_test.go +++ b/server/handlers/ssh_config/analyzer/options_test.go @@ -42,8 +42,8 @@ User root analyzeStructureIsValid(ctx) - if len(ctx.diagnostics) != 1 { - t.Fatalf("Expected 1 error, got %v", ctx.diagnostics) + if len(ctx.diagnostics) != 0 { + t.Fatalf("Expected no errors, got %v", ctx.diagnostics) } } @@ -85,7 +85,7 @@ Match analyzeStructureIsValid(ctx) - if len(ctx.diagnostics) != 2 { + if len(ctx.diagnostics) != 1 { t.Fatalf("Expected 1 error, got %v", ctx.diagnostics) } } @@ -108,7 +108,7 @@ Match analyzeStructureIsValid(ctx) - if len(ctx.diagnostics) != 1 { - t.Fatalf("Expected 1 error, got %v", ctx.diagnostics) + if len(ctx.diagnostics) != 0 { + t.Fatalf("Expected no errors, got %v", ctx.diagnostics) } } diff --git a/server/handlers/ssh_config/analyzer/values.go b/server/handlers/ssh_config/analyzer/values.go index 9cc9da2..4752220 100644 --- a/server/handlers/ssh_config/analyzer/values.go +++ b/server/handlers/ssh_config/analyzer/values.go @@ -2,9 +2,7 @@ package analyzer import ( "config-lsp/common" - docvalues "config-lsp/doc-values" "config-lsp/handlers/ssh_config/fields" - "config-lsp/utils" "fmt" protocol "github.com/tliron/glsp/protocol_3_16" @@ -17,7 +15,7 @@ func analyzeValuesAreValid( option := info.Option block := info.Block - docOption, found := fields.Options[option.Key.Key] + _, found := fields.Options[option.Key.Key] if !found { if ctx.document.Indexes.CanOptionBeIgnored(option, block) { @@ -36,20 +34,5 @@ func analyzeValuesAreValid( continue } - - errs := docOption.DeprecatedCheckIsValid(option.OptionValue.Value.Value) - ctx.diagnostics = append( - ctx.diagnostics, - utils.Map( - errs, - func(err *docvalues.InvalidValue) protocol.Diagnostic { - return protocol.Diagnostic{ - Range: err.GetRange(option.Start.Line, option.OptionValue.Start.Character), - Message: err.Err.Error(), - Severity: &common.SeverityError, - } - }, - )..., - ) } }