fix(ssh_config): Properly separate values and options analyzer

This commit is contained in:
Myzel394 2024-10-03 23:15:25 +02:00
parent 4750f8c709
commit 1c5de6c3e1
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
4 changed files with 52 additions and 29 deletions

View File

@ -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))
}
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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,
}
},
)...,
)
}
}