@@ -14,7 +14,7 @@ export const registerRunOnSave = () => {
14
14
if ( runOnSave . length === 0 ) return
15
15
disposable = vscode . workspace . onWillSaveTextDocument ( async ( { document, reason } ) => {
16
16
if ( reason === vscode . TextDocumentSaveReason . AfterDelay ) return
17
- if ( ! getExtensionSetting ( 'runOnSave.runOnAutoSave ' ) && reason === vscode . TextDocumentSaveReason . FocusOut ) return
17
+ if ( ! getExtensionSetting ( 'runOnSaveAfterFocusOut ' ) && reason === vscode . TextDocumentSaveReason . FocusOut ) return
18
18
const currentWorkspacePath = vscode . workspace . getWorkspaceFolder ( document . uri )
19
19
if ( ! currentWorkspacePath ) return
20
20
const packageJsonPath = runOnSave . some ( ( { deps } ) => deps && deps . length > 0 ) ? await findUpPackageJson ( document . uri ) : undefined
@@ -35,29 +35,35 @@ export const registerRunOnSave = () => {
35
35
}
36
36
37
37
console . log ( 'running runOnSave command:' , rule . command )
38
- await vscode . window . withProgress (
39
- { location : vscode . ProgressLocation . Notification , cancellable : true , title : `Running ${ rule . command } ` } ,
40
- async ( _ , token ) => {
41
- const cwd = ( ( ) => {
42
- // eslint-disable-next-line default-case
43
- switch ( rule . cwd ?? 'file' ) {
44
- case 'file' :
45
- return dirname ( document . uri . fsPath )
46
- case 'packageJson' :
47
- return packageJsonPath ?. fsPath ?? dirname ( document . uri . fsPath )
48
- case 'workspace' :
49
- return currentWorkspacePath . uri . fsPath
50
- }
51
- } ) ( )
52
- const [ command , ...args ] = rule . command . split ( ' ' )
53
- const exec = execa ( command ! , args , { cwd } )
54
- token . onCancellationRequested ( ( ) => exec . cancel ( ) )
55
- // TODO! also output output
56
- await exec . catch ( error => {
57
- console . error ( error . message )
58
- } )
59
- } ,
60
- )
38
+ const asyncFunction = async ( token ?: vscode . CancellationToken ) => {
39
+ const cwd = ( ( ) => {
40
+ // eslint-disable-next-line default-case
41
+ switch ( rule . cwd ?? 'file' ) {
42
+ case 'file' :
43
+ return dirname ( document . uri . fsPath )
44
+ case 'packageJson' :
45
+ return packageJsonPath ?. fsPath ?? dirname ( document . uri . fsPath )
46
+ case 'workspace' :
47
+ return currentWorkspacePath . uri . fsPath
48
+ }
49
+ } ) ( )
50
+ const [ command , ...args ] = rule . command . split ( ' ' )
51
+ const exec = execa ( command ! , args , { cwd } )
52
+ if ( token ) token . onCancellationRequested ( ( ) => exec . cancel ( ) )
53
+ // TODO! also output output
54
+ await exec . catch ( error => {
55
+ console . error ( error . message )
56
+ } )
57
+ }
58
+
59
+ if ( rule . silent ) await asyncFunction ( )
60
+ else
61
+ await vscode . window . withProgress (
62
+ { location : vscode . ProgressLocation . Notification , cancellable : true , title : `Running ${ rule . command } ` } ,
63
+ async ( _ , token ) => {
64
+ await asyncFunction ( token )
65
+ } ,
66
+ )
61
67
}
62
68
} )
63
69
}
0 commit comments