From 8aeeb692a7bc86d62dc51598699de4d4f59b0c1c Mon Sep 17 00:00:00 2001 From: Subham Date: Sat, 2 Aug 2025 07:37:09 +0530 Subject: [PATCH 1/3] Update build.cmd --- Code Samples/Fib/build.cmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code Samples/Fib/build.cmd b/Code Samples/Fib/build.cmd index 821c62747..8b78dafa9 100644 --- a/Code Samples/Fib/build.cmd +++ b/Code Samples/Fib/build.cmd @@ -1,2 +1,3 @@ +@@ -1,2 +0,0 @@ SET PATH=%PATH%;%1 -g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 \ No newline at end of file +g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 From 6b7cebe174020a48d66ae89823c304ce8358b3de Mon Sep 17 00:00:00 2001 From: Subham Sangwan Date: Sun, 9 Nov 2025 10:30:31 +0530 Subject: [PATCH 2/3] samples(Fib): remove build task, update README, remove preLaunchTask from launch.json --- Code Samples/Fib/.vscode/launch.json | 1 - Code Samples/Fib/.vscode/tasks.json | 72 +++++++++++----------------- Code Samples/Fib/README.md | 48 +++++++++++++++++++ 3 files changed, 76 insertions(+), 45 deletions(-) diff --git a/Code Samples/Fib/.vscode/launch.json b/Code Samples/Fib/.vscode/launch.json index 301f8c5f2..b1349d1a4 100644 --- a/Code Samples/Fib/.vscode/launch.json +++ b/Code Samples/Fib/.vscode/launch.json @@ -3,7 +3,6 @@ "configurations": [ { "name": "(gdb) Launch", - "preLaunchTask": "build", "type": "cppdbg", "request": "launch", "args": [], diff --git a/Code Samples/Fib/.vscode/tasks.json b/Code Samples/Fib/.vscode/tasks.json index 104a10aad..49c3004f1 100644 --- a/Code Samples/Fib/.vscode/tasks.json +++ b/Code Samples/Fib/.vscode/tasks.json @@ -1,50 +1,34 @@ +{ + "version": "2.0.0", + "tasks": [] +} +```jsonc +{ + "version": "2.0.0", + "tasks": [] +} +``` +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + // The explicit "build" task was removed because the sample now uses a direct g++ command + // (the Makefile was removed). If you prefer a build task, add one that runs the + // appropriate g++ command for your platform or call `build.cmd` on Windows. + "tasks": [] +} { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", - "tasks": [ - { - "label": "build", - "type": "shell", - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { + { + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + // The explicit "build" task was removed because the sample now uses a direct g++ command + // (the Makefile was removed). If you prefer a build task, add one that runs the + // appropriate g++ command for your platform or call `build.cmd` on Windows. + "tasks": [] + } "echo": true, - "reveal": "always", - "focus": false, - "panel": "shared" - }, - "windows": { - "command": "${workspaceRoot}/build.cmd", - "args": [ - "", // Path to the bin folder containing g++ to compile - "fib.exe" // Output executable name - ] - }, - "linux": { - "command": "g++", - "args": [ - "-g", - "*.cpp", - "-lpthread", - "--std=c++11", - "-o", - "fib.out" - ] - }, - "osx": { - "command": "g++", - "args": [ - "-g", - "*.cpp", - "-lpthread", - "--std=c++11", - "-o", - "fib.out" - ] - } - } - ] } diff --git a/Code Samples/Fib/README.md b/Code Samples/Fib/README.md index 6402c911b..a9f9eb045 100644 --- a/Code Samples/Fib/README.md +++ b/Code Samples/Fib/README.md @@ -1,3 +1,51 @@ # Fib +This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. + +## Building + +Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly. + +```bash +# Linux / macOS +g++ -g *.cpp -std=c++11 -o fib.out + +# Windows (MinGW) +g++ -g *.cpp -std=c++11 -o fib.exe +``` + +On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name): + +```powershell +.\build.cmd fib.exe +``` + +After building, use the `launch.json` in this folder (or your own) to debug the produced binary. +```markdown +# Fib + +This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. + +## Building + +Use one of the commands below to build the sample. The Makefile was removed and the sample is built with g++ directly. + +```bash +# Linux / macOS +g++ -g *.cpp -std=c++11 -o fib.out + +# Windows (MinGW) +g++ -g *.cpp -std=c++11 -o fib.exe +``` + +On Windows you can also run the included `build.cmd` if you prefer (it expects the path to a MinGW/Cygwin `bin` folder and an output name): + +```powershell +.\build.cmd fib.exe +``` + +After building, use the `launch.json` in this folder (or your own) to debug the produced binary. +``` +# Fib + This code sample is to show debugging. Update `launch.json` and `tasks.json` in the `.vscode` folder to use your setup to build and debug. \ No newline at end of file From 5f2444a3e8c849ff3c5e2e76e3c178759a8d45e6 Mon Sep 17 00:00:00 2001 From: Subham Sangwan Date: Sun, 12 Apr 2026 18:29:12 +0530 Subject: [PATCH 3/3] Implement per-workspace C/C++ configurations (#14363) --- Extension/package.json | 82 +++++++++++++++++++ .../src/LanguageServer/configurations.ts | 53 ++++++++---- Extension/src/LanguageServer/settings.ts | 1 + 3 files changed, 121 insertions(+), 15 deletions(-) diff --git a/Extension/package.json b/Extension/package.json index 49701bccf..d8263198f 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -1060,6 +1060,88 @@ "markdownDescription": "%c_cpp.configuration.default.recursiveIncludes.order.markdownDescription%", "scope": "resource" }, + "C_Cpp.configurations": { + "type": "array", + "description": "A list of configurations that will be used instead of c_cpp_properties.json when present in workspace settings.", + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string", + "description": "Configuration identifier." + }, + "compilerPath": { + "type": [ + "null", + "string" + ], + "description": "Full path of the compiler being used." + }, + "compilerArgs": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Compiler arguments." + }, + "includePath": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of paths for the IntelliSense engine to use while searching for included headers." + }, + "defines": { + "type": "array", + "items": { + "type": "string" + }, + "description": "A list of preprocessor definitions." + }, + "cStandard": { + "type": "string", + "description": "Version of the C language standard to use for IntelliSense." + }, + "cppStandard": { + "type": "string", + "description": "Version of the C++ language standard to use for IntelliSense." + }, + "intelliSenseMode": { + "type": "string", + "description": "The IntelliSense mode to use." + }, + "configurationProvider": { + "type": "string", + "description": "The id of a VS Code extension that can provide IntelliSense configuration information." + }, + "compileCommands": { + "type": "string", + "description": "Full path to a compile_commands.json file." + }, + "browse": { + "type": "object", + "properties": { + "path": { + "type": "array", + "items": { + "type": "string" + } + }, + "limitSymbolsToIncludedHeaders": { + "type": "boolean" + }, + "databaseFilename": { + "type": "string" + } + } + } + } + }, + "scope": "resource" + }, "C_Cpp.configurationWarnings": { "type": "string", "enum": [ diff --git a/Extension/src/LanguageServer/configurations.ts b/Extension/src/LanguageServer/configurations.ts index ce2fd780a..d7265f6cf 100644 --- a/Extension/src/LanguageServer/configurations.ts +++ b/Extension/src/LanguageServer/configurations.ts @@ -363,8 +363,8 @@ export class CppProperties { public onDidChangeSettings(): void { // Default settings may have changed in a way that affects the configuration. // Just send another message since the language server will sort out whether anything important changed or not. - if (!this.propertiesFile) { - this.resetToDefaultSettings(true); + const settings: CppSettings = new CppSettings(this.rootUri); + if (!this.propertiesFile || (settings.configurations && settings.configurations.length > 0)) { this.handleConfigurationChange(); } else if (!this.configurationIncomplete) { this.handleConfigurationChange(); @@ -1370,7 +1370,8 @@ export class CppProperties { } public handleConfigurationChange(): void { - if (this.propertiesFile === undefined) { + const settings: CppSettings = new CppSettings(this.rootUri); + if (this.propertiesFile === undefined && (!settings.configurations || settings.configurations.length === 0)) { return; // Occurs when propertiesFile hasn't been checked yet. } this.configFileWatcherFallbackTime = new Date(); @@ -1452,24 +1453,46 @@ export class CppProperties { } private parsePropertiesFile(): boolean { - if (!this.propertiesFile) { - this.configurationJson = undefined; - return false; - } + const settings: CppSettings = new CppSettings(this.rootUri); + const settingsConfigs: any[] | undefined = settings.configurations; + let success: boolean = true; const firstParse = this.configurationJson === undefined; - try { - const readResults: string = fs.readFileSync(this.propertiesFile.fsPath, 'utf8'); - if (readResults === "") { - return false; // Repros randomly when the file is initially created. The parse will get called again after the file is written. + + let newJson: ConfigurationJson | undefined; + if (settingsConfigs && settingsConfigs.length > 0) { + newJson = { + configurations: settingsConfigs as Configuration[], + version: configVersion + }; + } else { + if (!this.propertiesFile) { + this.configurationJson = undefined; + return false; } + try { + const readResults: string = fs.readFileSync(this.propertiesFile.fsPath, 'utf8'); + if (readResults === "") { + return false; // Repros randomly when the file is initially created. The parse will get called again after the file is written. + } - // Try to use the same configuration as before the change. - // TODO?: Handle when jsonc.parse() throws an exception due to invalid JSON contents. - const newJson: ConfigurationJson = jsonc.parse(readResults, undefined, true) as any; - if (!newJson || !newJson.configurations || newJson.configurations.length === 0) { + // Try to use the same configuration as before the change. + // TODO?: Handle when jsonc.parse() throws an exception due to invalid JSON contents. + newJson = jsonc.parse(readResults, undefined, true) as any; + } catch (err) { + this.configurationJson = undefined; + success = false; + } + } + + if (!newJson || !newJson.configurations || newJson.configurations.length === 0) { + if (settingsConfigs && settingsConfigs.length > 0) { + // If we tried to parse from settings and it was invalid, we should probably log an error. + } else if (this.propertiesFile) { throw { message: localize("invalid.configuration.file", "Invalid configuration file. There must be at least one configuration present in the array.") }; } + return false; + } if (!this.configurationIncomplete && this.configurationJson && this.configurationJson.configurations && this.CurrentConfigurationIndex >= 0 && this.CurrentConfigurationIndex < this.configurationJson.configurations.length) { for (let i: number = 0; i < newJson.configurations.length; i++) { diff --git a/Extension/src/LanguageServer/settings.ts b/Extension/src/LanguageServer/settings.ts index 881423789..836142a5a 100644 --- a/Extension/src/LanguageServer/settings.ts +++ b/Extension/src/LanguageServer/settings.ts @@ -448,6 +448,7 @@ export class CppSettings extends Settings { public get defaultCStandard(): string | undefined { return this.getAsStringOrUndefined("default.cStandard"); } public get defaultCppStandard(): string | undefined { return this.getAsStringOrUndefined("default.cppStandard"); } public get defaultConfigurationProvider(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.configurationProvider")); } + public get configurations(): any[] | undefined { return this.Section.get("configurations"); } public get defaultMergeConfigurations(): boolean { return this.getAsBoolean("default.mergeConfigurations"); } public get defaultBrowsePath(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.browse.path"); } public get defaultDatabaseFilename(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.browse.databaseFilename")); }