refactor(sshd_config): Move errsToDiagnostics to common

This commit is contained in:
Myzel394 2024-09-28 11:37:14 +02:00
parent e19ad01fd8
commit 6ab293d84e
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 14 additions and 13 deletions

View File

@ -1,3 +1,13 @@
# /sshd_config/analyzer # /sshd_config/analyzer
This folder analyzes the config file and returns errors, warnings, and suggestions. This folder analyzes the config file and returns errors, warnings, and suggestions.
The analyzer is usually done in three steps:
1. Check if the overall structure is valid
2. Create indexes and check if they were created successfully
3. Do all other checks that require indexes
This is why there are three if statements to check for errors.
If the first step fails, we can't create any indexes and thus show these errors already.

View File

@ -4,7 +4,6 @@ import (
"config-lsp/common" "config-lsp/common"
"config-lsp/handlers/sshd_config" "config-lsp/handlers/sshd_config"
"config-lsp/handlers/sshd_config/indexes" "config-lsp/handlers/sshd_config/indexes"
"config-lsp/utils"
protocol "github.com/tliron/glsp/protocol_3_16" protocol "github.com/tliron/glsp/protocol_3_16"
) )
@ -15,7 +14,7 @@ func Analyze(
errors := analyzeStructureIsValid(d) errors := analyzeStructureIsValid(d)
if len(errors) > 0 { if len(errors) > 0 {
return errsToDiagnostics(errors) return common.ErrsToDiagnostics(errors)
} }
i, indexErrors := indexes.CreateIndexes(*d.Config) i, indexErrors := indexes.CreateIndexes(*d.Config)
@ -25,7 +24,7 @@ func Analyze(
errors = append(errors, indexErrors...) errors = append(errors, indexErrors...)
if len(errors) > 0 { if len(errors) > 0 {
return errsToDiagnostics(errors) return common.ErrsToDiagnostics(errors)
} }
includeErrors := analyzeIncludeValues(d) includeErrors := analyzeIncludeValues(d)
@ -52,17 +51,9 @@ func Analyze(
errors = append(errors, analyzeMatchBlocks(d)...) errors = append(errors, analyzeMatchBlocks(d)...)
if len(errors) > 0 { if len(errors) > 0 {
return errsToDiagnostics(errors) return common.ErrsToDiagnostics(errors)
} }
return nil return nil
} }
func errsToDiagnostics(errs []common.LSPError) []protocol.Diagnostic {
return utils.Map(
errs,
func(err common.LSPError) protocol.Diagnostic {
return err.ToDiagnostic()
},
)
}