@@ -318,52 +318,6 @@ async function pickFolder(folders: ReadonlyArray<VWorkspaceFolder>, placeHolder:
318
318
return selected . folder ;
319
319
}
320
320
321
- function enable ( ) {
322
- const folders = Workspace . workspaceFolders ;
323
- if ( ! folders ) {
324
- Window . showWarningMessage ( 'ESLint can only be enabled if VS Code is opened on a workspace folder.' ) ;
325
- return ;
326
- }
327
- const disabledFolders = folders . filter ( folder => ! Workspace . getConfiguration ( 'eslint' , folder . uri ) . get ( 'enable' , true ) ) ;
328
- if ( disabledFolders . length === 0 ) {
329
- if ( folders . length === 1 ) {
330
- Window . showInformationMessage ( 'ESLint is already enabled in the workspace.' ) ;
331
- } else {
332
- Window . showInformationMessage ( 'ESLint is already enabled on all workspace folders.' ) ;
333
- }
334
- return ;
335
- }
336
- pickFolder ( disabledFolders , 'Select a workspace folder to enable ESLint for' ) . then ( folder => {
337
- if ( ! folder ) {
338
- return ;
339
- }
340
- Workspace . getConfiguration ( 'eslint' , folder . uri ) . update ( 'enable' , true ) ;
341
- } ) ;
342
- }
343
-
344
- function disable ( ) {
345
- const folders = Workspace . workspaceFolders ;
346
- if ( ! folders ) {
347
- Window . showErrorMessage ( 'ESLint can only be disabled if VS Code is opened on a workspace folder.' ) ;
348
- return ;
349
- }
350
- const enabledFolders = folders . filter ( folder => Workspace . getConfiguration ( 'eslint' , folder . uri ) . get ( 'enable' , true ) ) ;
351
- if ( enabledFolders . length === 0 ) {
352
- if ( folders . length === 1 ) {
353
- Window . showInformationMessage ( 'ESLint is already disabled in the workspace.' ) ;
354
- } else {
355
- Window . showInformationMessage ( 'ESLint is already disabled on all workspace folders.' ) ;
356
- }
357
- return ;
358
- }
359
- pickFolder ( enabledFolders , 'Select a workspace folder to disable ESLint for' ) . then ( folder => {
360
- if ( ! folder ) {
361
- return ;
362
- }
363
- Workspace . getConfiguration ( 'eslint' , folder . uri ) . update ( 'enable' , false ) ;
364
- } ) ;
365
- }
366
-
367
321
function createDefaultConfiguration ( ) : void {
368
322
const folders = Workspace . workspaceFolders ;
369
323
if ( ! folders ) {
@@ -495,12 +449,22 @@ function updateStatusInfo(param: StatusParams): void {
495
449
}
496
450
}
497
451
498
- function getExecutionInfo ( editor : TextEditor | undefined ) : ExecutionInfo | undefined {
452
+ function getExecutionInfo ( editor : TextEditor | undefined , strict : boolean ) : ExecutionInfo | undefined {
499
453
if ( editor === undefined ) {
500
454
return undefined ;
501
455
}
502
456
const info = resource2ResourceInfo . get ( editor . document . uri . toString ( ) ) ;
503
- return info ?. executionInfo ;
457
+ if ( info !== undefined ) {
458
+ return info . executionInfo ;
459
+ }
460
+ if ( ! strict ) {
461
+ const folder = Workspace . getWorkspaceFolder ( editor . document . uri ) ;
462
+ if ( folder !== undefined ) {
463
+ const values = workspaceFolder2ExecutionInfos . get ( folder . uri . toString ( ) ) ;
464
+ return values && values [ 0 ] ;
465
+ }
466
+ }
467
+ return undefined ;
504
468
}
505
469
506
470
function clearInfo ( info : ExecutionInfo ) : void {
@@ -587,7 +551,7 @@ async function askForLibraryConfirmation(client: LanguageClient | undefined, con
587
551
client && client . sendNotification ( DidChangeConfigurationNotification . type , { settings : { } } ) ;
588
552
}
589
553
590
- async function manageLibraryConfirmations ( client : LanguageClient | undefined , context : ExtensionContext , update : undefined | ( ( ) => void ) ) : Promise < void > {
554
+ async function resetLibraryConfirmations ( client : LanguageClient | undefined , context : ExtensionContext , update : undefined | ( ( ) => void ) ) : Promise < void > {
591
555
interface ESLintQuickPickItem extends QuickPickItem {
592
556
kind : 'all' | 'allConfirmed' | 'allRejected' | 'session' | 'alwaysAllow' ;
593
557
}
@@ -625,6 +589,10 @@ async function manageLibraryConfirmations(client: LanguageClient | undefined, co
625
589
context . globalState . update ( eslintExecutionKey , eslintExecutionState ) ;
626
590
context . globalState . update ( eslintAlwaysAllowExecutionKey , eslintAlwaysAllowExecutionState ) ;
627
591
disabledLibraries . clear ( ) ;
592
+ libraryPath2ExecutionInfo . clear ( ) ;
593
+ resource2ResourceInfo . clear ( ) ;
594
+ workspaceFolder2ExecutionInfos . clear ( ) ;
595
+ update && update ( ) ;
628
596
client && client . sendNotification ( DidChangeConfigurationNotification . type , { settings : { } } ) ;
629
597
}
630
598
@@ -663,19 +631,19 @@ export function activate(context: ExtensionContext) {
663
631
const openListener : Disposable = Workspace . onDidOpenTextDocument ( didOpenTextDocument ) ;
664
632
const configurationListener : Disposable = Workspace . onDidChangeConfiguration ( configurationChanged ) ;
665
633
666
- const notValidating = ( ) => Window . showInformationMessage ( 'ESLint is not running. By default only JavaScript files are validated. If you want to validate other file types please specify them in the \'eslint.validate \' setting.' ) ;
634
+ const notValidating = ( ) => Window . showInformationMessage ( 'ESLint is not running. By default only TypeScript and JavaScript files are validated. If you want to validate other file types please specify them in the \'eslint.probe \' setting.' ) ;
667
635
onActivateCommands = [
668
636
Commands . registerCommand ( 'eslint.executeAutofix' , notValidating ) ,
669
637
Commands . registerCommand ( 'eslint.showOutputChannel' , notValidating ) ,
670
- Commands . registerCommand ( 'eslint.manageLibraryConfirmations' , ( ) => {
671
- manageLibraryConfirmations ( undefined , context , undefined ) ;
638
+ Commands . registerCommand ( 'eslint.migrateSettings' , notValidating ) ,
639
+ Commands . registerCommand ( 'eslint.manageLibraryExecution' , notValidating ) ,
640
+ Commands . registerCommand ( 'eslint.resetLibraryExecution' , ( ) => {
641
+ resetLibraryConfirmations ( undefined , context , undefined ) ;
672
642
} )
673
643
] ;
674
644
675
645
context . subscriptions . push (
676
- Commands . registerCommand ( 'eslint.createConfig' , createDefaultConfiguration ) ,
677
- Commands . registerCommand ( 'eslint.enable' , enable ) ,
678
- Commands . registerCommand ( 'eslint.disable' , disable ) ,
646
+ Commands . registerCommand ( 'eslint.createConfig' , createDefaultConfiguration )
679
647
) ;
680
648
taskProvider = new TaskProvider ( ) ;
681
649
taskProvider . start ( ) ;
@@ -1029,7 +997,7 @@ function realActivate(context: ExtensionContext): void {
1029
997
let color : ThemeColor | undefined ;
1030
998
switch ( status ) {
1031
999
case Status . ok :
1032
- icon = eslintAlwaysAllowExecutionState ? '$(globe )' : '$(check)' ;
1000
+ icon = eslintAlwaysAllowExecutionState ? '$(check-all )' : '$(check)' ;
1033
1001
break ;
1034
1002
case Status . warn :
1035
1003
icon = '$(alert)' ;
@@ -1052,7 +1020,7 @@ function realActivate(context: ExtensionContext): void {
1052
1020
tooltip = 'ESLint execution is not approved or denied yet.\nClick to open approval dialog.' ;
1053
1021
break ;
1054
1022
default :
1055
- icon = eslintAlwaysAllowExecutionState ? '$(globe )' : '$(check)' ;
1023
+ icon = eslintAlwaysAllowExecutionState ? '$(check-all )' : '$(check)' ;
1056
1024
}
1057
1025
statusBarItem . text = icon ? `${ icon } ${ text } ` : text ;
1058
1026
statusBarItem . color = color ;
@@ -1118,11 +1086,11 @@ function realActivate(context: ExtensionContext): void {
1118
1086
provideCodeActions : ( _document , _range , context ) => {
1119
1087
for ( const diag of context . diagnostics ) {
1120
1088
if ( diag === diagnostic ) {
1121
- const result = new CodeAction ( 'ESLint: Approve execution ' , CodeActionKind . QuickFix ) ;
1089
+ const result = new CodeAction ( 'ESLint: Manage Library Execution ' , CodeActionKind . QuickFix ) ;
1122
1090
result . isPreferred = true ;
1123
1091
result . command = {
1124
- title : 'Confirm ESLint execution ' ,
1125
- command : 'eslint.confirmExecution ' ,
1092
+ title : 'Manage Library Execution ' ,
1093
+ command : 'eslint.manageLibraryExecution ' ,
1126
1094
arguments : [ info . params ]
1127
1095
} ;
1128
1096
return [ result ] ;
@@ -1167,7 +1135,7 @@ function realActivate(context: ExtensionContext): void {
1167
1135
return [ result !== undefined ? ConfirmExecutionResult . toStatus ( result ) : Status . ok , false ] ;
1168
1136
}
1169
1137
1170
- const executionInfo = getExecutionInfo ( editor ) ;
1138
+ const executionInfo = getExecutionInfo ( editor , true ) ;
1171
1139
if ( lastExecutionInfo !== executionInfo ) {
1172
1140
clearLastExecutionInfo ( ) ;
1173
1141
}
@@ -1848,7 +1816,7 @@ function realActivate(context: ExtensionContext): void {
1848
1816
} ) ;
1849
1817
} ) ,
1850
1818
Commands . registerCommand ( 'eslint.showOutputChannel' , async ( ) => {
1851
- const executionInfo = getExecutionInfo ( Window . activeTextEditor ) ;
1819
+ const executionInfo = getExecutionInfo ( Window . activeTextEditor , false ) ;
1852
1820
if ( executionInfo !== undefined && ( executionInfo . result === ConfirmExecutionResult . confirmationPending || executionInfo . result === ConfirmExecutionResult . disabled ) ) {
1853
1821
await askForLibraryConfirmation ( client , context , executionInfo . params , updateStatusBarAndDiagnostics ) ;
1854
1822
return ;
@@ -1860,7 +1828,7 @@ function realActivate(context: ExtensionContext): void {
1860
1828
}
1861
1829
1862
1830
if ( globalStatus === Status . executionDenied ) {
1863
- await manageLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1831
+ await resetLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1864
1832
return ;
1865
1833
}
1866
1834
@@ -1887,17 +1855,28 @@ function realActivate(context: ExtensionContext): void {
1887
1855
return ;
1888
1856
}
1889
1857
}
1890
- await manageLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1858
+ await resetLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1891
1859
} ) ,
1892
1860
Commands . registerCommand ( 'eslint.migrateSettings' , ( ) => {
1893
1861
migrateSettings ( ) ;
1894
1862
} ) ,
1895
- Commands . registerCommand ( 'eslint.manageLibraryConfirmations ' , ( ) => {
1896
- manageLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1863
+ Commands . registerCommand ( 'eslint.resetLibraryExecution ' , ( ) => {
1864
+ resetLibraryConfirmations ( client , context , updateStatusBarAndDiagnostics ) ;
1897
1865
} ) ,
1898
- Commands . registerCommand ( 'eslint.confirmExecution' , async ( params : ConfirmExecutionParams ) => {
1899
- disabledLibraries . delete ( params . libraryPath ) ;
1900
- await askForLibraryConfirmation ( client , context , params , updateStatusBarAndDiagnostics ) ;
1866
+ Commands . registerCommand ( 'eslint.manageLibraryExecution' , async ( params : ConfirmExecutionParams | undefined ) => {
1867
+ if ( params !== undefined ) {
1868
+ await askForLibraryConfirmation ( client , context , params , updateStatusBarAndDiagnostics ) ;
1869
+ } else {
1870
+ const info = getExecutionInfo ( Window . activeTextEditor , false ) ;
1871
+ if ( info !== undefined ) {
1872
+ await askForLibraryConfirmation ( client , context , info . params , updateStatusBarAndDiagnostics ) ;
1873
+ } else {
1874
+ Window . showInformationMessage (
1875
+ Window . activeTextEditor
1876
+ ? 'No ESLint library execution information found for the active editor.'
1877
+ : 'No ESLint library execution information found.' ) ;
1878
+ }
1879
+ }
1901
1880
} )
1902
1881
) ;
1903
1882
}
0 commit comments