Skip to content

Commit

Permalink
handler/formatting: Remove unused module query (hashicorp#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Apr 28, 2021
1 parent 7bac670 commit 2d03870
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion internal/langserver/handlers/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/command/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 1 addition & 11 deletions internal/langserver/handlers/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions internal/terraform/module/module_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions internal/terraform/module/terraform_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit 2d03870

Please sign in to comment.