mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 15:05:28 +02:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package analyzer
|
|
|
|
import (
|
|
"config-lsp/common"
|
|
"config-lsp/handlers/wireguard/fields"
|
|
"config-lsp/utils"
|
|
"fmt"
|
|
|
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
|
)
|
|
|
|
func analyzeStructureIsValid(ctx *analyzerContext) {
|
|
for _, section := range ctx.document.Config.Sections {
|
|
normalizedHeaderName := fields.CreateNormalizedName(section.Header.Name)
|
|
|
|
if section.Header.Name == "" {
|
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
|
Message: "This section is missing a name",
|
|
Range: section.Header.ToLSPRange(),
|
|
Severity: &common.SeverityError,
|
|
})
|
|
} else if !utils.KeyExists(fields.OptionsHeaderMap, normalizedHeaderName) {
|
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
|
Message: fmt.Sprintf("Unknown section '%s'. It must be one of: [Interface], [Peer]", section.Header.Name),
|
|
Range: section.Header.ToLSPRange(),
|
|
Severity: &common.SeverityError,
|
|
})
|
|
}
|
|
|
|
if section.Properties.Size() == 0 {
|
|
ctx.diagnostics = append(ctx.diagnostics, protocol.Diagnostic{
|
|
Message: "This section is empty",
|
|
Range: section.Header.ToLSPRange(),
|
|
Severity: &common.SeverityInformation,
|
|
Tags: []protocol.DiagnosticTag{
|
|
protocol.DiagnosticTagUnnecessary,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
}
|