-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce hooks package and register first completion hook
- Loading branch information
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Package hooks enables the implementation of hooks for dynamic | ||
// autocompletion. Hooks should be added to this package and | ||
// registered in AppendCompletionHooks in completion_hooks.go. | ||
// | ||
// A hook must have the following signature: | ||
// func (h *Hooks) Name(ctx context.Context, value cty.Value) ([]decoder.Candidate, error) | ||
// It receives the current value of the attribute and must return | ||
// a list of completion candidates. | ||
// | ||
// All hooks have access to path, filename and pos via context: | ||
// | ||
// path, ok := decoder.PathFromContext(ctx) | ||
// filename, ok := decoder.FilenameFromContext(ctx) | ||
// pos, ok := decoder.PosFromContext(ctx) | ||
package hooks | ||
|
||
import "github.com/hashicorp/terraform-ls/internal/state" | ||
|
||
type Hooks struct { | ||
ModStore *state.ModuleStore | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package hooks | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/hcl-lang/decoder" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
func (h *Hooks) LocalModuleSources(ctx context.Context, value cty.Value) ([]decoder.Candidate, error) { | ||
candidates := make([]decoder.Candidate, 0) | ||
|
||
// Obtain indexed modules via h.modStore.List() | ||
// TODO filter modules inside .terraform | ||
// TODO build candidates | ||
|
||
return candidates, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/hashicorp/hcl-lang/decoder" | ||
"github.com/hashicorp/terraform-ls/internal/hooks" | ||
) | ||
|
||
func (s *service) AppendCompletionHooks(ctx decoder.DecoderContext) { | ||
h := hooks.Hooks{ | ||
ModStore: s.modStore, | ||
} | ||
|
||
ctx.CompletionHooks["CompleteLocalModuleSources"] = h.LocalModuleSources | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters