diff --git a/CHANGELOG.md b/CHANGELOG.md index df7faf6..2872891 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # C/C++ Runner Change Log +## Version 3.2.2: March 6, 2022 + +- **Internal**: Removed task provider +- **Regression**: Fixed CMD arguments bug with whitespaces + ## Version 3.2.1: March 5, 2022 - **Regression**: Fixed problem with whitespaces in workspace dir diff --git a/README.md b/README.md index bbe31e1..24833f7 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ These arguments will be stored in the launch.json config for debugging the binar If you now run or debug your program these values will be fed into **argc**/**argv**. The stored arguments will be reset after selecting a new active folder. -Note: Do not use ' or " for any arguments. +Note: For strings with whitespaces please use \"\". ### Include & Exclude Folders for Selection diff --git a/media/arguments.png b/media/arguments.png index 1735020..fe1633a 100644 Binary files a/media/arguments.png and b/media/arguments.png differ diff --git a/media/argumentsDebug.png b/media/argumentsDebug.png index 3df7887..8e3ff6a 100644 Binary files a/media/argumentsDebug.png and b/media/argumentsDebug.png differ diff --git a/package.json b/package.json index 4d320f4..5389160 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "c-cpp-runner", "displayName": "C/C++ Runner", "description": "🚀 Compile, run and debug single or multiple C/C++ files with ease. 🚀", - "version": "3.2.1", + "version": "3.2.2", "publisher": "franneck94", "license": "MIT", "icon": "icon.png", diff --git a/src/executor/debugger.ts b/src/executor/debugger.ts index 2bdcdee..0967bc8 100644 --- a/src/executor/debugger.ts +++ b/src/executor/debugger.ts @@ -8,13 +8,10 @@ import { getLaunchConfigIndex } from '../utils/vscodeUtils'; const CONFIG_NAME = 'C/C++ Runner: Debug Session'; export async function runDebugger( - activeFolder: string | undefined, - workspaceFolder: string | undefined, + activeFolder: string, + workspaceFolder: string, buildMode: Builds, ) { - if (!activeFolder) return; - if (!workspaceFolder) return; - const uriWorkspaceFolder = vscode.Uri.file(workspaceFolder); const folder = vscode.workspace.getWorkspaceFolder(uriWorkspaceFolder); const launchPath = path.join(workspaceFolder, '.vscode', 'launch.json'); diff --git a/src/extension.ts b/src/extension.ts index 8a214a1..eb5ccae 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -18,7 +18,6 @@ import { import { LaunchProvider } from './provider/launchProvider'; import { PropertiesProvider } from './provider/propertiesProvider'; import { SettingsProvider } from './provider/settingsProvider'; -import { TaskProvider } from './provider/taskProvider'; import { foldersInDir, mkdirRecursive, pathExists } from './utils/fileUtils'; import * as logger from './utils/logger'; import { Builds } from './utils/types'; @@ -34,7 +33,6 @@ import { } from './utils/vscodeUtils'; let folderContextMenuDisposable: vscode.Disposable | undefined; -let taskProviderDisposable: Readonly; let commandHandlerDisposable: vscode.Disposable | undefined; let commandToggleStateDisposable: vscode.Disposable | undefined; let commandFolderDisposable: vscode.Disposable | undefined; @@ -55,7 +53,6 @@ let eventDeleteFilesDisposable: vscode.Disposable | undefined; let settingsProvider: SettingsProvider | undefined; let launchProvider: LaunchProvider | undefined; let propertiesProvider: PropertiesProvider | undefined; -let taskProvider: TaskProvider | undefined; let folderStatusBar: vscode.StatusBarItem | undefined; let modeStatusBar: vscode.StatusBarItem | undefined; @@ -140,7 +137,6 @@ export function deactivate() { disposeItem(runStatusBar); disposeItem(debugStatusBar); disposeItem(cleanStatusBar); - disposeItem(taskProviderDisposable); disposeItem(folderContextMenuDisposable); disposeItem(commandHandlerDisposable); disposeItem(commandToggleStateDisposable); @@ -182,31 +178,15 @@ function initWorkspaceProvider() { activeFolder, ); } - - if (!taskProvider) { - taskProvider = new TaskProvider(workspaceFolder, activeFolder, buildMode); - } } function initWorkspaceDisposables() { - initTaskProviderDisposable(); initArgumentParser(); initContextMenuDisposable(); initReset(); initToggleDisposable(); } -function initTaskProviderDisposable() { - if (!taskProvider || taskProviderDisposable) return; - - taskProviderDisposable = vscode.tasks.registerTaskProvider( - EXTENSION_NAME, - taskProvider, - ); - - extensionContext?.subscriptions.push(taskProviderDisposable); -} - function initToggleDisposable() { if (commandToggleStateDisposable) return; @@ -290,7 +270,6 @@ function initConfigurationChangeDisposable() { settingsProvider?.updateFileContent(); propertiesProvider?.updateFileContent(); launchProvider?.updateFileContent(); - taskProvider?.getTasks(); } }, ); @@ -344,11 +323,21 @@ function initFileDeleteDisposable() { if (workspaceFolder && oldName === workspaceFolder) { workspaceFolder = undefined; updateFolderData(); - updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems); + updateFolderStatus( + folderStatusBar, + workspaceFolder, + activeFolder, + showStatusBarItems, + ); } else if (activeFolder && oldName === activeFolder) { activeFolder = undefined; updateFolderData(); - updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems); + updateFolderStatus( + folderStatusBar, + workspaceFolder, + activeFolder, + showStatusBarItems, + ); } }); }, @@ -380,11 +369,6 @@ function updateFolderData() { initWorkspaceDisposables(); argumentsString = ''; - if (taskProvider) { - taskProvider.updateFolderData(workspaceFolder, activeFolder); - taskProvider.updateModeData(buildMode); - } - if (workspaceFolder && activeFolder) { if (settingsProvider) { settingsProvider.updateFolderData(workspaceFolder); @@ -404,7 +388,12 @@ function updateFolderData() { } if (folderStatusBar) { - updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems); + updateFolderStatus( + folderStatusBar, + workspaceFolder, + activeFolder, + showStatusBarItems, + ); } if (modeStatusBar) { updateModeStatus( @@ -446,10 +435,20 @@ function initFolderStatusBar() { activeFolder = workspaceFolderFs; updateFolderData(); } else { - updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems); + updateFolderStatus( + folderStatusBar, + workspaceFolder, + activeFolder, + showStatusBarItems, + ); } } else { - updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems); + updateFolderStatus( + folderStatusBar, + workspaceFolder, + activeFolder, + showStatusBarItems, + ); } } @@ -489,9 +488,7 @@ function initModeStatusBar() { const pickedMode = await modeHandler(); if (pickedMode) { buildMode = pickedMode; - if (taskProvider) { - taskProvider.updateModeData(buildMode); - } + updateModeStatus( modeStatusBar, showStatusBarItems, @@ -499,9 +496,6 @@ function initModeStatusBar() { buildMode, ); - if (!taskProvider) return; - taskProvider.updateModeData(buildMode); - if (!launchProvider) return; launchProvider.updateModeData(buildMode); launchProvider.updateFileContent(); @@ -543,7 +537,6 @@ function initReset() { async () => { settingsProvider?.reset(); propertiesProvider?.updateFileContent(); - taskProvider?.getTasks(); launchProvider?.updateFileContent(); }, ); @@ -723,5 +716,8 @@ async function cleanTaskCallback() { } function debugTaskCallback() { + if (!activeFolder) return; + if (!workspaceFolder) return; + runDebugger(activeFolder, workspaceFolder, buildMode); } diff --git a/src/items/statusBarItems.ts b/src/items/statusBarItems.ts index b6029de..89ede2b 100644 --- a/src/items/statusBarItems.ts +++ b/src/items/statusBarItems.ts @@ -1,28 +1,20 @@ import * as path from 'path'; import * as vscode from 'vscode'; -import { TaskProvider } from '../provider/taskProvider'; import { replaceBackslashes } from '../utils/fileUtils'; import { Builds } from '../utils/types'; export function updateFolderStatus( status: vscode.StatusBarItem | undefined, - taskProvider: TaskProvider | undefined, + workspaceFolder: string | undefined, + activeFolder: string | undefined, showStatusBarItems: boolean, ) { if (!status) return; - if ( - taskProvider && - taskProvider.workspaceFolder && - taskProvider.activeFolder - ) { - const workspaceFolder = taskProvider.workspaceFolder; + if (workspaceFolder && activeFolder) { const workspaceName = path.basename(workspaceFolder); - let text = taskProvider.activeFolder.replace( - workspaceFolder, - workspaceName, - ); + let text = activeFolder.replace(workspaceFolder, workspaceName); text = replaceBackslashes(text); const dirs = text.split('/'); diff --git a/src/provider/launchProvider.ts b/src/provider/launchProvider.ts index 8784817..d178c85 100644 --- a/src/provider/launchProvider.ts +++ b/src/provider/launchProvider.ts @@ -23,7 +23,7 @@ const CONFIG_NAME = 'C/C++ Runner: Debug Session'; export class LaunchProvider extends FileProvider { public buildMode: Builds = Builds.debug; - public argumentsString: string | undefined; + public argumentsString: string[] | undefined; constructor( protected settings: SettingsProvider, @@ -126,7 +126,19 @@ export class LaunchProvider extends FileProvider { public updateArgumentsData(argumentsString: string | undefined) { if (argumentsString !== undefined) { - this.argumentsString = argumentsString; + if (argumentsString.includes(' ')) { + if (!argumentsString.includes('"')) { + this.argumentsString = argumentsString.split(' '); + } else { + this.argumentsString = argumentsString.split('" '); + } + + this.argumentsString = this.argumentsString.map((arg: string) => + arg.replace('"', ''), + ); + } else { + this.argumentsString = [argumentsString]; + } } } @@ -167,7 +179,7 @@ export class LaunchProvider extends FileProvider { launchTemplate.configurations[0].externalConsole = true; if (this.argumentsString) { - launchTemplate.configurations[0].args = [this.argumentsString]; + launchTemplate.configurations[0].args = this.argumentsString; } else { launchTemplate.configurations[0].args = ['']; } @@ -223,7 +235,7 @@ export class LaunchProvider extends FileProvider { } if (this.argumentsString) { - launchTemplate.configurations[0].args = [this.argumentsString]; + launchTemplate.configurations[0].args = this.argumentsString; } else { launchTemplate.configurations[0].args = ['']; } diff --git a/src/provider/taskProvider.ts b/src/provider/taskProvider.ts deleted file mode 100644 index f78434a..0000000 --- a/src/provider/taskProvider.ts +++ /dev/null @@ -1,154 +0,0 @@ -import * as path from 'path'; -import * as vscode from 'vscode'; - -import { - readJsonFile, - replaceBackslashes, - writeJsonFile, -} from '../utils/fileUtils'; -import { Builds, JsonConfiguration, Task } from '../utils/types'; -import { getLaunchConfigIndex } from '../utils/vscodeUtils'; - -const EXTENSION_NAME = 'C_Cpp_Runner'; -const CONFIG_NAME = 'C/C++ Runner: Debug Session'; - -export class TaskProvider implements vscode.TaskProvider { - public tasks: vscode.Task[] | undefined; - - constructor( - private _workspaceFolder: string | undefined, - private _activeFolder: string | undefined, - private _buildMode: Builds, - ) { - this.getTasks(); - } - - public async resolveTask(task: Task) { - return task; - } - - public provideTasks() { - return this.getTasks(); - } - - public getTasks() { - if (!this.activeFolder) return []; - - this.setTasksDefinition(); - - if (!this.tasks) return []; - - return this.tasks; - } - - private setTasksDefinition() { - this.addDebugTask(); - - return this.tasks; - } - - public updateModeData(buildMode: Builds) { - this.buildMode = buildMode; - } - - public updateFolderData( - workspaceFolder: string | undefined, - activeFolder: string | undefined, - ) { - this.resetArguments(); - - this.workspaceFolder = workspaceFolder; - this.activeFolder = activeFolder; - } - - private resetArguments() { - if (this.workspaceFolder) { - const launchPath = path.join( - this.workspaceFolder, - '.vscode', - 'launch.json', - ); - - const configJson: JsonConfiguration | undefined = readJsonFile( - launchPath, - ); - - if (configJson) { - const configIdx = getLaunchConfigIndex(configJson, CONFIG_NAME); - - if (configIdx === undefined) return; - - configJson.configurations[configIdx].args = []; - writeJsonFile(launchPath, configJson); - } - } - } - - public getProjectFolder() { - if (this.activeFolder) { - return this.activeFolder; - } - - if (this.workspaceFolder) { - return this.workspaceFolder; - } - - return undefined; - } - - private addDebugTask() { - if (!this.tasks) return; - if (!this.workspaceFolder || !this.activeFolder) return; - - const folder = this.activeFolder.replace( - this.workspaceFolder, - path.basename(this.workspaceFolder), - ); - let label = `Debug: ${this.activeFolder}`; - const splitted = label.split(': '); - if (!splitted[1]) return; - label = label.replace(splitted[1], folder); - label = replaceBackslashes(label); - const definition = { - type: 'shell', - task: label, - }; - const problemMatcher = '$gcc'; - const scope = vscode.TaskScope.Workspace; - - const task = new Task( - definition, - scope, - label, - EXTENSION_NAME, - undefined, - problemMatcher, - ); - - this.tasks.push(task); - } - - public get buildMode() { - return this._buildMode; - } - - public set buildMode(value: Builds) { - this._buildMode = value; - } - - public get activeFolder() { - return this._activeFolder; - } - - public set activeFolder(value: string | undefined) { - this._activeFolder = value; - } - - public get workspaceFolder() { - return this._workspaceFolder; - } - - public set workspaceFolder(value: string | undefined) { - this._workspaceFolder = value; - } -} diff --git a/templates/tasks_template.json b/templates/tasks_template.json deleted file mode 100644 index caac568..0000000 --- a/templates/tasks_template.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Build: Folder", - "type": "shell", - "command": [], - "args": [] - }, - { - "label": "Run: Program", - "type": "shell", - "command": [], - "args": [], - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": ["$gcc"] - }, - { - "label": "Clean: Objects", - "type": "shell", - "command": [], - "args": [], - "group": { - "kind": "build", - "isDefault": true - }, - "problemMatcher": ["$gcc"] - } - ] -} diff --git a/test/integrationTest/testAssets/testExclude/nested/main.c b/test/integrationTest/testAssets/testExclude/nested/main.c index a10fb63..f0aeeaa 100644 --- a/test/integrationTest/testAssets/testExclude/nested/main.c +++ b/test/integrationTest/testAssets/testExclude/nested/main.c @@ -3,9 +3,9 @@ int main() { #ifndef NDEBUG - printf("Debug Mode"); + printf("Debug Mode - Nested 1"); #else - printf("Release Mode"); + printf("Release Mode - Nested 1"); #endif return 0; diff --git a/test/integrationTest/testAssets/testExclude/nested/nested2/main.c b/test/integrationTest/testAssets/testExclude/nested/nested2/main.c index a10fb63..1bdbe54 100644 --- a/test/integrationTest/testAssets/testExclude/nested/nested2/main.c +++ b/test/integrationTest/testAssets/testExclude/nested/nested2/main.c @@ -3,9 +3,9 @@ int main() { #ifndef NDEBUG - printf("Debug Mode"); + printf("Debug Mode - Nested 2"); #else - printf("Release Mode"); + printf("Release Mode - Nested 2"); #endif return 0;