From 2d038703bd997c26332ecf4be5863d2dd400f523 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 28 Apr 2021 21:18:07 +0100 Subject: [PATCH] handler/formatting: Remove unused module query (#466) --- internal/langserver/handlers/command/init.go | 2 +- internal/langserver/handlers/command/validate.go | 2 +- internal/langserver/handlers/formatting.go | 12 +----------- internal/langserver/handlers/service.go | 1 - internal/terraform/module/module_ops.go | 4 ++-- internal/terraform/module/terraform_executor.go | 8 ++++---- 6 files changed, 9 insertions(+), 20 deletions(-) diff --git a/internal/langserver/handlers/command/init.go b/internal/langserver/handlers/command/init.go index dabbec4d4..f9723140c 100644 --- a/internal/langserver/handlers/command/init.go +++ b/internal/langserver/handlers/command/init.go @@ -39,7 +39,7 @@ func TerraformInitHandler(ctx context.Context, args cmd.CommandArgs) (interface{ } } - tfExec, err := module.TerraformExecutorForModule(ctx, mod) + tfExec, err := module.TerraformExecutorForModule(ctx, mod.Path) if err != nil { return nil, errors.EnrichTfExecError(err) } diff --git a/internal/langserver/handlers/command/validate.go b/internal/langserver/handlers/command/validate.go index 3781ac8bf..af2603807 100644 --- a/internal/langserver/handlers/command/validate.go +++ b/internal/langserver/handlers/command/validate.go @@ -40,7 +40,7 @@ func TerraformValidateHandler(ctx context.Context, args cmd.CommandArgs) (interf } } - tfExec, err := module.TerraformExecutorForModule(ctx, mod) + tfExec, err := module.TerraformExecutorForModule(ctx, mod.Path) if err != nil { return nil, errors.EnrichTfExecError(err) } diff --git a/internal/langserver/handlers/formatting.go b/internal/langserver/handlers/formatting.go index e449371af..6a3515c1d 100644 --- a/internal/langserver/handlers/formatting.go +++ b/internal/langserver/handlers/formatting.go @@ -19,19 +19,9 @@ func (h *logHandler) TextDocumentFormatting(ctx context.Context, params lsp.Docu return edits, err } - mf, err := lsctx.ModuleFinder(ctx) - if err != nil { - return edits, err - } - fh := ilsp.FileHandlerFromDocumentURI(params.TextDocument.URI) - mod, err := mf.ModuleByPath(fh.Dir()) - if err != nil { - return edits, err - } - - tfExec, err := module.TerraformExecutorForModule(ctx, mod) + tfExec, err := module.TerraformExecutorForModule(ctx, fh.Dir()) if err != nil { return edits, errors.EnrichTfExecError(err) } diff --git a/internal/langserver/handlers/service.go b/internal/langserver/handlers/service.go index c359634a7..4248e1607 100644 --- a/internal/langserver/handlers/service.go +++ b/internal/langserver/handlers/service.go @@ -255,7 +255,6 @@ func (svc *service) Assigner() (jrpc2.Assigner, error) { } ctx = lsctx.WithDocumentStorage(ctx, svc.fs) - ctx = lsctx.WithModuleFinder(ctx, svc.modMgr) ctx = exec.WithExecutorOpts(ctx, execOpts) ctx = exec.WithExecutorFactory(ctx, svc.tfExecFactory) diff --git a/internal/terraform/module/module_ops.go b/internal/terraform/module/module_ops.go index facf83a4a..0b2995008 100644 --- a/internal/terraform/module/module_ops.go +++ b/internal/terraform/module/module_ops.go @@ -54,7 +54,7 @@ func GetTerraformVersion(ctx context.Context, modStore *state.ModuleStore, modPa } defer modStore.SetTerraformVersionState(modPath, op.OpStateLoaded) - tfExec, err := TerraformExecutorForModule(ctx, mod) + tfExec, err := TerraformExecutorForModule(ctx, mod.Path) if err != nil { sErr := modStore.UpdateTerraformVersion(modPath, nil, nil, err) if err != nil { @@ -97,7 +97,7 @@ func ObtainSchema(ctx context.Context, modStore *state.ModuleStore, schemaStore return err } - tfExec, err := TerraformExecutorForModule(ctx, mod) + tfExec, err := TerraformExecutorForModule(ctx, mod.Path) if err != nil { sErr := modStore.FinishProviderSchemaLoading(modPath, err) if sErr != nil { diff --git a/internal/terraform/module/terraform_executor.go b/internal/terraform/module/terraform_executor.go index df7360743..2782140fe 100644 --- a/internal/terraform/module/terraform_executor.go +++ b/internal/terraform/module/terraform_executor.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/terraform-ls/internal/terraform/exec" ) -func TerraformExecutorForModule(ctx context.Context, mod Module) (exec.TerraformExecutor, error) { +func TerraformExecutorForModule(ctx context.Context, modPath string) (exec.TerraformExecutor, error) { newExecutor, ok := exec.ExecutorFactoryFromContext(ctx) if !ok { return nil, fmt.Errorf("no terraform executor provided") } - execPath, err := TerraformExecPath(ctx, mod) + execPath, err := TerraformExecPath(ctx) if err != nil { return nil, err } - tfExec, err := newExecutor(mod.Path, execPath) + tfExec, err := newExecutor(modPath, execPath) if err != nil { return nil, err } @@ -34,7 +34,7 @@ func TerraformExecutorForModule(ctx context.Context, mod Module) (exec.Terraform return tfExec, nil } -func TerraformExecPath(ctx context.Context, mod Module) (string, error) { +func TerraformExecPath(ctx context.Context) (string, error) { opts, ok := exec.ExecutorOptsFromContext(ctx) if ok && opts.ExecPath != "" { return opts.ExecPath, nil