Skip to content

Commit d77470f

Browse files
authored
make browse.path optional (#2135)
1 parent 846cdc3 commit d77470f

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

Extension/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# C/C++ for Visual Studio Code Change Log
22

3+
## Version 0.17.5: June 18, 2018
4+
* Change inactive regions from gray to translucent. [#1907](https://github.com/Microsoft/vscode-cpptools/issues/1907)
5+
* Improve performance of recursive includes paths. [#2068](https://github.com/Microsoft/vscode-cpptools/issues/2068)
6+
* Fix #include completion with headers in the same directory. [#2031](https://github.com/Microsoft/vscode-cpptools/issues/2031)
7+
* Support asm clobber registers on Windows. [#2090](https://github.com/Microsoft/vscode-cpptools/issues/2090)
8+
* Fix some crashes. [#2080](https://github.com/Microsoft/vscode-cpptools/issues/2080)
9+
* `browse.path` now inherits `includePath` if not set in `c_cpp_properties.json`.
10+
311
## Version 0.17.4: May 31, 2018
412
* Fix infinite loop (caused by deadlock) when using recursive includes. [#2043](https://github.com/Microsoft/vscode-cpptools/issues/2043)
513
* Stop using recursive includes in the default configuration.

Extension/src/LanguageServer/configurations.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ const configVersion: number = 4;
1818
// The property defaults are moved down to applyDefaultIncludePathsAndFrameworks.
1919
function getDefaultConfig(): Configuration {
2020
if (process.platform === 'darwin') {
21-
return { name: "Mac", browse: {} };
21+
return { name: "Mac" };
2222
} else if (process.platform === 'win32') {
23-
return { name: "Win32", browse: {} };
23+
return { name: "Win32" };
2424
} else {
25-
return { name: "Linux", browse: {} };
25+
return { name: "Linux" };
2626
}
2727
}
2828

@@ -209,10 +209,7 @@ export class CppProperties {
209209
// We don't add system includes to the includePath anymore. The language server has this information.
210210
configuration.includePath = ["${workspaceFolder}"].concat(this.vcpkgIncludes);
211211
}
212-
if (!settings.defaultBrowsePath) {
213-
// We don't add system includes to the includePath anymore. The language server has this information.
214-
configuration.browse.path = ["${workspaceFolder}"].concat(this.vcpkgIncludes);
215-
}
212+
// browse.path is not set by default anymore. When it is not set, the includePath will be used instead.
216213
if (!settings.defaultDefines) {
217214
configuration.defines = (process.platform === 'win32') ? ["_DEBUG", "UNICODE", "_UNICODE"] : [];
218215
}
@@ -297,15 +294,6 @@ export class CppProperties {
297294
}
298295
}
299296

300-
private includePathConverted(): boolean {
301-
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
302-
if (this.configurationJson.configurations[i].browse === undefined || this.configurationJson.configurations[i].browse.path === undefined) {
303-
return false;
304-
}
305-
}
306-
return true;
307-
}
308-
309297
public addToIncludePathCommand(path: string): void {
310298
this.handleConfigurationEditCommand((document: vscode.TextDocument) => {
311299
telemetry.logLanguageServerEvent("addToIncludePath");
@@ -403,7 +391,23 @@ export class CppProperties {
403391
if (!configuration.browse) {
404392
configuration.browse = {};
405393
}
406-
configuration.browse.path = this.updateConfiguration(configuration.browse.path, settings.defaultBrowsePath);
394+
395+
if (!configuration.browse.path) {
396+
if (settings.defaultBrowsePath) {
397+
configuration.browse.path = settings.defaultBrowsePath;
398+
} else if (configuration.includePath) {
399+
// If the user doesn't set browse.path, copy the includePath over. Make sure ${workspaceFolder} is in there though...
400+
configuration.browse.path = configuration.includePath.slice(0);
401+
if (-1 === configuration.includePath.findIndex((value: string, index: number) => {
402+
return !!value.match(/^\$\{(workspaceRoot|workspaceFolder)\}(\\|\\\*\*|\/|\/\*\*)?$/g);
403+
})) {
404+
configuration.browse.path.push("${workspaceFolder}");
405+
}
406+
}
407+
} else {
408+
configuration.browse.path = this.updateConfiguration(configuration.browse.path, settings.defaultBrowsePath);
409+
}
410+
407411
configuration.browse.limitSymbolsToIncludedHeaders = this.updateConfiguration(configuration.browse.limitSymbolsToIncludedHeaders, settings.defaultLimitSymbolsToIncludedHeaders);
408412
configuration.browse.databaseFilename = this.updateConfiguration(configuration.browse.databaseFilename, settings.defaultDatabaseFilename);
409413
}
@@ -452,7 +456,7 @@ export class CppProperties {
452456
let filePath: vscode.Uri = vscode.Uri.parse("untitled:" + fullPathToFile);
453457
vscode.workspace.openTextDocument(filePath).then((document: vscode.TextDocument) => {
454458
let edit: vscode.WorkspaceEdit = new vscode.WorkspaceEdit();
455-
if (this.configurationJson === undefined) {
459+
if (this.configurationJson) {
456460
this.resetToDefaultSettings(true);
457461
}
458462
this.applyDefaultIncludePathsAndFrameworks();
@@ -571,17 +575,8 @@ export class CppProperties {
571575

572576
private updateToVersion2(): void {
573577
this.configurationJson.version = 2;
574-
if (!this.includePathConverted()) {
575-
for (let i: number = 0; i < this.configurationJson.configurations.length; i++) {
576-
let config: Configuration = this.configurationJson.configurations[i];
577-
if (config.browse === undefined) {
578-
config.browse = {};
579-
}
580-
if (config.browse.path === undefined && (this.defaultIncludes !== undefined || config.includePath !== undefined)) {
581-
config.browse.path = (config.includePath === undefined) ? this.defaultIncludes.slice(0) : config.includePath.slice(0);
582-
}
583-
}
584-
}
578+
// no-op. We don't automatically populate the browse.path anymore.
579+
// We use includePath if browse.path is not present which is what this code used to do.
585580
}
586581

587582
private updateToVersion3(): void {

0 commit comments

Comments
 (0)