Skip to content

Commit bd181c3

Browse files
authored
add compilerPath, cStandard, and cppStandard settings, fix inactive region deletion bug (#1549)
* Add compilerPath setting. * Add code to query the default compiler. * Add cStandard and cppStandard settings. * Fix bug with inactive region deletion.
1 parent 00f70ae commit bd181c3

File tree

9 files changed

+95
-42
lines changed

9 files changed

+95
-42
lines changed

Extension/CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# C/C++ for Visual Studio Code Change Log
22

3-
## Version 0.15.1: March 2018
3+
## Version 0.16.0: March 15, 2018
44
* Enable autocomplete for local and global scopes. [#13](https://github.com/Microsoft/vscode-cpptools/issues/13)
5-
* Support additional multiline comment patterns. [#1100](https://github.com/Microsoft/vscode-cpptools/issues/1100),[#1539](https://github.com/Microsoft/vscode-cpptools/issues/1539)
6-
* Added new setting: `C_Cpp.commentContinuationPatterns`
5+
* Support additional multiline comment patterns. [#1100](https://github.com/Microsoft/vscode-cpptools/issues/1100), [#1539](https://github.com/Microsoft/vscode-cpptools/issues/1539)
6+
* Add new setting: `C_Cpp.commentContinuationPatterns`.
77
* Add a setting to disable inactive region highlighting. [#1592](https://github.com/Microsoft/vscode-cpptools/issues/1592)
88
* Add support for forced includes. [#852](https://github.com/Microsoft/vscode-cpptools/issues/852)
9+
* Add `compilerPath`, `cStandard`, and `cppStandard` configuration settings, and query gcc/clang-based compilers for default defines. [#1293](https://github.com/Microsoft/vscode-cpptools/issues/1293), [#1251](https://github.com/Microsoft/vscode-cpptools/issues/1251), [#1448](https://github.com/Microsoft/vscode-cpptools/issues/1448), [#1465](https://github.com/Microsoft/vscode-cpptools/issues/1465), [#1484](https://github.com/Microsoft/vscode-cpptools/issues/1484)
10+
* Fix text being temporarily gray when an inactive region is deleted. [Microsoft/vscode#44872](https://github.com/Microsoft/vscode/issues/44872)
911

1012
## Version 0.15.0: February 15, 2018
1113
* Add colorization for inactive regions. [#1466](https://github.com/Microsoft/vscode-cpptools/issues/1466)
1214
* Fix 3 highest hitting crashes. [#1137](https://github.com/Microsoft/vscode-cpptools/issues/1137), [#1337](https://github.com/Microsoft/vscode-cpptools/issues/1337), [#1497](https://github.com/Microsoft/vscode-cpptools/issues/1497)
13-
* Update IntelliSense compiler (bug fixes and more C++17 support). [#1067](https://github.com/Microsoft/vscode-cpptools/issues/1067), [#1313](https://github.com/Microsoft/vscode-cpptools/issues/1313), [#1461](https://github.com/Microsoft/vscode-cpptools/issues/1461)
15+
* Update IntelliSense compiler (bug fixes and more C++17 support). [#1067](https://github.com/Microsoft/vscode-cpptools/issues/1067), [#1313](https://github.com/Microsoft/vscode-cpptools/issues/1313)
1416
* Fix duplicate `cannot open source file` errors. [#1469](https://github.com/Microsoft/vscode-cpptools/issues/1469)
1517
* Fix `Go to Symbol in File...` being slow for large workspaces. [#1472](https://github.com/Microsoft/vscode-cpptools/issues/1472)
1618
* Fix stuck processes during shutdown. [#1474](https://github.com/Microsoft/vscode-cpptools/issues/1474)

Extension/bin/msvc.64.darwin.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"defaults": [
33
"--clang",
44
"--pack_alignment",
5-
"8",
6-
"-D__CHAR_BIT__=8"
5+
"8"
76
],
87
"defaults_op" : "merge"
98
}

Extension/bin/msvc.64.intel.clang.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"defaults": [
33
"--clang",
44
"--pack_alignment",
5-
"8",
6-
"-D__CHAR_BIT__=8"
5+
"8"
76
],
87
"defaults_op" : "merge"
98
}

Extension/bin/msvc.64.linux.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"defaults": [
33
"--clang",
44
"--pack_alignment",
5-
"8",
6-
"-D__CHAR_BIT__=8"
5+
"8"
76
],
87
"defaults_op" : "merge"
98
}

Extension/bin/msvc.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
{
2929
"match": "^/dE--header_only_fallback",
3030
"replace": "--header_only_fallback"
31-
},
32-
{
33-
"match": "^/lang_c_",
34-
"replace": "--c\n--c11"
35-
},
36-
{
37-
"match": "^/lang_cpp_",
38-
"replace": "--c++17"
3931
}
4032
]
4133
}

Extension/c_cpp_properties.schema.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,33 @@
1414
"description": "Platform name. Mac, Linux, or Win32 are the defaults unless a custom platform is added.",
1515
"type": "string"
1616
},
17-
"compileCommands":{
17+
"compilerPath": {
18+
"description": "Full path name of the compiler being used, e.g. /usr/bin/gcc, to enable more accurate IntelliSense.",
19+
"type": "string"
20+
},
21+
"cStandard": {
22+
"description": "Version of the C language standard to use for IntelliSense.",
23+
"type": "string",
24+
"enum": [
25+
"c89",
26+
"c99",
27+
"c11"
28+
]
29+
},
30+
"cppStandard": {
31+
"description": "Version of the C++ language standard to use for IntelliSense.",
32+
"type": "string",
33+
"enum": [
34+
"c++98",
35+
"c++03",
36+
"c++11",
37+
"c++14",
38+
"c++17"
39+
]
40+
},
41+
"compileCommands": {
1842
"description": "path to compile_commands.json file for the workspace",
19-
"type":"string"
43+
"type": "string"
2044
},
2145
"includePath": {
2246
"description": "A list of paths for the IntelliSense engine to use while searching for included headers. Searching on these paths is not recursive.",

Extension/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cpptools",
33
"displayName": "C/C++",
44
"description": "C/C++ IntelliSense, debugging, and code browsing.",
5-
"version": "0.15.0",
5+
"version": "0.16.0",
66
"publisher": "ms-vscode",
77
"preview": true,
88
"icon": "LanguageCCPP_color_128x.png",
@@ -1145,7 +1145,7 @@
11451145
"runtimeDependencies": [
11461146
{
11471147
"description": "C/C++ language components (Linux / x86_64)",
1148-
"url": "https://go.microsoft.com/fwlink/?linkid=866913",
1148+
"url": "https://go.microsoft.com/fwlink/?linkid=867977",
11491149
"platforms": [
11501150
"linux"
11511151
],
@@ -1159,7 +1159,7 @@
11591159
},
11601160
{
11611161
"description": "C/C++ language components (Linux / x86)",
1162-
"url": "https://go.microsoft.com/fwlink/?linkid=866914",
1162+
"url": "https://go.microsoft.com/fwlink/?linkid=867978",
11631163
"platforms": [
11641164
"linux"
11651165
],
@@ -1175,7 +1175,7 @@
11751175
},
11761176
{
11771177
"description": "C/C++ language components (OS X)",
1178-
"url": "https://go.microsoft.com/fwlink/?linkid=866915",
1178+
"url": "https://go.microsoft.com/fwlink/?linkid=867979",
11791179
"platforms": [
11801180
"darwin"
11811181
],
@@ -1186,7 +1186,7 @@
11861186
},
11871187
{
11881188
"description": "C/C++ language components (Windows)",
1189-
"url": "https://go.microsoft.com/fwlink/?linkid=866916",
1189+
"url": "https://go.microsoft.com/fwlink/?linkid=867980",
11901190
"platforms": [
11911191
"win32"
11921192
],

Extension/src/LanguageServer/client.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface ReportStatusNotificationBody {
4444
status: string;
4545
}
4646

47-
interface QueryDefaultPathsParams {
47+
interface QueryCompilerDefaultsParams {
4848
}
4949

5050
interface FolderSettingsParams {
@@ -88,7 +88,7 @@ interface DecorationRangesPair {
8888
// Requests
8989
const NavigationListRequest: RequestType<TextDocumentIdentifier, string, void, void> = new RequestType<TextDocumentIdentifier, string, void, void>('cpptools/requestNavigationList');
9090
const GoToDeclarationRequest: RequestType<void, void, void, void> = new RequestType<void, void, void, void>('cpptools/goToDeclaration');
91-
const QueryDefaultPathsRequest: RequestType<QueryDefaultPathsParams, configs.DefaultPaths, void, void> = new RequestType<QueryDefaultPathsParams, configs.DefaultPaths, void, void>('cpptools/queryDefaultPaths');
91+
const QueryCompilerDefaultsRequest: RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void> = new RequestType<QueryCompilerDefaultsParams, configs.CompilerDefaults, void, void>('cpptools/queryCompilerDefaults');
9292
const SwitchHeaderSourceRequest: RequestType<SwitchHeaderSourceParams, string, void, void> = new RequestType<SwitchHeaderSourceParams, string, void, void>('cpptools/didSwitchHeaderSource');
9393

9494
// Notifications to the server
@@ -325,8 +325,8 @@ class DefaultClient implements Client {
325325

326326
// The configurations will not be sent to the language server until the default include paths and frameworks have been set.
327327
// The event handlers must be set before this happens.
328-
languageClient.sendRequest(QueryDefaultPathsRequest, {}).then((paths: configs.DefaultPaths) => {
329-
this.configuration.DefaultPaths = paths;
328+
languageClient.sendRequest(QueryCompilerDefaultsRequest, {}).then((compilerDefaults: configs.CompilerDefaults) => {
329+
this.configuration.CompilerDefaults = compilerDefaults;
330330
});
331331

332332
// Once this is set, we don't defer any more callbacks.
@@ -554,16 +554,10 @@ class DefaultClient implements Client {
554554
console.assert(this.languageClient !== undefined, "This method must not be called until this.languageClient is set in \"onReady\"");
555555

556556
this.languageClient.onNotification(DebugProtocolNotification, (output) => {
557-
let outputEditorExist: boolean = vscode.window.visibleTextEditors.some((editor: vscode.TextEditor) => {
558-
return editor.document.uri.scheme === "output";
559-
});
560557
if (!this.debugChannel) {
561558
this.debugChannel = vscode.window.createOutputChannel(`C/C++ Debug Protocol: ${this.Name}`);
562559
this.disposables.push(this.debugChannel);
563560
}
564-
if (!outputEditorExist) {
565-
this.debugChannel.show();
566-
}
567561
this.debugChannel.appendLine("");
568562
this.debugChannel.appendLine("************************************************************************************************************************");
569563
this.debugChannel.append(`${output}`);
@@ -705,7 +699,8 @@ class DefaultClient implements Client {
705699
private updateInactiveRegions(params: InactiveRegionParams): void {
706700
let renderOptions: vscode.DecorationRenderOptions = {
707701
light: { color: "rgba(175,175,175,1.0)" },
708-
dark: { color: "rgba(155,155,155,1.0)" }
702+
dark: { color: "rgba(155,155,155,1.0)" },
703+
rangeBehavior: vscode.DecorationRangeBehavior.ClosedOpen
709704
};
710705
let decoration: vscode.TextEditorDecorationType = vscode.window.createTextEditorDecorationType(renderOptions);
711706

Extension/src/LanguageServer/configurations.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export interface Browse {
8989

9090
export interface Configuration {
9191
name: string;
92+
compilerPath?: string;
93+
cStandard?: string;
94+
cppStandard?: string;
9295
includePath?: string[];
9396
macFrameworkPath?: string[];
9497
defines?: string[];
@@ -98,7 +101,10 @@ export interface Configuration {
98101
browse?: Browse;
99102
}
100103

101-
export interface DefaultPaths {
104+
export interface CompilerDefaults {
105+
compilerPath: string;
106+
cStandard: string;
107+
cppStandard: string;
102108
includes: string[];
103109
frameworks: string[];
104110
}
@@ -116,6 +122,9 @@ export class CppProperties {
116122
private configFileWatcher: vscode.FileSystemWatcher = null;
117123
private configFileWatcherFallbackTime: Date = new Date(); // Used when file watching fails.
118124
private compileCommandFileWatchers: fs.FSWatcher[] = [];
125+
private defaultCompilerPath: string = null;
126+
private defaultCStandard: string = null;
127+
private defaultCppStandard: string = null;
119128
private defaultIncludes: string[] = null;
120129
private defaultFrameworks: string[] = null;
121130
private readonly configurationGlobPattern: string = "**/c_cpp_properties.json"; // TODO: probably should be a single file, not all files...
@@ -171,9 +180,31 @@ export class CppProperties {
171180
return result;
172181
}
173182

174-
public set DefaultPaths(paths: DefaultPaths) {
175-
this.defaultIncludes = paths.includes;
176-
this.defaultFrameworks = paths.frameworks;
183+
public set CompilerDefaults(compilerDefaults: CompilerDefaults) {
184+
this.defaultCompilerPath = compilerDefaults.compilerPath;
185+
this.defaultCStandard = compilerDefaults.cStandard;
186+
this.defaultCppStandard = compilerDefaults.cppStandard;
187+
this.defaultIncludes = compilerDefaults.includes;
188+
this.defaultFrameworks = compilerDefaults.frameworks;
189+
190+
// Update the compilerPath, cStandard, and cppStandard with the default being used.
191+
let doUpdate: boolean = false;
192+
let config: Configuration = this.configurationJson.configurations[this.CurrentConfiguration];
193+
if (this.defaultCompilerPath && this.defaultCompilerPath.length > 0 && (!config.compilerPath || config.compilerPath.length === 0)) {
194+
config.compilerPath = this.defaultCompilerPath;
195+
doUpdate = true;
196+
}
197+
if (this.defaultCStandard && this.defaultCStandard.length > 0 && (!config.cStandard || config.cStandard.length === 0)) {
198+
config.cStandard = this.defaultCStandard;
199+
doUpdate = true;
200+
}
201+
if (this.defaultCppStandard && this.defaultCppStandard.length > 0 && (!config.cppStandard || config.cppStandard.length === 0)) {
202+
config.cppStandard = this.defaultCppStandard;
203+
doUpdate = true;
204+
}
205+
if (doUpdate) {
206+
fs.writeFileSync(this.propertiesFile.fsPath, JSON.stringify(this.configurationJson, null, 4));
207+
}
177208

178209
// defaultPaths is only used when there isn't a c_cpp_properties.json, but we don't send the configuration changed event
179210
// to the language server until the default include paths and frameworks have been sent.
@@ -202,12 +233,21 @@ export class CppProperties {
202233
}
203234

204235
private applyDefaultIncludePathsAndFrameworks(): void {
205-
if (this.configurationIncomplete && this.defaultIncludes !== undefined && this.defaultFrameworks !== undefined) {
236+
if (this.configurationIncomplete && this.defaultIncludes && this.defaultFrameworks) {
206237
this.configurationJson.configurations[this.CurrentConfiguration].includePath = this.defaultIncludes;
207238
this.configurationJson.configurations[this.CurrentConfiguration].browse.path = this.defaultIncludes;
208239
if (process.platform === 'darwin') {
209240
this.configurationJson.configurations[this.CurrentConfiguration].macFrameworkPath = this.defaultFrameworks;
210241
}
242+
if (this.defaultCompilerPath) {
243+
this.configurationJson.configurations[this.CurrentConfiguration].compilerPath = this.defaultCompilerPath;
244+
}
245+
if (this.defaultCStandard) {
246+
this.configurationJson.configurations[this.CurrentConfiguration].cStandard = this.defaultCStandard;
247+
}
248+
if (this.defaultCppStandard) {
249+
this.configurationJson.configurations[this.CurrentConfiguration].cppStandard = this.defaultCppStandard;
250+
}
211251
this.configurationIncomplete = false;
212252
}
213253
}
@@ -293,7 +333,7 @@ export class CppProperties {
293333
if (configuration.includePath) {
294334
configuration.includePath = this.resolveAndSplit(configuration.includePath);
295335
}
296-
if (configuration.browse) {
336+
if (configuration.browse && configuration.browse.path) {
297337
configuration.browse.path = this.resolveAndSplit(configuration.browse.path);
298338
}
299339
if (configuration.macFrameworkPath) {
@@ -305,6 +345,9 @@ export class CppProperties {
305345
if (configuration.compileCommands) {
306346
configuration.compileCommands = util.resolveVariables(configuration.compileCommands);
307347
}
348+
if (configuration.compilerPath) {
349+
configuration.compilerPath = util.resolveVariables(configuration.compilerPath);
350+
}
308351
}
309352

310353
this.updateCompileCommandsFileWatchers();

0 commit comments

Comments
 (0)