Skip to content

Commit 1142522

Browse files
authored
Merge pull request #14 from coder/stevenmasley/add_src
chore: define types explictly
2 parents 1b28509 + aa3e9e7 commit 1142522

File tree

7 files changed

+79
-58
lines changed

7 files changed

+79
-58
lines changed

preview/apitypes/apitypes.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package apitypes
33
import (
44
"time"
55

6-
"github.com/coder/preview"
6+
"github.com/hashicorp/hcl/v2"
7+
78
"github.com/coder/preview/types"
89
)
910

@@ -33,14 +34,19 @@ const (
3334
)
3435

3536
type PreviewOutput struct {
36-
Output *preview.Output `json:"output"`
37+
Output *Output `json:"output"`
3738
Diags types.Diagnostics `json:"diags"`
3839
// ParserLogs are trivy logs that occur during parsing the
3940
// Terraform files. This is useful for debugging issues with the
4041
// invalid terraform syntax.
4142
ParserLogs []ParserLog `json:"parser_logs,omitempty"`
4243
}
4344

45+
type Output struct {
46+
Parameters []ParameterWithSource `json:"parameters"`
47+
Files map[string]*hcl.File `json:"files"`
48+
}
49+
4450
type ParserLog struct {
4551
Time time.Time `json:"time"`
4652
Level string `json:"level"`
@@ -53,3 +59,24 @@ type ParserLog struct {
5359
type NullHCLString = types.NullHCLString
5460

5561
type FriendlyDiagnostic = types.FriendlyDiagnostic
62+
63+
type ParameterWithSource struct {
64+
types.Parameter
65+
TypeRange hcl.Range `json:"type_range"`
66+
}
67+
68+
func WithSource(p []types.Parameter) []ParameterWithSource {
69+
result := make([]ParameterWithSource, 0, len(p))
70+
for _, param := range p {
71+
src := ParameterWithSource{
72+
Parameter: param,
73+
}
74+
75+
if param.Source != nil {
76+
src.TypeRange = param.Source.HCLBlock().TypeRange
77+
}
78+
79+
result = append(result, src)
80+
}
81+
return result
82+
}

preview/go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.3
44

55
require (
66
github.com/coder/guts v1.5.0
7-
github.com/coder/preview v0.0.2-0.20250528204104-320b553c3e2c
7+
github.com/coder/preview v0.0.2-0.20250604144457-c9862a17f652
88
github.com/hashicorp/hcl/v2 v2.23.0
99
github.com/spf13/afero v1.14.0
1010
)
@@ -31,7 +31,7 @@ require (
3131
github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect
3232
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3333
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
34-
github.com/coder/terraform-provider-coder/v2 v2.4.2 // indirect
34+
github.com/coder/terraform-provider-coder/v2 v2.5.3 // indirect
3535
github.com/dlclark/regexp2 v1.11.4 // indirect
3636
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd // indirect
3737
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
@@ -52,18 +52,18 @@ require (
5252
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
5353
github.com/hashicorp/errwrap v1.1.0 // indirect
5454
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
55-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
55+
github.com/hashicorp/go-cty v1.5.0 // indirect
5656
github.com/hashicorp/go-getter v1.7.8 // indirect
5757
github.com/hashicorp/go-hclog v1.6.3 // indirect
5858
github.com/hashicorp/go-multierror v1.1.1 // indirect
5959
github.com/hashicorp/go-safetemp v1.0.0 // indirect
6060
github.com/hashicorp/go-uuid v1.0.3 // indirect
6161
github.com/hashicorp/go-version v1.7.0 // indirect
6262
github.com/hashicorp/logutils v1.0.0 // indirect
63-
github.com/hashicorp/terraform-json v0.24.0 // indirect
64-
github.com/hashicorp/terraform-plugin-go v0.26.0 // indirect
63+
github.com/hashicorp/terraform-json v0.25.0 // indirect
64+
github.com/hashicorp/terraform-plugin-go v0.27.0 // indirect
6565
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
66-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1 // indirect
66+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 // indirect
6767
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 // indirect
6868
github.com/klauspost/compress v1.18.0 // indirect
6969
github.com/mattn/go-colorable v0.1.14 // indirect
@@ -109,7 +109,7 @@ require (
109109
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect
110110
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb // indirect
111111
google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect
112-
google.golang.org/grpc v1.72.0 // indirect
112+
google.golang.org/grpc v1.72.1 // indirect
113113
google.golang.org/protobuf v1.36.6 // indirect
114114
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
115115
)

preview/go.sum

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,10 @@ github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 h1:Om6kYQYDUk5wWbT0t0q
707707
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
708708
github.com/coder/guts v1.5.0 h1:a94apf7xMf5jDdg1bIHzncbRiTn3+BvBZgrFSDbUnyI=
709709
github.com/coder/guts v1.5.0/go.mod h1:0Sbv5Kp83u1Nl7MIQiV2zmacJ3o02I341bkWkjWXSUQ=
710-
github.com/coder/preview v0.0.2-0.20250528204104-320b553c3e2c h1:ShixosbLEdK6/RfFI1MTAKsYOTyhUOk7jwcJ70Yp0Wg=
711-
github.com/coder/preview v0.0.2-0.20250528204104-320b553c3e2c/go.mod h1:Ltd83BrbNN7Nj+hToa6My7xTTj8FVa2xNk5589b1DJc=
712-
github.com/coder/terraform-provider-coder/v2 v2.4.2 h1:41SJkgwgiA555kwQzGIQcNS3bCm12sVMUmBSa5zGr+A=
713-
github.com/coder/terraform-provider-coder/v2 v2.4.2/go.mod h1:2kaBpn5k9ZWtgKq5k4JbkVZG9DzEqR4mJSmpdshcO+s=
710+
github.com/coder/preview v0.0.2-0.20250604144457-c9862a17f652 h1:GukgWbsop8A3vZXXwYtjJfLOIgLygvFw8I6BF0UuvNo=
711+
github.com/coder/preview v0.0.2-0.20250604144457-c9862a17f652/go.mod h1:nXz3bBwbU8/9NYI4OISUsoLDFlEREtTozYhJq6FAE8E=
712+
github.com/coder/terraform-provider-coder/v2 v2.5.3 h1:EwqIIQKe/j8bsR4WyDJ3bD0dVdkfVqJ43TwClyGneUU=
713+
github.com/coder/terraform-provider-coder/v2 v2.5.3/go.mod h1:kqP2MW/OF5u3QBRPDt84vn1izKjncICFfv26nSb781I=
714714
github.com/coder/trivy v0.0.0-20250527170238-9416a59d7019 h1:MHkv/W7l9eRAN9gOG0qZ1TLRGWIIfNi92273vPAQ8Fs=
715715
github.com/coder/trivy v0.0.0-20250527170238-9416a59d7019/go.mod h1:eqk+w9RLBmbd/cB5XfPZFuVn77cf/A6fB7qmEVeSmXk=
716716
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
@@ -941,16 +941,16 @@ github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3m
941941
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
942942
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
943943
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
944-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
945-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs=
944+
github.com/hashicorp/go-cty v1.5.0 h1:EkQ/v+dDNUqnuVpmS5fPqyY71NXVgT5gf32+57xY8g0=
945+
github.com/hashicorp/go-cty v1.5.0/go.mod h1:lFUCG5kd8exDobgSfyj4ONE/dc822kiYMguVKdHGMLM=
946946
github.com/hashicorp/go-getter v1.7.8 h1:mshVHx1Fto0/MydBekWan5zUipGq7jO0novchgMmSiY=
947947
github.com/hashicorp/go-getter v1.7.8/go.mod h1:2c6CboOEb9jG6YvmC9xdD+tyAFsrUaJPedwXDGr0TM4=
948948
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
949949
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
950950
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
951951
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
952-
github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog=
953-
github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q=
952+
github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg=
953+
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
954954
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
955955
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
956956
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
@@ -970,16 +970,16 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI
970970
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
971971
github.com/hashicorp/terraform-exec v0.23.0 h1:MUiBM1s0CNlRFsCLJuM5wXZrzA3MnPYEsiXmzATMW/I=
972972
github.com/hashicorp/terraform-exec v0.23.0/go.mod h1:mA+qnx1R8eePycfwKkCRk3Wy65mwInvlpAeOwmA7vlY=
973-
github.com/hashicorp/terraform-json v0.24.0 h1:rUiyF+x1kYawXeRth6fKFm/MdfBS6+lW4NbeATsYz8Q=
974-
github.com/hashicorp/terraform-json v0.24.0/go.mod h1:Nfj5ubo9xbu9uiAoZVBsNOjvNKB66Oyrvtit74kC7ow=
975-
github.com/hashicorp/terraform-plugin-go v0.26.0 h1:cuIzCv4qwigug3OS7iKhpGAbZTiypAfFQmw8aE65O2M=
976-
github.com/hashicorp/terraform-plugin-go v0.26.0/go.mod h1:+CXjuLDiFgqR+GcrM5a2E2Kal5t5q2jb0E3D57tTdNY=
973+
github.com/hashicorp/terraform-json v0.25.0 h1:rmNqc/CIfcWawGiwXmRuiXJKEiJu1ntGoxseG1hLhoQ=
974+
github.com/hashicorp/terraform-json v0.25.0/go.mod h1:sMKS8fiRDX4rVlR6EJUMudg1WcanxCMoWwTLkgZP/vc=
975+
github.com/hashicorp/terraform-plugin-go v0.27.0 h1:ujykws/fWIdsi6oTUT5Or4ukvEan4aN9lY+LOxVP8EE=
976+
github.com/hashicorp/terraform-plugin-go v0.27.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o=
977977
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
978978
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
979-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1 h1:WNMsTLkZf/3ydlgsuXePa3jvZFwAJhruxTxP/c1Viuw=
980-
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1/go.mod h1:P6o64QS97plG44iFzSM6rAn6VJIC/Sy9a9IkEtl79K4=
981-
github.com/hashicorp/terraform-registry-address v0.2.4 h1:JXu/zHB2Ymg/TGVCRu10XqNa4Sh2bWcqCNyKWjnCPJA=
982-
github.com/hashicorp/terraform-registry-address v0.2.4/go.mod h1:tUNYTVyCtU4OIGXXMDp7WNcJ+0W1B4nmstVDgHMjfAU=
979+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 h1:NFPMacTrY/IdcIcnUB+7hsore1ZaRWU9cnB6jFoBnIM=
980+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0/go.mod h1:QYmYnLfsosrxjCnGY1p9c7Zj6n9thnEE+7RObeYs3fA=
981+
github.com/hashicorp/terraform-registry-address v0.2.5 h1:2GTftHqmUhVOeuu9CW3kwDkRe4pcBDq0uuK5VJngU1M=
982+
github.com/hashicorp/terraform-registry-address v0.2.5/go.mod h1:PpzXWINwB5kuVS5CA7m1+eO2f1jKb5ZDIxrOPfpnGkg=
983983
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
984984
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
985985
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
@@ -1868,8 +1868,8 @@ google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5v
18681868
google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw=
18691869
google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g=
18701870
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
1871-
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
1872-
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
1871+
google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA=
1872+
google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
18731873
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
18741874
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
18751875
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=

preview/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ func tfpreview(this js.Value, p []js.Value) (output any) {
8686
}, tf)
8787

8888
data, _ := json.Marshal(apitypes.PreviewOutput{
89-
Output: pOutput,
89+
Output: &apitypes.Output{
90+
Parameters: apitypes.WithSource(pOutput.Parameters),
91+
Files: pOutput.Files,
92+
},
9093
Diags: types.Diagnostics(diags),
9194
ParserLogs: l.entries,
9295
})

public/build/preview.wasm

39.4 KB
Binary file not shown.

src/client/Preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const Preview: FC = () => {
9696
$setError(errors);
9797

9898
if (output.diags.length === 0) {
99-
$setParameters(output.output?.Parameters ?? []);
99+
$setParameters(output.output?.parameters ?? []);
100100
}
101101
}
102102
} catch (e) {

src/gen/types.ts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Code generated by 'guts'. DO NOT EDIT.
22

3-
// From terraform/block.go
4-
export interface Block {
5-
}
6-
73
// From types/diagnostics.go
84
export interface DiagnosticExtra {
95
code: string;
@@ -42,12 +38,10 @@ export interface NullHCLString {
4238
// From apitypes/apitypes.go
4339
export type OptionType = "bool" | "list(string)" | "number" | "string";
4440

45-
// From preview/preview.go
41+
// From apitypes/apitypes.go
4642
export interface Output {
47-
ModuleOutput: Value;
48-
Parameters: Parameter[];
49-
WorkspaceTags: TagBlocks;
50-
Files: Record<string, File | null> | null;
43+
parameters: ParameterWithSource[];
44+
files: Record<string, File | null> | null;
5145
}
5246

5347
// From types/parameter.go
@@ -104,6 +98,11 @@ export interface ParameterValidation {
10498
validation_monotonic: string | null;
10599
}
106100

101+
// From apitypes/apitypes.go
102+
export interface ParameterWithSource extends Parameter {
103+
type_range: Range;
104+
}
105+
107106
// From apitypes/apitypes.go
108107
export interface ParserLog {
109108
time: string;
@@ -114,33 +113,25 @@ export interface ParserLog {
114113
err: string;
115114
}
116115

116+
// From hcl/pos.go
117+
export interface Pos {
118+
Line: number;
119+
Column: number;
120+
Byte: number;
121+
}
122+
117123
// From apitypes/apitypes.go
118124
export interface PreviewOutput {
119125
output: Output | null;
120126
diags: Diagnostics;
121127
parser_logs?: ParserLog[];
122128
}
123129

124-
// From types/tags.go
125-
export interface Tag {
126-
Key: NullHCLString;
127-
Value: NullHCLString;
128-
}
129-
130-
// From types/tags.go
131-
export interface TagBlock {
132-
Tags: Tags;
133-
Block: Block | null;
134-
}
135-
136-
// From types/tags.go
137-
export type TagBlocks = TagBlock[];
138-
139-
// From types/tags.go
140-
export type Tags = Tag[];
141-
142-
// From cty/value.go
143-
export interface Value {
130+
// From hcl/pos.go
131+
export interface Range {
132+
Filename: string;
133+
Start: Pos;
134+
End: Pos;
144135
}
145136

146137

0 commit comments

Comments
 (0)