-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Implement per-workspace C/C++ configurations (#14363) #14366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8aeeb69
6b7cebe
86d415a
5f2444a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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/MinGW/Cygwin/Bin/Folder>", // 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" | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <Path\To\MinGW\Bin> 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 <Path\To\MinGW\Bin> 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| @@ -1,2 +0,0 @@ | ||
| SET PATH=%PATH%;%1 | ||
| g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 | ||
| g++ -g *.cpp -lpthread --std=c++11 -O0 -o %2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you reference localizable strings, e.g. %c_cpp.configuration.default.recursiveIncludes.order.markdownDescription% in package.nls.json? Or did you want us to do that? |
||
| "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": [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a "try" removed above, but the catch doesn't appear to be removed. That seems to cause a bunch of compiler errors. |
||
| 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++) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Subham-KRLX Can you revert the Code Samples folder changes?