Skip to content

Commit 74029b1

Browse files
committed
fix(runOnSave): rename setting to avoid collision warning
fix: add missing silent option to runOnSave rules
1 parent bcc4ab6 commit 74029b1

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

src/configurationType.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ type RunOnSaveRule = {
1919
/** Only when `semverRange` is specified */
2020
// noInstalledWarning?: boolean
2121
/** Kill previous command execution @default true */
22-
killPrev: boolean
22+
killPrev?: boolean
23+
/**
24+
* @default false
25+
*/
26+
silent?: boolean
2327
}
2428

2529
type PackageLinkAction =
@@ -213,10 +217,10 @@ export type Configuration = {
213217
'codeAction.resolveBranchName': boolean
214218
runOnSave: RunOnSaveRule[]
215219
/**
216-
* It won't run on after delay auto save type anyway
220+
* Wether to run `runOnSave` rules after save on focus out. I disabled after delay to not be annoying anyway
217221
* @default false
218222
*/
219-
'runOnSave.runOnAutoSave': ''
223+
runOnSaveAfterFocusOut: boolean
220224
/**
221225
* Wether to enable completions in package.json files
222226
* @default true

src/features/runOnSave.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const registerRunOnSave = () => {
1414
if (runOnSave.length === 0) return
1515
disposable = vscode.workspace.onWillSaveTextDocument(async ({ document, reason }) => {
1616
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
1818
const currentWorkspacePath = vscode.workspace.getWorkspaceFolder(document.uri)
1919
if (!currentWorkspacePath) return
2020
const packageJsonPath = runOnSave.some(({ deps }) => deps && deps.length > 0) ? await findUpPackageJson(document.uri) : undefined
@@ -35,29 +35,35 @@ export const registerRunOnSave = () => {
3535
}
3636

3737
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+
)
6167
}
6268
})
6369
}

0 commit comments

Comments
 (0)