mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
fix(ssh_config): Properly separate values and options analyzer
This commit is contained in:
parent
4750f8c709
commit
1c5de6c3e1
45
server/handlers/ssh_config/analyzer/dependents_test.go
Normal file
45
server/handlers/ssh_config/analyzer/dependents_test.go
Normal 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))
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
},
|
||||
)...,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user