Skip to content

Commit

Permalink
Wire up Stacks feature to LSP handlers
Browse files Browse the repository at this point in the history
Co-authored-by: James Pogran <jpogran@outlook.com>
  • Loading branch information
dbanck and jpogran committed Jul 5, 2024
1 parent 9a4842d commit 9a93f4d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
16 changes: 16 additions & 0 deletions internal/langserver/handlers/did_change_watched_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func TestLangServer_DidChangeWatchedFiles_change_file(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()

Expand Down Expand Up @@ -243,6 +245,8 @@ func TestLangServer_DidChangeWatchedFiles_create_file(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()
ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -380,6 +384,8 @@ func TestLangServer_DidChangeWatchedFiles_delete_file(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()
ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -512,6 +518,8 @@ func TestLangServer_DidChangeWatchedFiles_change_dir(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()
ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -651,6 +659,8 @@ func TestLangServer_DidChangeWatchedFiles_create_dir(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()
ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -787,6 +797,8 @@ func TestLangServer_DidChangeWatchedFiles_delete_dir(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()
ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -954,6 +966,8 @@ func TestLangServer_DidChangeWatchedFiles_pluginChange(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()
wc := walker.NewWalkerCollector()

ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down Expand Up @@ -1056,6 +1070,8 @@ func TestLangServer_DidChangeWatchedFiles_moduleInstalled(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()
wc := walker.NewWalkerCollector()

ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
Expand Down
1 change: 1 addition & 0 deletions internal/langserver/handlers/hooks_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func updateDiagnostics(features *Features, dNotifier *diagnostics.Notifier) noti

diags.Extend(features.Modules.Diagnostics(path))
diags.Extend(features.Variables.Diagnostics(path))
diags.Extend(features.Stacks.Diagnostics(path))

dNotifier.PublishHCLDiags(ctx, path, diags)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/langserver/handlers/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ func TestInitialize_differentWorkspaceLayouts(t *testing.T) {
defer features.RootModules.Stop()
features.Variables.Start(ctx)
defer features.Variables.Stop()
features.Stacks.Start(ctx)
defer features.Stacks.Stop()

wc := walker.NewWalkerCollector()

Expand Down
19 changes: 17 additions & 2 deletions internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/terraform-ls/internal/eventbus"
fmodules "github.com/hashicorp/terraform-ls/internal/features/modules"
frootmodules "github.com/hashicorp/terraform-ls/internal/features/rootmodules"
"github.com/hashicorp/terraform-ls/internal/features/stacks"
fvariables "github.com/hashicorp/terraform-ls/internal/features/variables"
"github.com/hashicorp/terraform-ls/internal/filesystem"
"github.com/hashicorp/terraform-ls/internal/job"
Expand Down Expand Up @@ -48,6 +49,7 @@ type Features struct {
Modules *fmodules.ModulesFeature
RootModules *frootmodules.RootModulesFeature
Variables *fvariables.VariablesFeature
Stacks *stacks.StacksFeature
}

type service struct {
Expand Down Expand Up @@ -534,17 +536,27 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s
variablesFeature.SetLogger(svc.logger)
variablesFeature.Start(svc.sessCtx)

stacksFeature, err := stacks.NewStacksFeature(svc.eventBus, svc.stateStore, svc.fs)
if err != nil {
return err
}
stacksFeature.SetLogger(svc.logger)
stacksFeature.Start(svc.sessCtx)

svc.features = &Features{
Modules: modulesFeature,
RootModules: rootModulesFeature,
Variables: variablesFeature,
Stacks: stacksFeature,
}
}

svc.decoder = decoder.NewDecoder(&idecoder.GlobalPathReader{
PathReaderMap: idecoder.PathReaderMap{
"terraform": svc.features.Modules,
"terraform-vars": svc.features.Variables,
"terraform": svc.features.Modules,
"terraform-vars": svc.features.Variables,
"terraform-stack": svc.features.Stacks,
"terraform-deploy": svc.features.Stacks,
},
})
decoderContext := idecoder.DecoderContext(ctx)
Expand Down Expand Up @@ -634,6 +646,9 @@ func (svc *service) shutdown() {
if svc.features.Variables != nil {
svc.features.Variables.Stop()
}
if svc.features.Stacks != nil {
svc.features.Stacks.Stop()
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions internal/langserver/handlers/session_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-ls/internal/eventbus"
fmodules "github.com/hashicorp/terraform-ls/internal/features/modules"
frootmodules "github.com/hashicorp/terraform-ls/internal/features/rootmodules"
fstacks "github.com/hashicorp/terraform-ls/internal/features/stacks"
fvariables "github.com/hashicorp/terraform-ls/internal/features/variables"
"github.com/hashicorp/terraform-ls/internal/filesystem"
"github.com/hashicorp/terraform-ls/internal/langserver/session"
Expand Down Expand Up @@ -161,9 +162,15 @@ func NewTestFeatures(eventBus *eventbus.EventBus, s *state.StateStore, fs *files
return nil, err
}

stacksFeature, err := fstacks.NewStacksFeature(eventBus, s, fs)
if err != nil {
return nil, err
}

return &Features{
Modules: modulesFeature,
RootModules: rootModulesFeature,
Variables: variablesFeature,
Stacks: stacksFeature,
}, nil
}

0 comments on commit 9a93f4d

Please sign in to comment.