diff --git a/internal/lsp/yaml_ast.go b/internal/lsp/yaml_ast.go index 7e085596..dc27a7da 100644 --- a/internal/lsp/yaml_ast.go +++ b/internal/lsp/yaml_ast.go @@ -8,18 +8,22 @@ import ( "github.com/smacker/go-tree-sitter/yaml" ) +func getRangeForNode(node *sitter.Node) sitter.Range { + return sitter.Range{ + StartPoint: node.StartPoint(), + EndPoint: node.EndPoint(), + StartByte: node.StartByte(), + EndByte: node.EndByte(), + } +} + func getTextNodeRanges(gotemplateNode *sitter.Node) []sitter.Range { textNodes := []sitter.Range{} for i := 0; i < int(gotemplateNode.ChildCount()); i++ { child := gotemplateNode.Child(i) if child.Type() == gotemplate.NodeTypeText { - textNodes = append(textNodes, sitter.Range{ - StartPoint: child.StartPoint(), - EndPoint: child.EndPoint(), - StartByte: child.StartByte(), - EndByte: child.EndByte(), - }) + textNodes = append(textNodes, getRangeForNode(child)) } else { textNodes = append(textNodes, getTextNodeRanges(child)...) } @@ -39,10 +43,13 @@ func ParseYamlAst(gotemplateTree *sitter.Tree, content string) *sitter.Tree { func TrimTemplate(gotemplateTree *sitter.Tree, content string) string { ranges := getTextNodeRanges(gotemplateTree.RootNode()) result := make([]byte, len(content)) - for i := 0; i < len(result); i++ { + for i := range result { if content[i] == '\n' { result[i] = byte('\n') continue + } else if content[i] == '\r' { + result[i] = byte('\r') + continue } result[i] = byte(' ') }