Skip to content

Commit

Permalink
Clean up promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Nov 30, 2022
1 parent ba46a47 commit 097d0c0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
};
14 changes: 11 additions & 3 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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
) => {
Expand Down
53 changes: 29 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
3 changes: 2 additions & 1 deletion src/test/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ async function main() {
}
}

main();
// eslint-disable-next-line no-console
main().catch((err) => console.error(err));
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"include": [
"src/**/*.ts",
"./node_modules/vscode/vscode.d.ts",
"./node_modules/vscode/lib/*"
"./node_modules/vscode/lib/*",
".eslintrc.js"
]
}

0 comments on commit 097d0c0

Please sign in to comment.