From 3c2d914266561a12c7a684459302475f69fa8b6d Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 27 Oct 2024 15:08:56 +0100 Subject: [PATCH] fix: off one errors in GetNodeForPosition --- internal/util/yaml.go | 2 +- internal/util/yaml_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/util/yaml.go b/internal/util/yaml.go index 69ea7a3..4162ad0 100644 --- a/internal/util/yaml.go +++ b/internal/util/yaml.go @@ -79,7 +79,7 @@ func GetNodeForPosition(node *yamlv3.Node, position lsp.Position) *yamlv3.Node { return nil } - if node.Value != "" && node.Line == int(position.Line+1) && node.Column <= int(position.Character-1) { + if node.Value != "" && node.Line == int(position.Line+1) && node.Column <= int(position.Character+1) { return node } diff --git a/internal/util/yaml_test.go b/internal/util/yaml_test.go index f8f927a..da6608f 100644 --- a/internal/util/yaml_test.go +++ b/internal/util/yaml_test.go @@ -95,6 +95,7 @@ func TestGetNodeForPosition(t *testing.T) { t.Fatalf("error parsing YAML: %v", err) } - result := GetNodeForPosition(&node, lsp.Position{Line: 9, Character: 3}) + result := GetNodeForPosition(&node, lsp.Position{Line: 8, Character: 3}) + assert.NotNil(t, result) assert.Equal(t, "repository", result.Value) }