Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Code Samples/Fib/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"args": [],
Expand Down
72 changes: 28 additions & 44 deletions Code Samples/Fib/.vscode/tasks.json
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"
]
}
}
]
}
48 changes: 48 additions & 0 deletions Code Samples/Fib/README.md
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.
3 changes: 2 additions & 1 deletion Code Samples/Fib/build.cmd
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
82 changes: 82 additions & 0 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
53 changes: 38 additions & 15 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any[]>("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")); }
Expand Down