mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
refactor(sshd_config): Move errsToDiagnostics to common
This commit is contained in:
parent
e19ad01fd8
commit
6ab293d84e
@ -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.
|
||||||
|
|
||||||
|
@ -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()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user