Skip to content

Commit

Permalink
feat(document-symbols): add yamlls document-symbols (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
qvalentin authored Jul 28, 2024
1 parent 312b9c0 commit cd29aa2
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/mrjosh/helm-ls
go 1.21

require (
github.com/gobwas/glob v0.2.3
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/smacker/go-tree-sitter v0.0.0-20240214120134-1f283e24f560
Expand Down Expand Up @@ -55,7 +56,6 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions internal/adapter/yamlls/initization.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func (yamllsConnector Connector) CallInitialize(ctx context.Context, workspaceUR
ClientInfo: &lsp.ClientInfo{
Name: "helm-ls",
},
Capabilities: lsp.ClientCapabilities{
TextDocument: &lsp.TextDocumentClientCapabilities{
DocumentSymbol: &lsp.DocumentSymbolClientCapabilities{
HierarchicalDocumentSymbolSupport: true,
},
},
},
}

_, err := yamllsConnector.server.Initialize(ctx, &params)
Expand Down
14 changes: 14 additions & 0 deletions internal/adapter/yamlls/symbol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package yamlls

import (
"context"

lsp "go.lsp.dev/protocol"
)

func (yamllsConnector Connector) CallDocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{}, err error) {
if yamllsConnector.server == nil {
return []interface{}{}, nil
}
return yamllsConnector.server.DocumentSymbol(ctx, params)
}
50 changes: 50 additions & 0 deletions internal/adapter/yamlls/symbol_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build integration

package yamlls

import (
"context"
"testing"
"time"

"github.com/mrjosh/helm-ls/internal/util"
"github.com/stretchr/testify/assert"
lsp "go.lsp.dev/protocol"
"go.lsp.dev/uri"
)

func TestYamllsDocumentSymoblIntegration(t *testing.T) {
config := util.DefaultConfig.YamllsConfiguration

testCases := []struct {
file string
expectedLen int
}{
{
file: "../../../testdata/example/templates/deployment.yaml",
expectedLen: 4,
},
{
file: "../../../testdata/example/templates/ingress.yaml",
expectedLen: 6,
},
}
for _, tt1 := range testCases {
tt := tt1
t.Run(tt.file, func(t *testing.T) {
t.Parallel()
yamllsConnector, documents, _ := getYamlLsConnector(t, config)
openFile(t, documents, tt.file, yamllsConnector)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
result, err := yamllsConnector.CallDocumentSymbol(context.Background(), &lsp.DocumentSymbolParams{
TextDocument: lsp.TextDocumentIdentifier{
URI: uri.File(tt.file),
},
})
assert.NoError(c, err)
assert.Len(c, result, tt.expectedLen)
}, time.Second*10, time.Second*2)
})
}
}
6 changes: 5 additions & 1 deletion internal/adapter/yamlls/yamlls.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ func NewConnector(ctx context.Context, yamllsConfiguration util.YamllsConfigurat
io.Copy(os.Stderr, strderr)

Check failure on line 68 in internal/adapter/yamlls/yamlls.go

View workflow job for this annotation

GitHub Actions / lint (1.21.5, ubuntu-latest)

Error return value of `io.Copy` is not checked (errcheck)
}()

yamllsConnector := Connector{documents: documents, config: yamllsConfiguration, client: client}
yamllsConnector := Connector{
config: yamllsConfiguration,
documents: documents,
client: client,
}

zapLogger, _ := zap.NewProduction()
_, _, server := protocol.NewClient(ctx, yamllsConnector, jsonrpc2.NewStream(readWriteCloser), zapLogger)
Expand Down
6 changes: 0 additions & 6 deletions internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ func (h *langHandler) DocumentLinkResolve(ctx context.Context, params *lsp.Docum
return nil, nil
}

// DocumentSymbol implements protocol.Server.
func (h *langHandler) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{}, err error) {
logger.Error("Document symbol unimplemented")
return nil, nil
}

// ExecuteCommand implements protocol.Server.
func (h *langHandler) ExecuteCommand(ctx context.Context, params *lsp.ExecuteCommandParams) (result interface{}, err error) {
logger.Error("Execute command unimplemented")
Expand Down
12 changes: 5 additions & 7 deletions internal/handler/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@ func (h *langHandler) Initialize(ctx context.Context, params *lsp.InitializePara
TextDocumentSync: lsp.TextDocumentSyncOptions{
Change: lsp.TextDocumentSyncKindIncremental,
OpenClose: true,
Save: &lsp.SaveOptions{
IncludeText: true,
},
},
CompletionProvider: &lsp.CompletionOptions{
TriggerCharacters: []string{".", "$."},
ResolveProvider: false,
},
HoverProvider: true,
DefinitionProvider: true,
ReferencesProvider: true,
HoverProvider: true,
DefinitionProvider: true,
ReferencesProvider: true,
DocumentSymbolProvider: true,
},
}, nil
}

func (h *langHandler) Initialized(ctx context.Context, _ *lsp.InitializedParams) (err error) {
go h.retrieveWorkspaceConfiguration(ctx)
h.retrieveWorkspaceConfiguration(ctx)
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions internal/handler/symbol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package handler

import (
"context"

lsp "go.lsp.dev/protocol"
)

// DocumentSymbol implements protocol.Server.
func (h *langHandler) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{}, err error) {
return h.yamllsConnector.CallDocumentSymbol(ctx, params)
}

0 comments on commit cd29aa2

Please sign in to comment.