@@ -17,6 +17,7 @@ type Configuration struct {
17
17
ResolvePathsWithTanka bool
18
18
JPaths []string
19
19
ExtVars map [string ]string
20
+ ExtCode map [string ]string
20
21
FormattingOptions formatter.Options
21
22
22
23
EnableEvalDiagnostics bool
@@ -82,6 +83,13 @@ func (s *Server) DidChangeConfiguration(ctx context.Context, params *protocol.Di
82
83
}
83
84
s .configuration .FormattingOptions = newFmtOpts
84
85
86
+ case "ext_code" :
87
+ newCode , err := s .parseExtCode (sv )
88
+ if err != nil {
89
+ return fmt .Errorf ("%w: ext_code parsing failed: %v" , jsonrpc2 .ErrInvalidParams , err )
90
+ }
91
+ s .configuration .ExtCode = newCode
92
+
85
93
default :
86
94
return fmt .Errorf ("%w: unsupported settings key: %q" , jsonrpc2 .ErrInvalidParams , sk )
87
95
}
@@ -133,11 +141,35 @@ func (s *Server) parseFormattingOpts(unparsed interface{}) (formatter.Options, e
133
141
return opts , nil
134
142
}
135
143
136
- func resetExtVars (vm * jsonnet.VM , vars map [string ]string ) {
144
+ func (s * Server ) parseExtCode (unparsed interface {}) (map [string ]string , error ) {
145
+ newVars , ok := unparsed .(map [string ]interface {})
146
+ if ! ok {
147
+ return nil , fmt .Errorf ("unsupported settings value for ext_code. expected json object. got: %T" , unparsed )
148
+ }
149
+
150
+ vm := s .getVM ("." )
151
+
152
+ extCode := make (map [string ]string , len (newVars ))
153
+ for varKey , varValue := range newVars {
154
+ vv , ok := varValue .(string )
155
+ if ! ok {
156
+ return nil , fmt .Errorf ("unsupported settings value for ext_code.%s. expected string. got: %T" , varKey , varValue )
157
+ }
158
+ jsonResult , _ := vm .EvaluateAnonymousSnippet ("ext-code" , vv )
159
+ extCode [varKey ] = jsonResult
160
+ }
161
+
162
+ return extCode , nil
163
+ }
164
+
165
+ func resetExtVars (vm * jsonnet.VM , vars map [string ]string , code map [string ]string ) {
137
166
vm .ExtReset ()
138
167
for vk , vv := range vars {
139
168
vm .ExtVar (vk , vv )
140
169
}
170
+ for vk , vv := range code {
171
+ vm .ExtCode (vk , vv )
172
+ }
141
173
}
142
174
143
175
func stringStyleDecodeFunc (from , to reflect.Type , unparsed interface {}) (interface {}, error ) {
0 commit comments