From 9a93f4d4ccfca199aa2daf07b58ac6c1f51e8b7f Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 5 Jul 2024 16:04:19 +0200 Subject: [PATCH] Wire up Stacks feature to LSP handlers Co-authored-by: James Pogran --- .../handlers/did_change_watched_files_test.go | 16 ++++++++++++++++ internal/langserver/handlers/hooks_module.go | 1 + .../langserver/handlers/initialize_test.go | 2 ++ internal/langserver/handlers/service.go | 19 +++++++++++++++++-- .../langserver/handlers/session_mock_test.go | 7 +++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/internal/langserver/handlers/did_change_watched_files_test.go b/internal/langserver/handlers/did_change_watched_files_test.go index 67b910952..aa208920c 100644 --- a/internal/langserver/handlers/did_change_watched_files_test.go +++ b/internal/langserver/handlers/did_change_watched_files_test.go @@ -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() @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/internal/langserver/handlers/hooks_module.go b/internal/langserver/handlers/hooks_module.go index d5547dcf7..c616d0e78 100644 --- a/internal/langserver/handlers/hooks_module.go +++ b/internal/langserver/handlers/hooks_module.go @@ -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) } diff --git a/internal/langserver/handlers/initialize_test.go b/internal/langserver/handlers/initialize_test.go index 5b0a163fe..9173cc870 100644 --- a/internal/langserver/handlers/initialize_test.go +++ b/internal/langserver/handlers/initialize_test.go @@ -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() diff --git a/internal/langserver/handlers/service.go b/internal/langserver/handlers/service.go index 1bb0474ad..85be34c55 100644 --- a/internal/langserver/handlers/service.go +++ b/internal/langserver/handlers/service.go @@ -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" @@ -48,6 +49,7 @@ type Features struct { Modules *fmodules.ModulesFeature RootModules *frootmodules.RootModulesFeature Variables *fvariables.VariablesFeature + Stacks *stacks.StacksFeature } type service struct { @@ -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) @@ -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() + } } } diff --git a/internal/langserver/handlers/session_mock_test.go b/internal/langserver/handlers/session_mock_test.go index 538961b55..a00beaa5c 100644 --- a/internal/langserver/handlers/session_mock_test.go +++ b/internal/langserver/handlers/session_mock_test.go @@ -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" @@ -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 }