Skip to content

Commit

Permalink
refactoring: Reference -> ReferenceTargets (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Jun 25, 2021
1 parent 4b41aaf commit 6469478
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/go-memdb v1.3.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.3.0
github.com/hashicorp/hcl-lang v0.0.0-20210625122313-29045f308402
github.com/hashicorp/hcl-lang v0.0.0-20210625140347-b5b9a34fd1c6
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/terraform-exec v0.13.3
github.com/hashicorp/terraform-json v0.12.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl-lang v0.0.0-20210616121206-bd34ebcc883b/go.mod h1:uMsq6wV8ZXEH8qndov4tncXlHDYnZ8aHsGmS4T74e2o=
github.com/hashicorp/hcl-lang v0.0.0-20210625122313-29045f308402 h1:dS/j/zM6hK7Be3BruXFFBOdmevskvTg7iCNfZHY3/ZE=
github.com/hashicorp/hcl-lang v0.0.0-20210625122313-29045f308402/go.mod h1:rDEzcPJU1AYRanWbpH9AZEik9i+jv1aoKkwqjfs7NyA=
github.com/hashicorp/hcl-lang v0.0.0-20210625140347-b5b9a34fd1c6 h1:vhjdOf16VR3QOrLOR9Il8Vjyswr6RkT6G5UuvZyWDLQ=
github.com/hashicorp/hcl-lang v0.0.0-20210625140347-b5b9a34fd1c6/go.mod h1:rDEzcPJU1AYRanWbpH9AZEik9i+jv1aoKkwqjfs7NyA=
github.com/hashicorp/hcl/v2 v2.10.0 h1:1S1UnuhDGlv3gRFV4+0EdwB+znNP5HmcGbIqwnSCByg=
github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
Expand Down
4 changes: 2 additions & 2 deletions internal/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
func DecoderForModule(ctx context.Context, mod module.Module) (*decoder.Decoder, error) {
d := decoder.NewDecoder()

d.SetReferenceReader(func() lang.References {
return mod.References
d.SetReferenceTargetReader(func() lang.ReferenceTargets {
return mod.RefTargets
})

d.SetUtmSource("terraform-ls")
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/did_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TextDocumentDidChange(ctx context.Context, params lsp.DidChangeTextDocument
if err != nil {
return err
}
err = modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeDecodeReferences)
err = modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeDecodeReferenceTargets)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/did_open.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (lh *logHandler) TextDocumentDidOpen(ctx context.Context, params lsp.DidOpe
modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeParseModuleConfiguration)
modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeParseVariables)
modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeLoadModuleMetadata)
modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeDecodeReferences)
modMgr.EnqueueModuleOpWait(mod.Path, op.OpTypeDecodeReferenceTargets)

if mod.TerraformVersionState == op.OpStateUnknown {
modMgr.EnqueueModuleOp(mod.Path, op.OpTypeGetTerraformVersion)
Expand Down
26 changes: 13 additions & 13 deletions internal/state/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ type Module struct {
ProviderSchemaErr error
ProviderSchemaState op.OpState

References lang.References
ReferencesErr error
ReferencesState op.OpState
RefTargets lang.ReferenceTargets
RefTargetsErr error
RefTargetsState op.OpState

ParsedModuleFiles map[string]*hcl.File
ParsedVarsFiles map[string]*hcl.File
Expand Down Expand Up @@ -102,9 +102,9 @@ func (m *Module) Copy() *Module {
ProviderSchemaErr: m.ProviderSchemaErr,
ProviderSchemaState: m.ProviderSchemaState,

References: m.References.Copy(),
ReferencesErr: m.ReferencesErr,
ReferencesState: m.ReferencesState,
RefTargets: m.RefTargets.Copy(),
RefTargetsErr: m.RefTargetsErr,
RefTargetsState: m.RefTargetsState,

ModuleParsingErr: m.ModuleParsingErr,
VarsParsingErr: m.VarsParsingErr,
Expand Down Expand Up @@ -163,7 +163,7 @@ func newModule(modPath string) *Module {
ModManifestState: op.OpStateUnknown,
TerraformVersionState: op.OpStateUnknown,
ProviderSchemaState: op.OpStateUnknown,
ReferencesState: op.OpStateUnknown,
RefTargetsState: op.OpStateUnknown,
ModuleParsingState: op.OpStateUnknown,
MetaState: op.OpStateUnknown,
}
Expand Down Expand Up @@ -575,7 +575,7 @@ func (s *ModuleStore) UpdateVarsDiagnostics(path string, diags map[string]hcl.Di
return nil
}

func (s *ModuleStore) SetReferencesState(path string, state op.OpState) error {
func (s *ModuleStore) SetReferenceTargetsState(path string, state op.OpState) error {
txn := s.db.Txn(true)
defer txn.Abort()

Expand All @@ -584,7 +584,7 @@ func (s *ModuleStore) SetReferencesState(path string, state op.OpState) error {
return err
}

mod.ReferencesState = state
mod.RefTargetsState = state
err = txn.Insert(s.tableName, mod)
if err != nil {
return err
Expand All @@ -594,10 +594,10 @@ func (s *ModuleStore) SetReferencesState(path string, state op.OpState) error {
return nil
}

func (s *ModuleStore) UpdateReferences(path string, refs lang.References, rErr error) error {
func (s *ModuleStore) UpdateReferenceTargets(path string, refs lang.ReferenceTargets, rErr error) error {
txn := s.db.Txn(true)
txn.Defer(func() {
s.SetReferencesState(path, op.OpStateLoaded)
s.SetReferenceTargetsState(path, op.OpStateLoaded)
})
defer txn.Abort()

Expand All @@ -606,8 +606,8 @@ func (s *ModuleStore) UpdateReferences(path string, refs lang.References, rErr e
return err
}

mod.References = refs
mod.ReferencesErr = rErr
mod.RefTargets = refs
mod.RefTargetsErr = rErr

err = txn.Insert(s.tableName, mod)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/terraform/module/builtin_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

var builtinScopeId = lang.ScopeId("builtin")

func builtinReferences(modPath string) lang.References {
return lang.References{
func builtinReferences(modPath string) lang.ReferenceTargets {
return lang.ReferenceTargets{
{
Addr: lang.Address{
lang.RootStep{Name: "path"},
Expand Down
8 changes: 4 additions & 4 deletions internal/terraform/module/module_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ func (ml *moduleLoader) executeModuleOp(ctx context.Context, modOp ModuleOperati
ml.logger.Printf("failed to load module metadata: %s", err)
}
return
case op.OpTypeDecodeReferences:
err := DecodeReferences(ml.modStore, ml.schemaStore, modOp.ModulePath)
case op.OpTypeDecodeReferenceTargets:
err := DecodeReferenceTargets(ml.modStore, ml.schemaStore, modOp.ModulePath)
if err != nil {
ml.logger.Printf("failed to decode references: %s", err)
}
Expand Down Expand Up @@ -244,12 +244,12 @@ func (ml *moduleLoader) EnqueueModuleOp(modOp ModuleOperation) error {
return nil
}
ml.modStore.SetMetaState(modOp.ModulePath, op.OpStateQueued)
case op.OpTypeDecodeReferences:
case op.OpTypeDecodeReferenceTargets:
if mod.MetaState == op.OpStateQueued {
// avoid enqueuing duplicate operation
return nil
}
ml.modStore.SetReferencesState(modOp.ModulePath, op.OpStateQueued)
ml.modStore.SetReferenceTargetsState(modOp.ModulePath, op.OpStateQueued)
}

ml.queue.PushOp(modOp)
Expand Down
12 changes: 6 additions & 6 deletions internal/terraform/module/module_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ func LoadModuleMetadata(modStore *state.ModuleStore, modPath string) error {
return mErr
}

func DecodeReferences(modStore *state.ModuleStore, schemaReader state.SchemaReader, modPath string) error {
err := modStore.SetReferencesState(modPath, op.OpStateLoading)
func DecodeReferenceTargets(modStore *state.ModuleStore, schemaReader state.SchemaReader, modPath string) error {
err := modStore.SetReferenceTargetsState(modPath, op.OpStateLoading)
if err != nil {
return err
}
Expand All @@ -360,20 +360,20 @@ func DecodeReferences(modStore *state.ModuleStore, schemaReader state.SchemaRead

fullSchema, schemaErr := schemaForModule(mod, schemaReader)
if schemaErr != nil {
sErr := modStore.UpdateReferences(modPath, lang.References{}, schemaErr)
sErr := modStore.UpdateReferenceTargets(modPath, lang.ReferenceTargets{}, schemaErr)
if sErr != nil {
return sErr
}
return schemaErr
}
d.SetSchema(fullSchema)

refs, rErr := d.DecodeReferences()
targets, rErr := d.CollectReferenceTargets()

bRefs := builtinReferences(modPath)
refs = append(refs, bRefs...)
targets = append(targets, bRefs...)

sErr := modStore.UpdateReferences(modPath, refs, rErr)
sErr := modStore.UpdateReferenceTargets(modPath, targets, rErr)
if sErr != nil {
return sErr
}
Expand Down
6 changes: 3 additions & 3 deletions internal/terraform/module/operation/op_type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/terraform/module/operation/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ const (
OpTypeParseVariables
OpTypeParseModuleManifest
OpTypeLoadModuleMetadata
OpTypeDecodeReferences
OpTypeDecodeReferenceTargets
)

0 comments on commit 6469478

Please sign in to comment.