Skip to content

Commit

Permalink
feat(values): support values of dependecy-charts (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin committed May 24, 2024
1 parent 2707018 commit c240de6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
38 changes: 33 additions & 5 deletions internal/charts/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,52 @@ type QueriedValuesFiles struct {
// ResolveValueFiles returns a list of all values files in the chart
// and all parent charts if the query tries to access global values
func (c *Chart) ResolveValueFiles(query []string, chartStore *ChartStore) []*QueriedValuesFiles {
ownResult := []*QueriedValuesFiles{{Selector: query, ValuesFiles: c.ValuesFiles}}
logger.Debug(fmt.Sprintf("Resolving values files for %s with query %s", c.HelmChart.Name(), query))
result := []*QueriedValuesFiles{{Selector: query, ValuesFiles: c.ValuesFiles}}
if len(query) == 0 {
return ownResult
return result
}

for _, dependency := range c.HelmChart.Dependencies() {
logger.Debug(fmt.Sprintf("Resolving dependency %s with query %s", dependency.Name(), query))
if dependency.Name() == query[0] {

subQuery := []string{}
if len(query) > 1 {
subQuery = query[1:]
}

valueNode, error := util.ValuesToYamlNode(dependency.Values)

Check failure on line 78 in internal/charts/chart.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
logger.Error(fmt.Sprintf("Error loading values file %s: %s", dependency.Name(), error.Error()))
continue
}

result = append(result,
// TODO: should we do this now? or should we create a chart in the store for each dependency
&QueriedValuesFiles{Selector: subQuery, ValuesFiles: &ValuesFiles{
MainValuesFile: &ValuesFile{
Values: dependency.Values,
ValueNode: valueNode,
URI: uri.File(dependency.ChartPath()), // TODO: Fix this, chartPath is not a file path but something like chartNameA.common
},
}})
}
}

parentChart := c.ParentChart.GetParentChart(chartStore)
if parentChart == nil {
return ownResult
return result
}

if query[0] == "global" {
return append(ownResult,
return append(result,
parentChart.ResolveValueFiles(query, chartStore)...)
}

chartName := c.ChartMetadata.Metadata.Name
extendedQuery := append([]string{chartName}, query...)
return append(ownResult,
return append(result,
parentChart.ResolveValueFiles(extendedQuery, chartStore)...)
}

Expand Down
2 changes: 2 additions & 0 deletions internal/handler/text_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"errors"
"fmt"
"path/filepath"

"github.com/mrjosh/helm-ls/internal/charts"
Expand Down Expand Up @@ -106,6 +107,7 @@ func (h *langHandler) LoadDocsOnNewChart(chart *charts.Chart) {
h.documents.Store(filepath.Join(chart.RootURI.Filename(), file.Name), file.Data, h.helmlsConfig)
}
for _, file := range chart.GetDependeciesTemplates() {
logger.Debug(fmt.Sprintf("Storing dependency %s", file.Path))
h.documents.Store(file.Path, file.Content, h.helmlsConfig)
}
}
2 changes: 1 addition & 1 deletion internal/lsp/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (d *Document) ApplyChanges(changes []lsp.TextDocumentContentChangeEvent) {
d.Content = string(content)

d.ApplyChangesToAst(d.Content)
d.SymbolTable = NewSymbolTable(d.Ast, []byte(d.Content))
d.SymbolTable = NewSymbolTable(d.Ast, content)

d.lines = nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/lsp/document_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *DocumentStore) DidOpen(params *lsp.DidOpenTextDocumentParams, helmlsCon
return doc, nil
}

func (s *DocumentStore) Store(filename string, content []byte, helmlsConfig util.HelmlsConfiguration) error {
func (s *DocumentStore) Store(filename string, content []byte, helmlsConfig util.HelmlsConfiguration) {
ast := ParseAst(nil, string(content))
s.documents.Store(filename,
&Document{
Expand All @@ -62,7 +62,6 @@ func (s *DocumentStore) Store(filename string, content []byte, helmlsConfig util
SymbolTable: NewSymbolTable(ast, content),
},
)
return nil
}

func (s *DocumentStore) Get(docuri uri.URI) (*Document, bool) {
Expand Down
10 changes: 10 additions & 0 deletions internal/util/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

lsp "go.lsp.dev/protocol"
yamlv3 "gopkg.in/yaml.v3"
"helm.sh/helm/v3/pkg/chartutil"
)

func GetPositionOfNode(node *yamlv3.Node, query []string) (lsp.Position, error) {
Expand Down Expand Up @@ -85,3 +86,12 @@ func ReadYamlFileToNode(filename string) (node yamlv3.Node, err error) {
err = yamlv3.Unmarshal(data, &node)
return node, err
}

func ValuesToYamlNode(values chartutil.Values) (node yamlv3.Node, err error) {
yaml, error := values.YAML()

Check failure on line 91 in internal/util/yaml.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

redefines-builtin-id: redefinition of the built-in type error (revive)
if error != nil {
return yamlv3.Node{}, error
}
err = yamlv3.Unmarshal([]byte(yaml), &node)
return node, err
}

0 comments on commit c240de6

Please sign in to comment.