fix(ssh_config): Check Host options in order

This commit is contained in:
Myzel394 2024-10-02 15:59:07 +02:00
parent 90b62cf01f
commit 6c603f5c5b
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
2 changed files with 14 additions and 1 deletions

View File

@ -1,9 +1,12 @@
package analyzer
import (
"cmp"
"config-lsp/common"
"config-lsp/handlers/ssh_config/ast"
hostparser "config-lsp/handlers/ssh_config/host-parser"
"fmt"
"slices"
protocol "github.com/tliron/glsp/protocol_3_16"
)
@ -13,7 +16,15 @@ func analyzeHostBlock(
) {
hosts := make(map[string]*hostparser.HostValue, 0)
for _, block := range ctx.document.GetAllHostBlocks() {
blocks := ctx.document.GetAllHostBlocks()
slices.SortFunc(
blocks,
func(a, b *ast.SSHHostBlock) int {
return cmp.Compare(a.Start.Line, b.Start.Line)
},
)
for _, block := range blocks {
if block == nil || block.HostValue == nil {
continue
}

View File

@ -57,6 +57,8 @@ func (d SSHDocument) GetAllMatchBlocks() []*ast.SSHMatchBlock {
var hostOption = fields.CreateNormalizedName("Host")
// GetAllHostBlocks: Returns all Host blocks.
// Note: This is not sorted
func (d SSHDocument) GetAllHostBlocks() []*ast.SSHHostBlock {
hostBlocks := make([]*ast.SSHHostBlock, 0, 5)