Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Radek Simko <radek.simko@gmail.com>
  • Loading branch information
jpogran and radeksimko committed Sep 29, 2023
1 parent abc5741 commit f6fb85e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
12 changes: 6 additions & 6 deletions internal/terraform/ast/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func VarsFilesFromMap(m map[string]*hcl.File) VarsFiles {
return mf
}

func (mf VarsFiles) Copy() VarsFiles {
m := make(VarsFiles, len(mf))
for name, file := range mf {
func (vf VarsFiles) Copy() VarsFiles {
m := make(VarsFiles, len(vf))
for name, file := range vf {
m[name] = file
}
return m
Expand All @@ -70,9 +70,9 @@ func VarsDiagsFromMap(m map[string]hcl.Diagnostics) VarsDiags {
return mf
}

func (mf VarsDiags) Copy() VarsDiags {
m := make(VarsDiags, len(mf))
for name, file := range mf {
func (vd VarsDiags) Copy() VarsDiags {
m := make(VarsDiags, len(vd))
for name, file := range vd {
m[name] = file
}
return m
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 @@ -477,7 +477,7 @@ func ParseVariables(ctx context.Context, fs ReadOnlyFS, modStore *state.ModuleSt
}
fileName := filepath.Base(filePath)

f, vdiags, err := parser.ParseVariableFile(fs, filePath)
f, vDiags, err := parser.ParseVariableFile(fs, filePath)
if err != nil {
return err
}
Expand All @@ -492,7 +492,7 @@ func ParseVariables(ctx context.Context, fs ReadOnlyFS, modStore *state.ModuleSt
} else {
existingDiags = existingDiags.Copy()
}
existingDiags[ast.VarsFilename(fileName)] = vdiags
existingDiags[ast.VarsFilename(fileName)] = vDiags
diags = existingDiags
} else {
// this is the first time file is opened so parse the whole module
Expand Down
21 changes: 8 additions & 13 deletions internal/terraform/module/module_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1127,20 +1127,19 @@ func TestParseVariables(t *testing.T) {
}

// say we're coming from did_change request
fooURI, err := filepath.Abs(filepath.Join(singleFileModulePath, "example.tfvars"))
fileURI, err := filepath.Abs(filepath.Join(singleFileModulePath, "example.tfvars"))
if err != nil {
t.Fatal(err)
}
x := lsctx.RPCContextData{
rpcData := lsctx.RPCContextData{
Method: "textDocument/didChange",
URI: uri.FromPath(fooURI),
// URI: "file:///test/example.tfvars",
URI: uri.FromPath(fileURI),
}

// ignore job state
ctx = job.WithIgnoreState(ctx, true)
ctx = lsctx.WithLanguageId(ctx, ilsp.Tfvars.String())
ctx = lsctx.WithRPCContext(ctx, x)
ctx = lsctx.WithRPCContext(ctx, rpcData)
err = ParseVariables(ctx, testFs, ss.Modules, singleFileModulePath)
if err != nil {
t.Fatal(err)
Expand All @@ -1156,15 +1155,11 @@ func TestParseVariables(t *testing.T) {
t.Fatal("file should mismatch")
}

b := before.VarsDiagnostics[ast.HCLParsingSource]
ex := b[ast.VarsFilename("example.tfvars")]

a := after.VarsDiagnostics[ast.HCLParsingSource]
exA := a[ast.VarsFilename("example.tfvars")]
beforeDiags := before.VarsDiagnostics[ast.HCLParsingSource]
afterDiags := after.VarsDiagnostics[ast.HCLParsingSource]

// // diags should change for example.tfvars
if ex[0] == exA[0] {
// if before.VarsDiagnostics["example.tfvars"][0] == after.VarsDiagnostics["example.tfvars"][0] {
// diags should change for example.tfvars
if beforeDiags[ast.VarsFilename("example.tfvars")][0] == afterDiags[ast.VarsFilename("example.tfvars")][0] {
t.Fatal("diags should mismatch")
}
}
Expand Down

0 comments on commit f6fb85e

Please sign in to comment.