@@ -7,7 +7,7 @@ import vscode = require('vscode');
7
7
import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration' ;
8
8
import goEnv = require( '../../src/goEnv' ) ;
9
9
import { updateGoVarsFromConfig } from '../../src/goInstallTools' ;
10
- import { getCurrentGoPath , rmdirRecursive } from '../../src/util' ;
10
+ import { getGoConfig , rmdirRecursive } from '../../src/util' ;
11
11
12
12
suite ( 'Debug Environment Variable Merge Test' , ( ) => {
13
13
const debugConfigProvider = new GoDebugConfigurationProvider ( ) ;
@@ -134,3 +134,148 @@ suite('Debug Environment Variable Merge Test', () => {
134
134
} ) ;
135
135
} ) ;
136
136
} ) ;
137
+
138
+ suite ( 'Debug Configuration Merge User Settings' , ( ) => {
139
+ const debugConfigProvider = new GoDebugConfigurationProvider ( ) ;
140
+ const utils = require ( '../../src/util' ) ;
141
+
142
+ teardown ( ( ) => sinon . restore ( ) ) ;
143
+
144
+ suite ( `merge 'go' config from settings.json` , ( ) => {
145
+ test ( 'go flags config does not affect debug config' , ( ) => {
146
+ // This tests that the testFlags and GOOS and GOARCH set
147
+ // in settings.json do not affect the resolved debug configuration.
148
+ // When this expected behavior changes, this test can be updated.
149
+
150
+ // Run resolveDebugConfiguration with the default workspace settings.
151
+ const cfg1 = {
152
+ name : 'Launch' ,
153
+ type : 'go' ,
154
+ request : 'launch' ,
155
+ mode : 'auto' ,
156
+ program : '${fileDirname}' ,
157
+ } ;
158
+
159
+ const emptyResult = debugConfigProvider . resolveDebugConfiguration ( undefined , cfg1 ) ;
160
+ const goConfig = Object . create ( getGoConfig ( ) , {
161
+ testFlags : { value : '-tags=myTagTest' } ,
162
+ buildFlags : { value : '-tags=myTagBuild' } ,
163
+ goroot : { value : '/path/to/goroot' } ,
164
+ gopath : { value : '/path/to/gopath' }
165
+ } ) as vscode . WorkspaceConfiguration ;
166
+
167
+ // Adjust the workspace config.
168
+ sinon . stub ( utils , 'getGoConfig' ) . returns ( goConfig ) ;
169
+
170
+ const cfg2 = {
171
+ name : 'Launch' ,
172
+ type : 'go' ,
173
+ request : 'launch' ,
174
+ mode : 'auto' ,
175
+ program : '${fileDirname}' ,
176
+ } ;
177
+
178
+ const filledResult = debugConfigProvider . resolveDebugConfiguration ( undefined , cfg2 ) ;
179
+
180
+ assert . strictEqual ( filledResult . name , emptyResult . name ) ;
181
+ assert . strictEqual ( filledResult . type , emptyResult . type ) ;
182
+ assert . strictEqual ( filledResult . mode , emptyResult . mode ) ;
183
+ assert . strictEqual ( filledResult . request , emptyResult . request ) ;
184
+ assert . strictEqual ( filledResult . program , emptyResult . program ) ;
185
+ assert . strictEqual ( filledResult . dlvToolPath , emptyResult . dlvToolPath ) ;
186
+ assert . strictEqual ( filledResult . apiVersion , emptyResult . apiVersion ) ;
187
+ assert . strictEqual ( filledResult . showGlobalVariables , emptyResult . showGlobalVariables ) ;
188
+ } ) ;
189
+
190
+ test ( 'delve config in settings.json is added to debug config' , ( ) => {
191
+ // This tests that the testFlags and GOOS and GOARCH set
192
+ // in settings.json do not affect the resolved debug configuration.
193
+ // When this expected behavior changes, this test can be updated.
194
+
195
+ // Run resolveDebugConfiguration with the default workspace settings.
196
+ const goConfig = Object . create ( getGoConfig ( ) , {
197
+ delveConfig : { value : {
198
+ dlvLoadConfig : {
199
+ followPointers : false ,
200
+ maxVariableRecurse : 3 ,
201
+ maxStringLen : 32 ,
202
+ maxArrayValues : 32 ,
203
+ maxStructFields : 5
204
+ } ,
205
+ apiVersion : 1 ,
206
+ showGlobalVariables : true
207
+ }
208
+ }
209
+ } ) as vscode . WorkspaceConfiguration ;
210
+ sinon . stub ( utils , 'getGoConfig' ) . returns ( goConfig ) ;
211
+
212
+ const cfg = {
213
+ name : 'Launch' ,
214
+ type : 'go' ,
215
+ request : 'launch' ,
216
+ mode : 'auto' ,
217
+ program : '${fileDirname}' ,
218
+ } ;
219
+
220
+ const result = debugConfigProvider . resolveDebugConfiguration ( undefined , cfg ) ;
221
+ assert . strictEqual ( result . apiVersion , 1 ) ;
222
+ assert . strictEqual ( result . showGlobalVariables , true ) ;
223
+ const dlvLoadConfig = result . dlvLoadConfig ;
224
+ assert . strictEqual ( dlvLoadConfig . followPointers , false ) ;
225
+ assert . strictEqual ( dlvLoadConfig . maxVariableRecurse , 3 ) ;
226
+ assert . strictEqual ( dlvLoadConfig . maxStringLen , 32 ) ;
227
+ assert . strictEqual ( dlvLoadConfig . maxArrayValues , 32 ) ;
228
+ assert . strictEqual ( dlvLoadConfig . maxStructFields , 5 ) ;
229
+ } ) ;
230
+
231
+ test ( 'delve config in settings.json is overriden by launch.json' , ( ) => {
232
+ // This tests that the testFlags and GOOS and GOARCH set
233
+ // in settings.json do not affect the resolved debug configuration.
234
+ // When this expected behavior changes, this test can be updated.
235
+
236
+ // Run resolveDebugConfiguration with the default workspace settings.
237
+ const goConfig = Object . create ( getGoConfig ( ) , {
238
+ delveConfig : { value : {
239
+ dlvLoadConfig : {
240
+ followPointers : false ,
241
+ maxVariableRecurse : 3 ,
242
+ maxStringLen : 32 ,
243
+ maxArrayValues : 32 ,
244
+ maxStructFields : 5
245
+ } ,
246
+ apiVersion : 1 ,
247
+ showGlobalVariables : true
248
+ }
249
+ }
250
+ } ) as vscode . WorkspaceConfiguration ;
251
+ sinon . stub ( utils , 'getGoConfig' ) . returns ( goConfig ) ;
252
+
253
+ const cfg = {
254
+ name : 'Launch' ,
255
+ type : 'go' ,
256
+ request : 'launch' ,
257
+ mode : 'auto' ,
258
+ program : '${fileDirname}' ,
259
+ apiVersion : 2 ,
260
+ showGlobalVariables : false ,
261
+ dlvLoadConfig : {
262
+ followPointers : true ,
263
+ maxVariableRecurse : 6 ,
264
+ maxStringLen : 128 ,
265
+ maxArrayValues : 128 ,
266
+ maxStructFields : - 1
267
+ } ,
268
+ } ;
269
+
270
+ const result = debugConfigProvider . resolveDebugConfiguration ( undefined , cfg ) ;
271
+ assert . strictEqual ( result . apiVersion , 2 ) ;
272
+ assert . strictEqual ( result . showGlobalVariables , false ) ;
273
+ const dlvLoadConfig = result . dlvLoadConfig ;
274
+ assert . strictEqual ( dlvLoadConfig . followPointers , true ) ;
275
+ assert . strictEqual ( dlvLoadConfig . maxVariableRecurse , 6 ) ;
276
+ assert . strictEqual ( dlvLoadConfig . maxStringLen , 128 ) ;
277
+ assert . strictEqual ( dlvLoadConfig . maxArrayValues , 128 ) ;
278
+ assert . strictEqual ( dlvLoadConfig . maxStructFields , - 1 ) ;
279
+ } ) ;
280
+ } ) ;
281
+ } ) ;
0 commit comments