Skip to content

Commit

Permalink
up for 9.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
franneck94 committed Dec 25, 2023
1 parent bba783c commit c3f9ceb
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- **TODO**: Upcomming feature: open the generated assembler file to the side

## Version 9.4.0: Dec 25, 2023

- **Regression**: Improved error messages when the user selected c/c++ compiler does not exits/work

## Version 9.3.0: Nov 30, 2023

- **Regression**: Some changes for default MSVC Path (internal)
Expand Down
4 changes: 2 additions & 2 deletions 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": "9.3.0",
"version": "9.4.0",
"publisher": "franneck94",
"license": "MIT",
"icon": "icon.png",
Expand All @@ -11,7 +11,7 @@
"theme": "dark"
},
"engines": {
"vscode": "^1.84.0"
"vscode": "^1.85.0"
},
"categories": [
"Programming Languages",
Expand Down
25 changes: 20 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
mkdirRecursive,
pathExists,
} from './utils/fileUtils';
import { checkForCompilerIsValid } from './utils/systemUtils';
import {
createStatusBarItem,
disposeItem,
Expand Down Expand Up @@ -164,11 +165,24 @@ export function deactivate() {
disposeItem(eventRenameFilesDisposable);
}

function initWorkspaceProvider() {
async function initWorkspaceProvider() {
if (!workspaceFolder || !createExtensionFiles || !activeFolder) return;

if (!settingsProvider) {
settingsProvider = new SettingsProvider(workspaceFolder, activeFolder);

const cCompilerIsValid = await checkForCompilerIsValid(
`${settingsProvider.cCompilerPath} --version`,
);
const cppCompilerIsValid = await checkForCompilerIsValid(
`${settingsProvider.cppCompilerPath} --version`,
);

if (!cCompilerIsValid && !cppCompilerIsValid) {
vscode.window.showErrorMessage(
"The compiler that you have set does not exist or wasn't installed properly.",
);
}
}

if (!propertiesProvider) {
Expand Down Expand Up @@ -658,6 +672,7 @@ async function initCleanStatusBar() {
function initProviderBasedOnSingleFile() {
const currentFile = vscode.window.activeTextEditor?.document.fileName;
if (!currentFile) return;

const currentFolder = path.dirname(currentFile);
if (activeFolder !== currentFolder) {
activeFolder = currentFolder;
Expand Down Expand Up @@ -764,7 +779,7 @@ async function buildTaskCallback(singleFileBuild: boolean) {
) {
if (!pathExists(settingsProvider.cCompilerPath)) {
vscode.window.showErrorMessage(
"The C compiler that you have set does not exist or wasn't installed properly.",
"The C compiler (gcc/clang) that you have set does not exist or wasn't installed properly.",
);
return;
}
Expand All @@ -776,7 +791,7 @@ async function buildTaskCallback(singleFileBuild: boolean) {
) {
if (!pathExists(settingsProvider.cppCompilerPath)) {
vscode.window.showErrorMessage(
"The C++ compiler that you have set does not exist or wasn't installed properly.",
"The C++ compiler (g++/clang++) that you have set does not exist or wasn't installed properly.",
);
return;
}
Expand Down Expand Up @@ -806,7 +821,7 @@ async function runTaskCallback() {

if (!pathExists(modeDir) || !pathExists(executablePath)) {
vscode.window.showErrorMessage(
'The executable you want to run does not (yet) exist.',
'The executable you want to run does not (yet) exist. You need to build it first.',
);
return;
}
Expand Down Expand Up @@ -852,7 +867,7 @@ function debugTaskCallback() {

if (!pathExists(modeDir) || !pathExists(executablePath)) {
vscode.window.showErrorMessage(
'The executable you want to debug does not (yet) exist.',
'The executable you want to debug does not (yet) exist. You need to build it first.',
);
return;
}
Expand Down
29 changes: 15 additions & 14 deletions src/provider/launchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,21 @@ export class LaunchProvider extends FileProvider {

if (!launchTemplate) return;

if (
this.settings.operatingSystem === OperatingSystems.windows &&
(this.settings.useMsvc ||
this.settings.cCompilerPath.toLowerCase().includes('clang'))
) {
this.msvcBasedDebugger(launchTemplate);
delete launchTemplate.configurations[0]?.externalConsole;
} else if (
this.settings.operatingSystem === OperatingSystems.windows &&
launchTemplate.configurations[0]
) {
this.unixBasedDebugger(launchTemplate);
delete launchTemplate.configurations[0]?.console;
launchTemplate.configurations[0].externalConsole = true;
const is_windows =
this.settings.operatingSystem === OperatingSystems.windows;
const is_windows_based_compiler =
this.settings.useMsvc ||
this.settings.cCompilerPath.toLowerCase().includes('clang');

if (is_windows) {
if (is_windows_based_compiler) {
this.msvcBasedDebugger(launchTemplate);
delete launchTemplate.configurations[0]?.externalConsole;
} else if (launchTemplate.configurations[0]) {
this.unixBasedDebugger(launchTemplate);
delete launchTemplate.configurations[0]?.console;
launchTemplate.configurations[0].externalConsole = true;
}
} else {
this.unixBasedDebugger(launchTemplate);
delete launchTemplate.configurations[0]?.console;
Expand Down
26 changes: 25 additions & 1 deletion src/utils/systemUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from 'child_process';
import { exec, execSync } from 'child_process';
import { lookpath } from 'lookpath';
import { platform } from 'os';

Expand Down Expand Up @@ -61,3 +61,27 @@ export function getCompilerArchitecture(compiler: string) {

return { architecture: architecture, isCygwin: isCygwin };
}

interface CommandResult {
success: boolean;
stdout?: string;
stderr?: string;
}

async function executeCommand(command: string): Promise<CommandResult> {
return new Promise((resolve) => {
exec(command, (error, stdout, stderr) => {
if (error) {
resolve({ success: false, stderr: stderr || error.message });
} else {
resolve({ success: true, stdout: stdout.trim() });
}
});
});
}

export async function checkForCompilerIsValid(command: string) {
const result = await executeCommand(command);

return result.success;
}

0 comments on commit c3f9ceb

Please sign in to comment.