Skip to content

Commit

Permalink
refactor: cleanup lsp package (#115)
Browse files Browse the repository at this point in the history
* refactor: cleanup lsp package

* fix: delete not used code
  • Loading branch information
qvalentin authored Nov 10, 2024
1 parent b9fe971 commit 9bc4f54
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 27 deletions.
4 changes: 2 additions & 2 deletions cmds/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/mrjosh/helm-ls/internal/charts"
locallsp "github.com/mrjosh/helm-ls/internal/lsp"
helmlint "github.com/mrjosh/helm-ls/internal/helm_lint"
"github.com/spf13/cobra"
"go.lsp.dev/uri"
)
Expand All @@ -26,7 +26,7 @@ func newLintCmd() *cobra.Command {
return err
}

msgs := locallsp.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values)
msgs := helmlint.GetDiagnostics(rootPath, chart.ValuesFiles.MainValuesFile.Values)

for _, msg := range msgs {
fmt.Println(msg)
Expand Down
5 changes: 3 additions & 2 deletions internal/handler/text_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/mrjosh/helm-ls/internal/charts"
helmlint "github.com/mrjosh/helm-ls/internal/helm_lint"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
lsp "go.lsp.dev/protocol"
)
Expand All @@ -28,7 +29,7 @@ func (h *langHandler) DidOpen(ctx context.Context, params *lsp.DidOpenTextDocume
if err != nil {
logger.Error("Error getting chart info for file", doc.URI, err)
}
notifications := lsplocal.GetDiagnosticsNotifications(chart, doc)
notifications := helmlint.GetDiagnosticsNotifications(chart, doc)

defer h.publishDiagnostics(ctx, notifications)

Expand All @@ -50,7 +51,7 @@ func (h *langHandler) DidSave(ctx context.Context, params *lsp.DidSaveTextDocume
}

h.yamllsConnector.DocumentDidSave(doc, *params)
notifications := lsplocal.GetDiagnosticsNotifications(chart, doc)
notifications := helmlint.GetDiagnosticsNotifications(chart, doc)

defer h.publishDiagnostics(ctx, notifications)

Expand Down
7 changes: 3 additions & 4 deletions internal/lsp/lint.go → internal/helm_lint/lint.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lsp
package helmlint

import (
"fmt"
Expand All @@ -8,19 +8,18 @@ import (

"github.com/mrjosh/helm-ls/internal/charts"
"github.com/mrjosh/helm-ls/internal/log"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
"github.com/mrjosh/helm-ls/internal/util"

lsp "go.lsp.dev/protocol"
"go.lsp.dev/uri"
"helm.sh/helm/v3/pkg/action"

"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/lint/support"
)

var logger = log.GetLogger()

func GetDiagnosticsNotifications(chart *charts.Chart, doc *Document) []lsp.PublishDiagnosticsParams {
func GetDiagnosticsNotifications(chart *charts.Chart, doc *lsplocal.Document) []lsp.PublishDiagnosticsParams {
vals := chart.ValuesFiles.MainValuesFile.Values
if chart.ValuesFiles.OverlayValuesFile != nil {
vals = chartutil.CoalesceTables(chart.ValuesFiles.OverlayValuesFile.Values, chart.ValuesFiles.MainValuesFile.Values)
Expand Down
7 changes: 4 additions & 3 deletions internal/lsp/lint_test.go → internal/helm_lint/lint_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package lsp
package helmlint

import (
"testing"

"github.com/mrjosh/helm-ls/internal/charts"
lsplocal "github.com/mrjosh/helm-ls/internal/lsp"
"github.com/stretchr/testify/assert"
"go.lsp.dev/uri"
"helm.sh/helm/v3/pkg/chartutil"
Expand All @@ -25,7 +26,7 @@ func TestLintNotifications(t *testing.T) {
AdditionalValuesFiles: []*charts.ValuesFile{},
},
}
diagnostics := GetDiagnosticsNotifications(&chart, &Document{URI: uri.File("../../testdata/example/templates/deployment-no-templates.yaml")})
diagnostics := GetDiagnosticsNotifications(&chart, &lsplocal.Document{URI: uri.File("../../testdata/example/templates/deployment-no-templates.yaml")})
assert.NotEmpty(t, diagnostics)
assert.Len(t, diagnostics, 3)

Expand All @@ -50,7 +51,7 @@ func TestLintNotificationsIncludesEmptyDiagnosticsForFixedIssues(t *testing.T) {
AdditionalValuesFiles: []*charts.ValuesFile{},
},
}
diagnostics := GetDiagnosticsNotifications(&chart, &Document{URI: uri.File("../../testdata/example/templates/deployment-no-templates.yaml")})
diagnostics := GetDiagnosticsNotifications(&chart, &lsplocal.Document{URI: uri.File("../../testdata/example/templates/deployment-no-templates.yaml")})

uris := []string{}
for _, notification := range diagnostics {
Expand Down
3 changes: 3 additions & 0 deletions internal/lsp/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"fmt"
"strings"

"github.com/mrjosh/helm-ls/internal/log"
"github.com/mrjosh/helm-ls/internal/util"
sitter "github.com/smacker/go-tree-sitter"
lsp "go.lsp.dev/protocol"
)

var logger = log.GetLogger()

// Document represents an opened file.
type Document struct {
URI lsp.DocumentURI
Expand Down
15 changes: 0 additions & 15 deletions internal/lsp/symbol_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ func (t TemplateContext) AppendSuffix(suffix string) TemplateContext {
return t
}

// Adds a new context to the beginning
func (t TemplateContext) PrependContext(context string) TemplateContext {
if context == "." {
return t
}
return append(TemplateContext{ensureNoLeadingDot(context)}, t...)
}

func NewTemplateContext(string string) TemplateContext {
if string == "." {
return TemplateContext{}
Expand All @@ -51,13 +43,6 @@ func NewTemplateContext(string string) TemplateContext {
return splitted
}

func ensureNoLeadingDot(context string) string {
if context[0] == '.' && len(context) > 1 {
return context[1:]
}
return context
}

type SymbolTable struct {
contexts map[string][]sitter.Range
contextsReversed map[sitter.Range]TemplateContext
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/symbol_table_template_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (v *TemplateContextVisitor) EnterContextShift(node *sitter.Node, suffix str
switch node.Type() {
case gotemplate.NodeTypeFieldIdentifier:
content := node.Content(v.content) + suffix
v.currentContext = append(v.currentContext, content)
v.PushContext(content)
case gotemplate.NodeTypeField:
content := node.ChildByFieldName("name").Content(v.content) + suffix
v.PushContext(content)
Expand Down

0 comments on commit 9bc4f54

Please sign in to comment.