fix(server): Improve wireguard

Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
This commit is contained in:
Myzel394 2025-03-09 19:49:23 +01:00 committed by Myzel394
parent 1227949f26
commit e14866bcdc
No known key found for this signature in database
GPG Key ID: B603E877F73D4ABB

View File

@ -2,6 +2,7 @@ package analyzer
import ( import (
"config-lsp/common" "config-lsp/common"
docvalues "config-lsp/doc-values"
"config-lsp/handlers/wireguard/ast" "config-lsp/handlers/wireguard/ast"
"config-lsp/handlers/wireguard/fields" "config-lsp/handlers/wireguard/fields"
"config-lsp/utils" "config-lsp/utils"
@ -63,23 +64,39 @@ func analyzeStructureIsValid(ctx *analyzerContext) {
Range: property.ToLSPRange(), Range: property.ToLSPRange(),
Severity: &common.SeverityError, Severity: &common.SeverityError,
}) })
checkAllowedProperty = false
} }
if checkAllowedProperty { if checkAllowedProperty {
options := fields.OptionsHeaderMap[normalizedHeaderName] availableOptions := fields.OptionsHeaderMap[normalizedHeaderName]
if !utils.KeyExists(options, normalizedPropertyName) { // Duplicate check
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ if existingProperty, found := existingProperties[normalizedPropertyName]; found {
Message: fmt.Sprintf("Unknown property '%s'", property.Key.Name),
Range: property.Key.ToLSPRange(),
Severity: &common.SeverityError,
})
} else if existingProperty, found := existingProperties[normalizedPropertyName]; found {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{ ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Message: fmt.Sprintf("Property '%s' has already been defined on line %d", property.Key.Name, existingProperty.Start.Line+1), Message: fmt.Sprintf("Property '%s' has already been defined on line %d", property.Key.Name, existingProperty.Start.Line+1),
Severity: &common.SeverityError, Severity: &common.SeverityError,
Range: existingProperty.ToLSPRange(), Range: existingProperty.ToLSPRange(),
}) })
// Check if value is valid
} else if option, found := availableOptions[normalizedPropertyName]; found {
invalidValues := option.DeprecatedCheckIsValid(property.Value.Value)
for _, invalidValue := range invalidValues {
err := docvalues.LSPErrorFromInvalidValue(property.Start.Line, *invalidValue).ShiftCharacter(property.Value.Start.Character)
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Range: err.Range.ToLSPRange(),
Message: err.Err.Error(),
Severity: &common.SeverityError,
})
}
// Unknown property
} else {
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
Message: fmt.Sprintf("Unknown property '%s'", property.Key.Name),
Range: property.Key.ToLSPRange(),
Severity: &common.SeverityError,
})
} }
existingProperties[normalizedPropertyName] = property existingProperties[normalizedPropertyName] = property