From 6f8e894acb269eda5227106481f07a37d022c4a0 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 13 Apr 2024 13:44:34 +0200 Subject: [PATCH] references to values.yaml --- internal/handler/generic_document_usecase.go | 1 + .../language_features/generic_document_usecase.go | 1 + internal/language_features/template_context.go | 15 +++++++++++++++ internal/lsp/symbol_table.go | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/internal/handler/generic_document_usecase.go b/internal/handler/generic_document_usecase.go index 4f8c6783..b4e7bf20 100644 --- a/internal/handler/generic_document_usecase.go +++ b/internal/handler/generic_document_usecase.go @@ -31,6 +31,7 @@ func (h *langHandler) NewGenericDocumentUseCase(params lsp.TextDocumentPositionP Document: doc, DocumentStore: h.documents, Chart: chart, + ChartStore: h.chartStore, Node: node, ParentNode: parentNode, ParentNodeType: parentNodeType, diff --git a/internal/language_features/generic_document_usecase.go b/internal/language_features/generic_document_usecase.go index 33188df1..23afbbf9 100644 --- a/internal/language_features/generic_document_usecase.go +++ b/internal/language_features/generic_document_usecase.go @@ -11,6 +11,7 @@ type GenericDocumentUseCase struct { DocumentStore *lsplocal.DocumentStore Chart *charts.Chart Node *sitter.Node + ChartStore *charts.ChartStore NodeType string ParentNode *sitter.Node ParentNodeType string diff --git a/internal/language_features/template_context.go b/internal/language_features/template_context.go index 20f31789..0eaeb736 100644 --- a/internal/language_features/template_context.go +++ b/internal/language_features/template_context.go @@ -52,6 +52,21 @@ func (f *TemplateContextFeature) getReferenceLocations(templateContext lsplocal. } } + return append(locations, f.getDefinitionLocations(templateContext)...) +} + +func (f *TemplateContextFeature) getDefinitionLocations(templateContext lsplocal.TemplateContext) []lsp.Location { + locations := []lsp.Location{} + if len(templateContext) == 0 || templateContext == nil { + return []lsp.Location{} + } + + switch templateContext[0] { + case "Values": + for _, value := range f.Chart.ResolveValueFiles(templateContext.Tail(), f.ChartStore) { + locations = append(locations, value.ValuesFiles.GetPositionsForValue(value.Selector)...) + } + } return locations } diff --git a/internal/lsp/symbol_table.go b/internal/lsp/symbol_table.go index 982c70ea..c9b5e5c3 100644 --- a/internal/lsp/symbol_table.go +++ b/internal/lsp/symbol_table.go @@ -12,6 +12,10 @@ func (t TemplateContext) Format() string { return strings.Join(t, ".") } +func (t TemplateContext) Tail() TemplateContext { + return t[1:] +} + type SymbolTable struct { contexts map[string][]sitter.Range contextsReversed map[sitter.Range]TemplateContext