@@ -90,11 +90,11 @@ function exportCurrentAsHtml(context, webView) {
90
90
91
91
previewPanels . forEach ( p => {
92
92
let msgValue = p . getContextData ( ) ;
93
-
93
+ let wsfolder = vscode . workspace . workspaceFolders . length > 0 ? vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath : ""
94
94
//export report to workspace
95
95
96
96
vscode . window . showSaveDialog ( {
97
- defaultUri : vscode . Uri . file ( path . join ( vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath , "solidity-metrics.html" ) ) ,
97
+ defaultUri : vscode . Uri . file ( path . join ( wsfolder , "solidity-metrics.html" ) ) ,
98
98
saveLabel : "Export"
99
99
} ) . then ( fileUri => {
100
100
if ( ! fileUri ) {
@@ -168,14 +168,15 @@ function onActivate(context) {
168
168
169
169
let document = vscode . window . activeTextEditor . document ;
170
170
let selectedWorkspace = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
171
+ let wsPath = selectedWorkspace ? selectedWorkspace . uri . fsPath : path . dirname ( document . uri . fsPath ) ;
171
172
172
- let metrics = new SolidityMetricsContainer ( selectedWorkspace . name , {
173
- basePath : selectedWorkspace . uri . fsPath + "/" ,
173
+ let metrics = new SolidityMetricsContainer ( selectedWorkspace ? selectedWorkspace . name : vscode . workspace . name , {
174
+ basePath : wsPath + "/" ,
174
175
inputFileGlobExclusions : settings . extensionConfig ( ) . file . exclusions . glob ,
175
176
inputFileGlob : undefined ,
176
177
inputFileGlobLimit : settings . extensionConfig ( ) . file . limit ,
177
178
debug : settings . extensionConfig ( ) . debug ,
178
- repoInfo : getWsGitInfo ( selectedWorkspace . uri . fsPath )
179
+ repoInfo : getWsGitInfo ( wsPath )
179
180
} ) ;
180
181
metrics . inputFileGlob = document . fileName . replace ( metrics . basePath , "" ) ;
181
182
@@ -231,34 +232,43 @@ function onActivate(context) {
231
232
console . log ( "User canceled the long running operation" ) ;
232
233
} ) ;
233
234
234
- await vscode . workspace . findFiles ( metrics . inputFileGlob , metrics . inputFileGlobExclusions , metrics . inputFileGlobLimit )
235
- . then ( uris => {
236
- uris . forEach ( uri => {
237
- metrics . analyze ( uri . fsPath ) ;
238
- progress . report ( { increment : 1 } ) ;
239
- } ) ;
235
+ await vscode . workspace . findFiles (
236
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlob ) ,
237
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlobExclusions ) ,
238
+ metrics . inputFileGlobLimit
239
+ ) . then ( uris => {
240
+ uris . forEach ( uri => {
241
+ metrics . analyze ( uri . fsPath ) ;
242
+ progress . report ( { increment : 1 } ) ;
240
243
} ) ;
244
+ } ) ;
241
245
242
- await vscode . workspace . findFiles ( "**/truffle*.js" , metrics . inputFileGlobExclusions , metrics . inputFileGlobLimit )
243
- . then ( uris => {
244
- uris . forEach ( uri => {
245
- if ( uri . fsPath . endsWith ( ".js" ) ) {
246
- metrics . addTruffleProjectLocation ( uri . fsPath ) ;
247
- progress . report ( { increment : 1 } ) ;
248
- }
249
- } ) ;
246
+ await vscode . workspace . findFiles (
247
+ new vscode . RelativePattern ( selectedWorkspace , "**/truffle*.js" ) ,
248
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlobExclusions ) ,
249
+ metrics . inputFileGlobLimit
250
+ ) . then ( uris => {
251
+ uris . forEach ( uri => {
252
+ if ( uri . fsPath . endsWith ( ".js" ) ) {
253
+ metrics . addTruffleProjectLocation ( uri . fsPath ) ;
254
+ progress . report ( { increment : 1 } ) ;
255
+ }
250
256
} ) ;
257
+ } ) ;
251
258
252
259
// {**/node_modules,**/mock*,**/test*,**/migrations,**/Migrations.sol}
253
260
let excludeFilesGlobArray = metrics . inputFileGlobExclusions . replace ( "{" , "" ) . replace ( "}" , "" ) . split ( "," ) . map ( g => g . endsWith ( ".sol" ) ? g : g + "/**/*.sol" ) ;
254
261
255
- await vscode . workspace . findFiles ( "{" + excludeFilesGlobArray . join ( "," ) + "}" , undefined , metrics . excludeFileGlobLimit )
256
- . then ( uris => {
257
- uris . forEach ( uri => {
258
- metrics . addExcludedFile ( uri . fsPath ) ;
259
- progress . report ( { increment : 1 } ) ;
260
- } ) ;
262
+ await vscode . workspace . findFiles (
263
+ new vscode . RelativePattern ( selectedWorkspace , "{" + excludeFilesGlobArray . join ( "," ) + "}" ) ,
264
+ undefined ,
265
+ metrics . excludeFileGlobLimit
266
+ ) . then ( uris => {
267
+ uris . forEach ( uri => {
268
+ metrics . addExcludedFile ( uri . fsPath ) ;
269
+ progress . report ( { increment : 1 } ) ;
261
270
} ) ;
271
+ } ) ;
262
272
263
273
if ( ! metrics . seenFiles . length ) {
264
274
vscode . window . showWarningMessage ( "No valid solidity source files found." ) ;
@@ -272,7 +282,6 @@ function onActivate(context) {
272
282
console . log ( error ) ;
273
283
}
274
284
progress . report ( { increment : 10 } ) ;
275
- console . log ( "YO?" )
276
285
metrics . generateReportMarkdown ( ) . then ( markdown => {
277
286
progress . report ( { increment : 1 } ) ;
278
287
previewHtml ( webView ,
@@ -291,18 +300,29 @@ function onActivate(context) {
291
300
context . subscriptions . push (
292
301
vscode . commands . registerCommand ( 'solidity-metrics.contextMenu.report' , async ( clickedFileUri , selectedFiles ) => {
293
302
303
+ if ( ! clickedFileUri ) {
304
+ return ; // no file selected, skip
305
+ }
294
306
let selectedWorkspace = vscode . workspace . getWorkspaceFolder ( clickedFileUri ) ;
307
+ let wsPath = selectedWorkspace ? selectedWorkspace . uri . fsPath : fs . statSync ( clickedFileUri . fsPath ) . isDirectory ( ) ? clickedFileUri . fsPath : path . dirname ( clickedFileUri . fsPath ) ;
295
308
296
- let metrics = new SolidityMetricsContainer ( selectedWorkspace . name , {
297
- basePath : selectedWorkspace . uri . fsPath + "/" ,
309
+ let metrics = new SolidityMetricsContainer ( selectedWorkspace ? selectedWorkspace . name : vscode . workspace . name , {
310
+ basePath : wsPath + "/" ,
298
311
inputFileGlobExclusions : settings . extensionConfig ( ) . file . exclusions . glob ,
299
312
inputFileGlob : undefined ,
300
313
inputFileGlobLimit : settings . extensionConfig ( ) . file . limit ,
301
314
debug : settings . extensionConfig ( ) . debug ,
302
- repoInfo : getWsGitInfo ( selectedWorkspace . uri . fsPath )
315
+ repoInfo : getWsGitInfo ( wsPath )
303
316
} ) ;
304
- metrics . inputFileGlob = "{" + selectedFiles . map ( x => x . fsPath . endsWith ( ".sol" ) ? x . fsPath . replace ( metrics . basePath , "" ) : x . fsPath . replace ( metrics . basePath , "" ) + "/**/*.sol" ) . join ( "," ) + "}" ;
305
-
317
+ metrics . inputFileGlob = "{" + selectedFiles . map ( x => {
318
+ if ( x . fsPath . endsWith ( ".sol" ) ) {
319
+ return x . fsPath . replace ( metrics . basePath , "" ) ;
320
+ }
321
+ else if ( x . fsPath == wsPath || x . fsPath == metrics . basePath ) {
322
+ return "**/*.sol" ; //special case: workspace selected
323
+ }
324
+ return x . fsPath . replace ( metrics . basePath , "" ) + "/**/*.sol" ;
325
+ } ) . join ( "," ) + "}" ;
306
326
307
327
vscode . window . withProgress ( {
308
328
location : vscode . ProgressLocation . Notification ,
@@ -314,7 +334,10 @@ function onActivate(context) {
314
334
} ) ;
315
335
316
336
//progress.report({ increment: 0 });
317
- await vscode . workspace . findFiles ( metrics . inputFileGlob , metrics . inputFileGlobExclusions , metrics . inputFileGlobLimit )
337
+ await vscode . workspace . findFiles (
338
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlob ) ,
339
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlobExclusions ) ,
340
+ metrics . inputFileGlobLimit )
318
341
. then ( uris => {
319
342
uris . forEach ( uri => {
320
343
metrics . analyze ( uri . fsPath ) ;
@@ -325,15 +348,19 @@ function onActivate(context) {
325
348
//discover truffle projects
326
349
let truffleFileGlob = "{" + selectedFiles . map ( x => x . fsPath . endsWith ( ".sol" ) ? x . fsPath . replace ( metrics . basePath , "" ) : x . fsPath . replace ( metrics . basePath , "" ) + "/**/truffle*.js" ) . join ( "," ) + "}" ;
327
350
328
- await vscode . workspace . findFiles ( truffleFileGlob , metrics . inputFileGlobExclusions , metrics . inputFileGlobLimit )
329
- . then ( uris => {
330
- uris . forEach ( uri => {
331
- if ( uri . fsPath . endsWith ( ".js" ) ) {
332
- metrics . addTruffleProjectLocation ( uri . fsPath ) ;
333
- progress . report ( { increment : 1 } ) ;
334
- }
335
- } ) ;
351
+
352
+ await vscode . workspace . findFiles (
353
+ new vscode . RelativePattern ( selectedWorkspace , truffleFileGlob ) ,
354
+ new vscode . RelativePattern ( selectedWorkspace , metrics . inputFileGlobExclusions ) ,
355
+ metrics . inputFileGlobLimit
356
+ ) . then ( uris => {
357
+ uris . forEach ( uri => {
358
+ if ( uri . fsPath . endsWith ( ".js" ) ) {
359
+ metrics . addTruffleProjectLocation ( uri . fsPath ) ;
360
+ progress . report ( { increment : 1 } ) ;
361
+ }
336
362
} ) ;
363
+ } ) ;
337
364
//list excluded files
338
365
339
366
// {**/node_modules,**/mock*,**/test*,**/migrations,**/Migrations.sol}
@@ -350,13 +377,16 @@ function onActivate(context) {
350
377
}
351
378
}
352
379
if ( excludeFilesGlob . length ) {
353
- await vscode . workspace . findFiles ( "{" + excludeFilesGlob . join ( "," ) + "}" , undefined , metrics . excludeFileGlobLimit )
354
- . then ( uris => {
355
- uris . forEach ( uri => {
356
- metrics . addExcludedFile ( uri . fsPath ) ;
357
- progress . report ( { increment : 1 } ) ;
358
- } ) ;
380
+ await vscode . workspace . findFiles (
381
+ new vscode . RelativePattern ( selectedWorkspace , "{" + excludeFilesGlob . join ( "," ) + "}" ) ,
382
+ undefined ,
383
+ metrics . excludeFileGlobLimit
384
+ ) . then ( uris => {
385
+ uris . forEach ( uri => {
386
+ metrics . addExcludedFile ( uri . fsPath ) ;
387
+ progress . report ( { increment : 1 } ) ;
359
388
} ) ;
389
+ } ) ;
360
390
}
361
391
362
392
if ( ! metrics . seenFiles . length ) {
0 commit comments