mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
fix(aliases): Add double keys analyzer
This commit is contained in:
parent
31faa9a96d
commit
4ea6f9f160
@ -1,13 +1,33 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/hosts"
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/aliases"
|
||||
"config-lsp/utils"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
func Analyze(
|
||||
d *hosts.HostsDocument,
|
||||
d *aliases.AliasesDocument,
|
||||
) []protocol.Diagnostic {
|
||||
return nil
|
||||
errors := analyzeValuesAreValid(*d.Parser)
|
||||
|
||||
if len(errors) > 0 {
|
||||
return utils.Map(
|
||||
errors,
|
||||
func(err common.LSPError) protocol.Diagnostic {
|
||||
return err.ToDiagnostic()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
errors = append(errors, analyzeDoubleKeys(d)...)
|
||||
|
||||
return utils.Map(
|
||||
errors,
|
||||
func(err common.LSPError) protocol.Diagnostic {
|
||||
return err.ToDiagnostic()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
21
handlers/aliases/analyzer/double_keys.go
Normal file
21
handlers/aliases/analyzer/double_keys.go
Normal file
@ -0,0 +1,21 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"config-lsp/common"
|
||||
"config-lsp/handlers/aliases"
|
||||
"config-lsp/handlers/aliases/indexes"
|
||||
)
|
||||
|
||||
func analyzeDoubleKeys(
|
||||
d *aliases.AliasesDocument,
|
||||
) []common.LSPError {
|
||||
indexes, errors := indexes.CreateIndexes(*d.Parser)
|
||||
|
||||
d.Indexes = &indexes
|
||||
|
||||
if len(errors) > 0 {
|
||||
return errors
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
73
handlers/aliases/analyzer/double_keys_test.go
Normal file
73
handlers/aliases/analyzer/double_keys_test.go
Normal file
@ -0,0 +1,73 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"config-lsp/handlers/aliases"
|
||||
"config-lsp/handlers/aliases/ast"
|
||||
"config-lsp/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWorks(
|
||||
t *testing.T,
|
||||
) {
|
||||
input := utils.Dedent(`
|
||||
support: michael
|
||||
marketing: john
|
||||
support: jane
|
||||
`)
|
||||
p := ast.NewAliasesParser()
|
||||
errors := p.Parse(input)
|
||||
|
||||
d := aliases.AliasesDocument{
|
||||
Parser: &p,
|
||||
}
|
||||
|
||||
if len(errors) != 0 {
|
||||
t.Errorf("Expected no errors, got %v", errors)
|
||||
}
|
||||
|
||||
errors = analyzeDoubleKeys(&d)
|
||||
|
||||
if !(len(errors) == 1) {
|
||||
t.Errorf("Expected 1 error, got %v", errors)
|
||||
}
|
||||
|
||||
if d.Indexes == nil {
|
||||
t.Errorf("Expected indexes to be set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidWorks(
|
||||
t *testing.T,
|
||||
) {
|
||||
input := utils.Dedent(`
|
||||
support: michael
|
||||
marketing: john
|
||||
supportgroup: jane
|
||||
suppor: jane
|
||||
`)
|
||||
p := ast.NewAliasesParser()
|
||||
errors := p.Parse(input)
|
||||
|
||||
d := aliases.AliasesDocument{
|
||||
Parser: &p,
|
||||
}
|
||||
|
||||
if len(errors) != 0 {
|
||||
t.Errorf("Expected no errors, got %v", errors)
|
||||
}
|
||||
|
||||
errors = analyzeDoubleKeys(&d)
|
||||
|
||||
if !(len(errors) == 0) {
|
||||
t.Errorf("Expected 0 errors, got %v", errors)
|
||||
}
|
||||
|
||||
if d.Indexes == nil {
|
||||
t.Errorf("Expected indexes to be set")
|
||||
}
|
||||
|
||||
if d.Indexes.Keys["support"] == nil {
|
||||
t.Errorf("Expected support to be in indexes")
|
||||
}
|
||||
}
|
@ -7,9 +7,9 @@ import (
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
|
||||
type HostsDocument struct {
|
||||
type AliasesDocument struct {
|
||||
Parser *ast.AliasesParser
|
||||
Indexes *indexes.AliasesIndexes
|
||||
}
|
||||
|
||||
var DocumentParserMap = map[protocol.DocumentUri]*HostsDocument{}
|
||||
var DocumentParserMap = map[protocol.DocumentUri]*AliasesDocument{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user