Skip to content

Commit

Permalink
Merge pull request #65 from franneck94/3.2.2
Browse files Browse the repository at this point in the history
3.2.2
  • Loading branch information
franneck94 authored Mar 6, 2022
2 parents bf3d1be + 03aaf4a commit ae2a987
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 252 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified media/arguments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/argumentsDebug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 2 additions & 5 deletions src/executor/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
72 changes: 34 additions & 38 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,7 +33,6 @@ import {
} from './utils/vscodeUtils';

let folderContextMenuDisposable: vscode.Disposable | undefined;
let taskProviderDisposable: Readonly<vscode.Disposable | undefined>;
let commandHandlerDisposable: vscode.Disposable | undefined;
let commandToggleStateDisposable: vscode.Disposable | undefined;
let commandFolderDisposable: vscode.Disposable | undefined;
Expand All @@ -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;
Expand Down Expand Up @@ -140,7 +137,6 @@ export function deactivate() {
disposeItem(runStatusBar);
disposeItem(debugStatusBar);
disposeItem(cleanStatusBar);
disposeItem(taskProviderDisposable);
disposeItem(folderContextMenuDisposable);
disposeItem(commandHandlerDisposable);
disposeItem(commandToggleStateDisposable);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -290,7 +270,6 @@ function initConfigurationChangeDisposable() {
settingsProvider?.updateFileContent();
propertiesProvider?.updateFileContent();
launchProvider?.updateFileContent();
taskProvider?.getTasks();
}
},
);
Expand Down Expand Up @@ -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,
);
}
});
},
Expand Down Expand Up @@ -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);
Expand All @@ -404,7 +388,12 @@ function updateFolderData() {
}

if (folderStatusBar) {
updateFolderStatus(folderStatusBar, taskProvider, showStatusBarItems);
updateFolderStatus(
folderStatusBar,
workspaceFolder,
activeFolder,
showStatusBarItems,
);
}
if (modeStatusBar) {
updateModeStatus(
Expand Down Expand Up @@ -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,
);
}
}

Expand Down Expand Up @@ -489,19 +488,14 @@ function initModeStatusBar() {
const pickedMode = await modeHandler();
if (pickedMode) {
buildMode = pickedMode;
if (taskProvider) {
taskProvider.updateModeData(buildMode);
}

updateModeStatus(
modeStatusBar,
showStatusBarItems,
activeFolder,
buildMode,
);

if (!taskProvider) return;
taskProvider.updateModeData(buildMode);

if (!launchProvider) return;
launchProvider.updateModeData(buildMode);
launchProvider.updateFileContent();
Expand Down Expand Up @@ -543,7 +537,6 @@ function initReset() {
async () => {
settingsProvider?.reset();
propertiesProvider?.updateFileContent();
taskProvider?.getTasks();
launchProvider?.updateFileContent();
},
);
Expand Down Expand Up @@ -723,5 +716,8 @@ async function cleanTaskCallback() {
}

function debugTaskCallback() {
if (!activeFolder) return;
if (!workspaceFolder) return;

runDebugger(activeFolder, workspaceFolder, buildMode);
}
16 changes: 4 additions & 12 deletions src/items/statusBarItems.ts
Original file line number Diff line number Diff line change
@@ -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('/');
Expand Down
20 changes: 16 additions & 4 deletions src/provider/launchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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];
}
}
}

Expand Down Expand Up @@ -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 = [''];
}
Expand Down Expand Up @@ -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 = [''];
}
Expand Down
Loading

0 comments on commit ae2a987

Please sign in to comment.