From f20df5eb1f4cbde4dff601a3cd95d53e403d0393 Mon Sep 17 00:00:00 2001 From: uctakeoff Date: Sun, 16 Jan 2022 01:22:59 +0900 Subject: [PATCH] fix: #62 --- package.json | 2 +- src/extension.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 52f818d..675f6da 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-counter", "displayName": "VS Code Counter", "description": "Count lines of code in many programming languages.", - "version": "3.0.0", + "version": "3.0.2", "publisher": "uctakeoff", "author": { "name": "Ushiyama Kentaro" diff --git a/src/extension.ts b/src/extension.ts index b61f260..5c93b39 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -26,7 +26,7 @@ const toStringWithCommas = (obj: any) => { const sleep = (msec: number) => new Promise(resolve => setTimeout(resolve, msec)); const log = (message: string, ...items: any[]) => console.log(`${new Date().toISOString()} ${message}`, ...items); const showError = (message: string, ...items: any[]) => vscode.window.showErrorMessage(`[${EXTENSION_NAME}] ${message}`, ...items); -const registerCommand = (command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable => { +const registerCommand = (command: string, callback: (...args: any[]) => Promise, thisArg?: any): vscode.Disposable => { return vscode.commands.registerCommand(`extension.vscode-counter.${command}`, async (...args) => { try { await callback(...args); @@ -46,7 +46,7 @@ export const activate = (context: vscode.ExtensionContext) => { codeCountController, registerCommand('countInWorkspace', () => codeCountController.countLinesInWorkSpace()), registerCommand('countInDirectory', (targetDir: vscode.Uri | undefined) => codeCountController.countLinesInDirectory(targetDir)), - registerCommand('countInFile', () => codeCountController.toggleVisible()), + registerCommand('countInFile', async () => codeCountController.toggleVisible()), registerCommand('saveLanguageConfigurations', () => codeCountController.saveLanguageConfigurations()), registerCommand('outputAvailableLanguages', () => codeCountController.outputAvailableLanguages()) ); @@ -186,7 +186,7 @@ class CodeCounterController { public async countLinesInDirectory(targetDir: vscode.Uri | undefined) { const folder = await currentWorkspaceFolder(); if (targetDir) { - this.countLinesInDirectory_(targetDir, folder.uri); + await this.countLinesInDirectory_(targetDir, folder.uri); } else { const option = { value: folder.uri.toString(true), @@ -195,13 +195,13 @@ class CodeCounterController { }; const uri = await vscode.window.showInputBox(option); if (uri) { - this.countLinesInDirectory_(vscode.Uri.parse(uri), folder.uri); + await this.countLinesInDirectory_(vscode.Uri.parse(uri), folder.uri); } } } public async countLinesInWorkSpace() { const folder = await currentWorkspaceFolder(); - this.countLinesInDirectory_(folder.uri, folder.uri); + await this.countLinesInDirectory_(folder.uri, folder.uri); } private async countLinesInDirectory_(targetUri: vscode.Uri, workspaceDir: vscode.Uri) { const date = new Date(); @@ -227,7 +227,8 @@ class CodeCounterController { throw Error(`There was no target file.`); } statusBar.text = `VSCodeCounter: Totaling...`; - + + await makeDirectories(outputDir); const regex = /^\d\d\d\d-\d\d-\d\d\_\d\d-\d\d-\d\d$/; const histories = (await vscode.workspace.fs.readDirectory(outputDir)) .filter(d => ((d[1] & vscode.FileType.Directory) != 0) && regex.test(d[0]))