Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/mitchellh/cli v1.1.5
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.5.0
github.com/opentofu/opentofu-schema v0.0.11
github.com/opentofu/opentofu-schema v0.0.12
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a
github.com/opentofu/tofu-exec v0.0.1
github.com/opentofu/tofudl v0.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opentofu/opentofu-schema v0.0.11 h1:DiOqEyzYw4wu6DSdv6I+QQyJf0Q4oF+ar6knCfHfxxQ=
github.com/opentofu/opentofu-schema v0.0.11/go.mod h1:3G/KsYw9CRdZ3zx1JzRbg0aCgDAEGKxkv+UtHsB5bUo=
github.com/opentofu/opentofu-schema v0.0.12 h1:IzXvnDyiXYYADRTt3lpUY0sjcddmpXMgnvP6GPkU3vw=
github.com/opentofu/opentofu-schema v0.0.12/go.mod h1:3G/KsYw9CRdZ3zx1JzRbg0aCgDAEGKxkv+UtHsB5bUo=
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a h1:NyM/PPbc+kxxv2d4OKfE32C5fLtVTLceyg4YKKCYO9Y=
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a/go.mod h1:HzQhpVo/NJnGmN+7FPECCVCA5ijU7AUcvf39enBKYOc=
github.com/opentofu/tofu-exec v0.0.1 h1:QL77U8z0WA+RhfGhjnpktrcuuxnz017tDiildEILMnI=
Expand Down
125 changes: 125 additions & 0 deletions internal/langserver/handlers/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package handlers
import (
"encoding/json"
"fmt"
"github.com/zclconf/go-cty/cty"
"testing"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -265,3 +266,127 @@ func TestVarsHover_withValidData(t *testing.T) {
}
}`)
}
func TestHoverDynamic_inProvider(t *testing.T) {
tmpDir := TempDir(t)
InitPluginCache(t, tmpDir.Path())

var testSchema tfjson.ProviderSchemas
err := json.Unmarshal([]byte(testModuleSchemaOutput), &testSchema)
if err != nil {
t.Fatal(err)
}

//Adding a configuration block to the schema to test dynamic blocks
if testSchema.Schemas["test/test"].ConfigSchema.Block.NestedBlocks == nil {
testSchema.Schemas["test/test"].ConfigSchema.Block.NestedBlocks = make(map[string]*tfjson.SchemaBlockType)
}
testSchema.Schemas["test/test"].ConfigSchema.Block.NestedBlocks["simple_block"] = &tfjson.SchemaBlockType{
NestingMode: "set",
Block: &tfjson.SchemaBlock{
Attributes: map[string]*tfjson.SchemaAttribute{
"name": {
AttributeType: cty.String,
Description: "The name of the block",
},
},
},
}

ss, err := state.NewStateStore()
if err != nil {
t.Fatal(err)
}
wc := walker.NewWalkerCollector()

ls := langserver.NewLangServerMock(t, NewMockSession(&MockSessionInput{
TofuCalls: &exec.TofuMockCalls{
PerWorkDir: map[string][]*mock.Call{
tmpDir.Path(): {
{
Method: "Version",
Repeatability: 1,
Arguments: []interface{}{
mock.AnythingOfType(""),
},
ReturnArguments: []interface{}{
version.Must(version.NewVersion("1.9.0")),
nil,
nil,
},
},
{
Method: "GetExecPath",
Repeatability: 1,
ReturnArguments: []interface{}{
"",
},
},
{
Method: "ProviderSchemas",
Repeatability: 1,
Arguments: []interface{}{
mock.AnythingOfType(""),
},
ReturnArguments: []interface{}{
&testSchema,
nil,
},
},
},
},
},
StateStore: ss,
WalkerCollector: wc,
}))
stop := ls.Start(t)
defer stop()

ls.Call(t, &langserver.CallRequest{
Method: "initialize",
ReqParams: fmt.Sprintf(`{
"capabilities": {},
"rootUri": %q,
"processId": 12345
}`, tmpDir.URI)})
waitForWalkerPath(t, ss, wc, tmpDir)
ls.Notify(t, &langserver.CallRequest{
Method: "initialized",
ReqParams: "{}",
})
ls.Call(t, &langserver.CallRequest{
Method: "textDocument/didOpen",
ReqParams: fmt.Sprintf(`{
"textDocument": {
"version": 0,
"languageId": "opentofu",
"text": "provider \"test\" {\n dynamic \"test_dyn\" { \n }\n \n}\n",
"uri": "%s/main.tf"
}
}`, TempDir(t).URI)})
waitForAllJobs(t, ss)

ls.CallAndExpectResponse(t, &langserver.CallRequest{
Method: "textDocument/hover",
ReqParams: fmt.Sprintf(`{
"textDocument": {
"uri": "%s/main.tf"
},
"position": {
"character": 3,
"line": 1
}
}`, TempDir(t).URI)}, `{
"jsonrpc": "2.0",
"id": 3,
"result": {
"contents": {
"kind": "plaintext",
"value": "dynamic Block\n\nA dynamic block to produce blocks dynamically by iterating over a given complex value"
},
"range": {
"start": { "line":1, "character":1 },
"end": { "line":1, "character":8 }
}
}
}`)
}
Loading