Skip to content

Commit

Permalink
It doesn't crash
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanck committed Apr 17, 2024
1 parent fc1458f commit c8d820d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
26 changes: 26 additions & 0 deletions internal/decoder/path_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package decoder

import (
"context"

"github.com/hashicorp/hcl-lang/decoder"
"github.com/hashicorp/hcl-lang/lang"
)

type PathReader struct {
}

var _ decoder.PathReader = &PathReader{}

func (mr *PathReader) Paths(ctx context.Context) []lang.Path {
paths := make([]lang.Path, 0)

return paths
}

func (mr *PathReader) PathContext(path lang.Path) (*decoder.PathContext, error) {
return &decoder.PathContext{}, nil
}
1 change: 1 addition & 0 deletions internal/flavors/modules/modules_flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (f *ModulesFlavor) Run(ctx context.Context) {

func (f *ModulesFlavor) DidOpen(ctx context.Context, path string, languageID string) (job.IDs, error) {
ids := make(job.IDs, 0)
f.logger.Printf("did open %q %q", path, languageID)

// Add to state if language ID matches
if languageID == "terraform" {
Expand Down
42 changes: 21 additions & 21 deletions internal/flavors/modules/state/module_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ func (s *ModuleStore) add(txn *memdb.Txn, modPath string) error {
return err
}

err = s.queueModuleChange(txn, nil, mod)
if err != nil {
return err
}
// err = s.queueModuleChange(txn, nil, mod)
// if err != nil {
// return err
// }

return nil
}
Expand All @@ -116,11 +116,11 @@ func (s *ModuleStore) Remove(modPath string) error {
return nil
}

oldMod := oldObj.(*ModuleRecord)
err = s.queueModuleChange(txn, oldMod, nil)
if err != nil {
return err
}
// oldMod := oldObj.(*ModuleRecord)
// err = s.queueModuleChange(txn, oldMod, nil)
// if err != nil {
// return err
// }

_, err = txn.DeleteAll(s.tableName, "id", modPath)
if err != nil {
Expand Down Expand Up @@ -384,10 +384,10 @@ func (s *ModuleStore) FinishProviderSchemaLoading(path string, psErr error) erro
return err
}

err = s.queueModuleChange(txn, oldMod, mod)
if err != nil {
return err
}
// err = s.queueModuleChange(txn, oldMod, mod)
// if err != nil {
// return err
// }

txn.Commit()
return nil
Expand Down Expand Up @@ -465,10 +465,10 @@ func (s *ModuleStore) UpdateMetadata(path string, meta *tfmod.Meta, mErr error)
return err
}

err = s.queueModuleChange(txn, oldMod, mod)
if err != nil {
return err
}
// err = s.queueModuleChange(txn, oldMod, mod)
// if err != nil {
// return err
// }

txn.Commit()
return nil
Expand Down Expand Up @@ -497,10 +497,10 @@ func (s *ModuleStore) UpdateModuleDiagnostics(path string, source ast.Diagnostic
return err
}

err = s.queueModuleChange(txn, oldMod, mod)
if err != nil {
return err
}
// err = s.queueModuleChange(txn, oldMod, mod)
// if err != nil {
// return err
// }

txn.Commit()
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func (svc *service) configureSessionDependencies(ctx context.Context, cfgOpts *s
svc.stateStore.JobStore, svc.tfExecFactory, svc.registryClient)
svc.indexer.SetLogger(svc.logger)

svc.decoder = decoder.NewDecoder(nil)
svc.decoder = decoder.NewDecoder(&idecoder.PathReader{})
decoderContext := idecoder.DecoderContext(ctx)
svc.AppendCompletionHooks(decoderContext)
svc.decoder.SetContext(decoderContext)
Expand Down

0 comments on commit c8d820d

Please sign in to comment.