-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vscode): move saving time code to
features/
- Loading branch information
1 parent
ec1a1ef
commit 9344e23
Showing
3 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as vscode from 'vscode'; | ||
import { config } from '../config'; | ||
|
||
export function register() { | ||
|
||
let start: number | undefined; | ||
let isSavingMultiple = false; | ||
|
||
return [ | ||
vscode.workspace.onWillSaveTextDocument((e) => { | ||
if (e.document.languageId !== 'vue') { | ||
return; | ||
} | ||
if (start !== undefined) { | ||
isSavingMultiple = true; | ||
} | ||
start = Date.now(); | ||
}), | ||
vscode.workspace.onDidSaveTextDocument(async () => { | ||
|
||
if (isSavingMultiple) { | ||
isSavingMultiple = false; | ||
start = undefined; | ||
} | ||
|
||
if (start === undefined) { | ||
return; | ||
} | ||
|
||
const time = Date.now() - start; | ||
start = undefined; | ||
|
||
if (config.codeActions.enabled && time > config.codeActions.savingTimeLimit) { | ||
const options = [ | ||
'Disable codeActions', | ||
'Increase saveTimeLimit', | ||
'What is this?', | ||
];; | ||
const result = await vscode.window.showInformationMessage( | ||
`Saving time is too long. (${time} ms > ${config.codeActions.savingTimeLimit} ms), `, | ||
...options, | ||
); | ||
if (result === options[0]) { | ||
config.update('codeActions.enabled', false); | ||
vscode.window.showInformationMessage('Code Actions is disabled. (You can enable it in .vscode/settings.json)'); | ||
} | ||
else if (result === options[1]) { | ||
vscode.commands.executeCommand('workbench.action.openSettings2', { query: 'vue.codeActions.savingTimeLimit' }); | ||
} | ||
else if (result === options[2]) { | ||
vscode.env.openExternal(vscode.Uri.parse('https://github.com/vuejs/language-tools/discussions/2740')); | ||
} | ||
} | ||
}), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters