diff --git a/handlers/ssh_config/analyzer/host.go b/handlers/ssh_config/analyzer/host.go index 84e6eac..0fcc94c 100644 --- a/handlers/ssh_config/analyzer/host.go +++ b/handlers/ssh_config/analyzer/host.go @@ -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 } diff --git a/handlers/ssh_config/document_fields.go b/handlers/ssh_config/document_fields.go index cf673c4..7663a21 100644 --- a/handlers/ssh_config/document_fields.go +++ b/handlers/ssh_config/document_fields.go @@ -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)