-
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.
Merge pull request #58 from mrjosh/feat-multiple-charts
Multiple Charts, Subcharts and multiple Values file support
- Loading branch information
Showing
43 changed files
with
1,734 additions
and
606 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/bin | ||
/dist | ||
__debug_bin* | ||
.vscode | ||
.coverage |
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
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,57 @@ | ||
package charts | ||
|
||
import ( | ||
"github.com/mrjosh/helm-ls/internal/log" | ||
"github.com/mrjosh/helm-ls/internal/util" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
var logger = log.GetLogger() | ||
|
||
type Chart struct { | ||
ValuesFiles *ValuesFiles | ||
ChartMetadata *ChartMetadata | ||
RootURI uri.URI | ||
ParentChart ParentChart | ||
} | ||
|
||
func NewChart(rootURI uri.URI, valuesFilesConfig util.ValuesFilesConfig) *Chart { | ||
return &Chart{ | ||
ValuesFiles: NewValuesFiles(rootURI, | ||
valuesFilesConfig.MainValuesFileName, | ||
valuesFilesConfig.LintOverlayValuesFileName, | ||
valuesFilesConfig.AdditionalValuesFilesGlobPattern), | ||
ChartMetadata: NewChartMetadata(rootURI), | ||
RootURI: rootURI, | ||
ParentChart: newParentChart(rootURI), | ||
} | ||
} | ||
|
||
type QueriedValuesFiles struct { | ||
Selector []string | ||
ValuesFiles *ValuesFiles | ||
} | ||
|
||
// 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}} | ||
if len(query) == 0 { | ||
return ownResult | ||
} | ||
|
||
parentChart := c.ParentChart.GetParentChart(chartStore) | ||
if parentChart == nil { | ||
return ownResult | ||
} | ||
|
||
if query[0] == "global" { | ||
return append(ownResult, | ||
parentChart.ResolveValueFiles(query, chartStore)...) | ||
} | ||
|
||
chartName := c.ChartMetadata.Metadata.Name | ||
extendedQuery := append([]string{chartName}, query...) | ||
return append(ownResult, | ||
parentChart.ResolveValueFiles(extendedQuery, chartStore)...) | ||
} |
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,70 @@ | ||
package charts | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/mrjosh/helm-ls/pkg/chartutil" | ||
lsp "go.lsp.dev/protocol" | ||
"go.lsp.dev/uri" | ||
) | ||
|
||
func (s *ChartStore) GetChartForDoc(uri lsp.DocumentURI) (*Chart, error) { | ||
chart := s.getChartFromCache(uri) | ||
if chart != nil { | ||
return chart, nil | ||
} | ||
|
||
chart, err := s.getChartFromFilesystemForTemplates(uri.Filename()) | ||
s.Charts[chart.RootURI] = chart | ||
if err != nil { | ||
return chart, ErrChartNotFound{ | ||
URI: uri, | ||
} | ||
} | ||
return chart, nil | ||
} | ||
|
||
func (s *ChartStore) getChartFromCache(uri lsp.DocumentURI) *Chart { | ||
for chartURI, chart := range s.Charts { | ||
if strings.HasPrefix(uri.Filename(), filepath.Join(chartURI.Filename(), "template")) { | ||
return chart | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s *ChartStore) getChartFromFilesystemForTemplates(path string) (*Chart, error) { | ||
directory := filepath.Dir(path) | ||
if filepath.Base(directory) == "templates" { | ||
templatesDir := directory | ||
expectedChartDir := filepath.Dir(templatesDir) | ||
|
||
// check if Chart.yaml exists | ||
if isChartDirectory(expectedChartDir) { | ||
return s.newChart(uri.File(expectedChartDir), s.valuesFilesConfig), nil | ||
} | ||
} | ||
|
||
rootDirectory := s.RootURI.Filename() | ||
if directory == rootDirectory || directory == path { | ||
return s.newChart(uri.File(directory), s.valuesFilesConfig), ErrChartNotFound{} | ||
} | ||
|
||
return s.getChartFromFilesystemForTemplates(directory) | ||
} | ||
|
||
func isChartDirectory(expectedChartDir string) bool { | ||
_, err := os.Stat(filepath.Join(expectedChartDir, chartutil.ChartfileName)) | ||
return err == nil | ||
} | ||
|
||
type ErrChartNotFound struct { | ||
URI lsp.DocumentURI | ||
} | ||
|
||
func (e ErrChartNotFound) Error() string { | ||
return fmt.Sprintf("Chart not found for file: %s. Using fallback", e.URI) | ||
} |
Oops, something went wrong.