diff --git a/handlers/sshd_config/analyzer/README.md b/handlers/sshd_config/analyzer/README.md index dfd445c..25d1233 100644 --- a/handlers/sshd_config/analyzer/README.md +++ b/handlers/sshd_config/analyzer/README.md @@ -1,3 +1,13 @@ # /sshd_config/analyzer -This folder analyzes the config file and returns errors, warnings, and suggestions. \ No newline at end of file +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. + diff --git a/handlers/sshd_config/analyzer/analyzer.go b/handlers/sshd_config/analyzer/analyzer.go index 3a204ea..73ab878 100644 --- a/handlers/sshd_config/analyzer/analyzer.go +++ b/handlers/sshd_config/analyzer/analyzer.go @@ -4,7 +4,6 @@ import ( "config-lsp/common" "config-lsp/handlers/sshd_config" "config-lsp/handlers/sshd_config/indexes" - "config-lsp/utils" protocol "github.com/tliron/glsp/protocol_3_16" ) @@ -15,7 +14,7 @@ func Analyze( errors := analyzeStructureIsValid(d) if len(errors) > 0 { - return errsToDiagnostics(errors) + return common.ErrsToDiagnostics(errors) } i, indexErrors := indexes.CreateIndexes(*d.Config) @@ -25,7 +24,7 @@ func Analyze( errors = append(errors, indexErrors...) if len(errors) > 0 { - return errsToDiagnostics(errors) + return common.ErrsToDiagnostics(errors) } includeErrors := analyzeIncludeValues(d) @@ -52,17 +51,9 @@ func Analyze( errors = append(errors, analyzeMatchBlocks(d)...) if len(errors) > 0 { - return errsToDiagnostics(errors) + return common.ErrsToDiagnostics(errors) } return nil } -func errsToDiagnostics(errs []common.LSPError) []protocol.Diagnostic { - return utils.Map( - errs, - func(err common.LSPError) protocol.Diagnostic { - return err.ToDiagnostic() - }, - ) -}