Myzel394 eb076dbf53
refactor(server): Improve Wireguard analyzer
Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
2025-03-16 00:23:54 +01:00

46 lines
879 B
Go

package analyzer
import (
"config-lsp/common"
"config-lsp/handlers/wireguard"
"config-lsp/handlers/wireguard/indexes"
protocol "github.com/tliron/glsp/protocol_3_16"
)
type analyzerContext struct {
document *wireguard.WGDocument
diagnostics []protocol.Diagnostic
}
func Analyze(
d *wireguard.WGDocument,
) []protocol.Diagnostic {
ctx := &analyzerContext{
document: d,
diagnostics: make([]protocol.Diagnostic, 0),
}
analyzeStructureIsValid(ctx)
if len(ctx.diagnostics) > 0 {
return ctx.diagnostics
}
i, indexErrors := indexes.CreateIndexes(d.Config)
if len(indexErrors) > 0 {
return common.ErrsToDiagnostics(indexErrors)
}
d.Indexes = i
analyzeInterfaceSection(ctx)
analyzeDNSPropertyContainsFallback(ctx)
analyzeKeepAlivePropertyIsSet(ctx)
analyzeSymmetricPropertiesSet(ctx)
analyzeDuplicateAllowedIPs(ctx)
return ctx.diagnostics
}