From 097d0c007ffb0755747a36d9007db42d3c317ebe Mon Sep 17 00:00:00 2001 From: Nathan Totten Date: Wed, 30 Nov 2022 12:41:56 -0600 Subject: [PATCH] Clean up promises --- .eslintrc.js | 4 +++ src/PrettierEditService.ts | 14 +++++++--- src/extension.ts | 53 +++++++++++++++++++++----------------- src/test/runTests.ts | 3 ++- tsconfig.json | 3 ++- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index dd7b2996d..1f192dc04 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,6 +13,10 @@ module.exports = { "no-console": "error", "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/no-non-null-assertion": 0, + "@typescript-eslint/no-floating-promises": "error", }, ignorePatterns: ["test-fixtures/**"], + parserOptions: { + project: "./tsconfig.json", + }, }; diff --git a/src/PrettierEditService.ts b/src/PrettierEditService.ts index 0729303e4..250980df8 100644 --- a/src/PrettierEditService.ts +++ b/src/PrettierEditService.ts @@ -94,10 +94,10 @@ export default class PrettierEditService implements Disposable { prettierConfigWatcher.onDidDelete(this.prettierConfigChanged); const textEditorChange = window.onDidChangeActiveTextEditor( - this.handleActiveTextEditorChanged + this.handleActiveTextEditorChangedSync ); - this.handleActiveTextEditorChanged(window.activeTextEditor); + this.handleActiveTextEditorChangedSync(window.activeTextEditor); return [ packageWatcher, @@ -136,7 +136,7 @@ export default class PrettierEditService implements Disposable { private prettierConfigChanged = async (uri: Uri) => this.resetFormatters(uri); - private resetFormatters = async (uri?: Uri) => { + private resetFormatters = (uri?: Uri) => { if (uri) { const workspaceFolder = workspace.getWorkspaceFolder(uri); this.registeredWorkspaces.delete(workspaceFolder?.uri.fsPath ?? "global"); @@ -147,6 +147,14 @@ export default class PrettierEditService implements Disposable { this.statusBar.update(FormatterStatus.Ready); }; + private handleActiveTextEditorChangedSync = ( + textEditor: TextEditor | undefined + ) => { + this.handleActiveTextEditorChanged(textEditor).catch((err) => { + this.loggingService.logError("Error handling text editor change", err); + }); + }; + private handleActiveTextEditorChanged = async ( textEditor: TextEditor | undefined ) => { diff --git a/src/extension.ts b/src/extension.ts index 1bbc50e78..1c21099d9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -50,29 +50,34 @@ export function activate(context: ExtensionContext) { loggingService, statusBar ); - editService.registerGlobal(); - - const createConfigFileFunc = createConfigFile(templateService); - const createConfigFileCommand = commands.registerCommand( - "prettier.createConfigFile", - createConfigFileFunc - ); - const openOutputCommand = commands.registerCommand( - "prettier.openOutput", - () => { - loggingService.show(); - } - ); - const forceFormatDocumentCommand = commands.registerCommand( - "prettier.forceFormatDocument", - editService.forceFormatDocument - ); + editService + .registerGlobal() + .then(() => { + const createConfigFileFunc = createConfigFile(templateService); + const createConfigFileCommand = commands.registerCommand( + "prettier.createConfigFile", + createConfigFileFunc + ); + const openOutputCommand = commands.registerCommand( + "prettier.openOutput", + () => { + loggingService.show(); + } + ); + const forceFormatDocumentCommand = commands.registerCommand( + "prettier.forceFormatDocument", + editService.forceFormatDocument + ); - context.subscriptions.push( - editService, - createConfigFileCommand, - openOutputCommand, - forceFormatDocumentCommand, - ...editService.registerDisposables() - ); + context.subscriptions.push( + editService, + createConfigFileCommand, + openOutputCommand, + forceFormatDocumentCommand, + ...editService.registerDisposables() + ); + }) + .catch((err) => { + loggingService.logError("Eerror registering extension", err); + }); } diff --git a/src/test/runTests.ts b/src/test/runTests.ts index 422a83dbf..0d9e7873a 100644 --- a/src/test/runTests.ts +++ b/src/test/runTests.ts @@ -63,4 +63,5 @@ async function main() { } } -main(); +// eslint-disable-next-line no-console +main().catch((err) => console.error(err)); diff --git a/tsconfig.json b/tsconfig.json index d54ae03f5..3d2443eb2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,7 @@ "include": [ "src/**/*.ts", "./node_modules/vscode/vscode.d.ts", - "./node_modules/vscode/lib/*" + "./node_modules/vscode/lib/*", + ".eslintrc.js" ] }