-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(definition): go to defintion for values and Chart
- Loading branch information
Showing
8 changed files
with
272 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
|
||
lsp "go.lsp.dev/protocol" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func GetPositionOfNode(node yaml.Node, query []string) (lsp.Position, error) { | ||
|
||
if node.IsZero() { | ||
return lsp.Position{}, fmt.Errorf("Could not find Position of %s in values.yaml. Node was zero.", query) | ||
} | ||
println(node.Value) | ||
|
||
for index, value := range node.Content { | ||
if value.Value == "" { | ||
result, err := GetPositionOfNode(*value, query) | ||
if err == nil { | ||
return result, nil | ||
} | ||
} | ||
if value.Value == query[0] { | ||
if len(query) > 1 { | ||
if len(node.Content) < index+1 { | ||
return lsp.Position{}, fmt.Errorf("Could not find Position of %s in values.yaml", query) | ||
} else { | ||
return GetPositionOfNode(*node.Content[index+1], query[1:]) | ||
} | ||
} else { | ||
return lsp.Position{Line: uint32(value.Line) - 1, Character: uint32(value.Column) - 1}, nil | ||
} | ||
} | ||
} | ||
return lsp.Position{}, fmt.Errorf("Could not find Position of %s in values.yaml. Found no match.", query) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
lsp "go.lsp.dev/protocol" | ||
"os" | ||
"testing" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestGetPositionOfNode(t *testing.T) { | ||
|
||
data, err := os.ReadFile("./yaml_test_input.yaml") | ||
if err != nil { | ||
print(fmt.Sprint(err)) | ||
t.Errorf("error yml parsing") | ||
} | ||
|
||
var node yaml.Node | ||
err = yaml.Unmarshal(data, &node) | ||
|
||
if err != nil { | ||
print(fmt.Sprint(err)) | ||
t.Errorf("error yml parsing") | ||
} | ||
|
||
result, err := GetPositionOfNode(node, []string{"replicaCount"}) | ||
expected := lsp.Position{Line: 6, Character: 1} | ||
if err != nil { | ||
t.Errorf("Result had error: %s", err) | ||
} | ||
if result != expected { | ||
t.Errorf("Result was not expected Position %v but was %v", expected, result) | ||
} | ||
|
||
result, err = GetPositionOfNode(node, []string{"image", "repository"}) | ||
expected = lsp.Position{Line: 9, Character: 3} | ||
if err != nil { | ||
t.Errorf("Result had error: %s", err) | ||
} | ||
if result != expected { | ||
t.Errorf("Result was not expected Position %v but was %v", expected, result) | ||
} | ||
|
||
result, err = GetPositionOfNode(node, []string{"service", "test", "nested", "value"}) | ||
expected = lsp.Position{Line: 31, Character: 7} | ||
if err != nil { | ||
t.Errorf("Result had error: %s", err) | ||
} | ||
if result != expected { | ||
t.Errorf("Result was not expected Position %v but was %v", expected, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
global: | ||
some: | ||
test: 1 | ||
|
||
replicaCount: 1 | ||
|
||
image: | ||
repository: nginx | ||
pullPolicy: IfNotPresent | ||
# Overrides the image tag whose default is the chart appVersion. | ||
tag: "" | ||
|
||
nameOverride: "" | ||
fullnameOverride: "" | ||
|
||
serviceAccount: | ||
# Specifies whether a service account should be created | ||
create: true | ||
# Annotations to add to the service account | ||
annotations: {} | ||
# The name of the service account to use. | ||
# If not set and create is true, a name is generated using the fullname template | ||
name: "" | ||
|
||
service: | ||
type: ClusterIP | ||
port: 80 | ||
test: | ||
nested: | ||
value: test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters