mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
feat(wireguard): Add DNS fallback analyzer
This commit is contained in:
parent
ffdf5bac46
commit
74698bb8c5
@ -5,6 +5,7 @@ import (
|
||||
"config-lsp/utils"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
@ -18,10 +19,43 @@ func (p wireguardParser) analyze() []protocol.Diagnostic {
|
||||
|
||||
diagnostics := []protocol.Diagnostic{}
|
||||
diagnostics = append(diagnostics, p.checkForDuplicateProperties()...)
|
||||
diagnostics = append(diagnostics, p.analyzeDNSContainsFallback()...)
|
||||
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
func (p wireguardParser) analyzeDNSContainsFallback() []protocol.Diagnostic {
|
||||
lineNumber, property := p.fetchPropertyByName("DNS")
|
||||
|
||||
if property == nil {
|
||||
return []protocol.Diagnostic{}
|
||||
}
|
||||
|
||||
dnsAmount := len(strings.Split(property.Value.Value, ","))
|
||||
|
||||
if dnsAmount == 1 {
|
||||
severity := protocol.DiagnosticSeverityWarning
|
||||
return []protocol.Diagnostic{
|
||||
{
|
||||
Message: "There is one DNS server specified. It is recommended to set up fallback DNS servers",
|
||||
Severity: &severity,
|
||||
Range: protocol.Range{
|
||||
Start: protocol.Position{
|
||||
Line: *lineNumber,
|
||||
Character: property.Value.Location.Start,
|
||||
},
|
||||
End: protocol.Position{
|
||||
Line: *lineNumber,
|
||||
Character: property.Value.Location.End,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return []protocol.Diagnostic{}
|
||||
}
|
||||
|
||||
func (p wireguardParser) checkIfValuesAreValid() []protocol.Diagnostic {
|
||||
diagnostics := []protocol.Diagnostic{}
|
||||
|
||||
|
@ -33,6 +33,20 @@ type wireguardParser struct {
|
||||
LineIndexes map[uint32]wireguardLineIndex
|
||||
}
|
||||
|
||||
// Search for a property by name
|
||||
// Returns (line number, property)
|
||||
func (p *wireguardParser) fetchPropertyByName(name string) (*uint32, *wireguardProperty) {
|
||||
for _, section := range p.Sections {
|
||||
for lineNumber, property := range section.Properties {
|
||||
if property.Key.Name == name {
|
||||
return &lineNumber, &property
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (p *wireguardParser) clear() {
|
||||
p.Sections = []*wireguardSection{}
|
||||
p.CommentLines = map[uint32]struct{}{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user