@@ -166,3 +166,66 @@ func H(x int) any { return &x }
166
166
)
167
167
})
168
168
}
169
+
170
+ // TestCompilerOptDetails_config exercises that the "want optimization
171
+ // details" flag honors the "annotation" configuration setting.
172
+ func TestCompilerOptDetails_config (t * testing.T ) {
173
+ if runtime .GOOS == "android" {
174
+ t .Skipf ("the compiler optimization details code action doesn't work on Android" )
175
+ }
176
+
177
+ const mod = `
178
+ -- go.mod --
179
+ module mod.com
180
+ go 1.18
181
+
182
+ -- a/a.go --
183
+ package a
184
+
185
+ func F(x int) any { return &x } // escape(x escapes to heap)
186
+ func G() { defer func(){} () } // cannotInlineFunction(unhandled op DEFER)
187
+ `
188
+
189
+ for _ , escape := range []bool {true , false } {
190
+ WithOptions (
191
+ Settings {"annotations" : map [string ]any {"inline" : true , "escape" : escape }},
192
+ ).Run (t , mod , func (t * testing.T , env * Env ) {
193
+ env .OpenFile ("a/a.go" )
194
+ actions := env .CodeActionForFile ("a/a.go" , nil )
195
+
196
+ docAction , err := codeActionByKind (actions , settings .GoToggleCompilerOptDetails )
197
+ if err != nil {
198
+ t .Fatal (err )
199
+ }
200
+ params := & protocol.ExecuteCommandParams {
201
+ Command : docAction .Command .Command ,
202
+ Arguments : docAction .Command .Arguments ,
203
+ }
204
+ env .ExecuteCommand (params , nil )
205
+
206
+ env .OnceMet (
207
+ CompletedWork (server .DiagnosticWorkTitle (server .FromToggleCompilerOptDetails ), 1 , true ),
208
+ cond (escape , Diagnostics , NoDiagnostics )(
209
+ ForFile ("a/a.go" ),
210
+ AtPosition ("a/a.go" , 2 , 7 ),
211
+ WithMessage ("x escapes to heap" ),
212
+ WithSeverityTags ("optimizer details" , protocol .SeverityInformation , nil ),
213
+ ),
214
+ Diagnostics (
215
+ ForFile ("a/a.go" ),
216
+ AtPosition ("a/a.go" , 3 , 5 ),
217
+ WithMessage ("cannotInlineFunction(unhandled op DEFER)" ),
218
+ WithSeverityTags ("optimizer details" , protocol .SeverityInformation , nil ),
219
+ ),
220
+ )
221
+ })
222
+ }
223
+ }
224
+
225
+ func cond [T any ](cond bool , x , y T ) T {
226
+ if cond {
227
+ return x
228
+ } else {
229
+ return y
230
+ }
231
+ }
0 commit comments