Skip to content

Commit 9937753

Browse files
authored
Add setting to enable multiline comment customizations (#1583)
* Work in progress. Wrote framework for comment pattern handling. Implementation incomplete and some bugs remain. * address TODOs * incorrect disposal * incorrect type decorations * WIP: update changelog, add a test * test updates * rename the setting, update package.json and add more tests * deal with whitespace continuations * address PR feedback
1 parent 03cc6b2 commit 9937753

File tree

9 files changed

+462
-38
lines changed

9 files changed

+462
-38
lines changed

Extension/CHANGELOG.md

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

3+
## Version 0.15.1: March 2018
4+
* Support additional multiline comment patterns. [#1100](https://github.com/Microsoft/vscode-cpptools/issues/1100),[#1539](https://github.com/Microsoft/vscode-cpptools/issues/1539)
5+
* Added new setting: `C_Cpp.commentContinuationPatterns`
6+
37
## Version 0.15.0: February 15, 2018
48
* Add colorization for inactive regions. [#1466](https://github.com/Microsoft/vscode-cpptools/issues/1466)
59
* 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)

Extension/package.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,35 @@
194194
"default": "checkFolders",
195195
"description": "Instructs the extension when to use the \"files.exclude\" setting when determining which files should be added to the code navigation database while traversing through the paths in the \"browse.path\" array. \"checkFolders\" means that the exclusion filters will only be evaluated once per folder (individual files are not checked). \"checkFilesAndFolders\" means that the exclusion filters will be evaluated against every file and folder encountered. If your \"files.exclude\" setting only contains folders, then \"checkFolders\" is the best choice and will increase the speed at which the extension can initialize the code navigation database.",
196196
"scope": "resource"
197+
},
198+
"C_Cpp.commentContinuationPatterns": {
199+
"type": "array",
200+
"default": [
201+
"/**"
202+
],
203+
"items": {
204+
"anyOf": [
205+
{
206+
"type": "string",
207+
"description": "The pattern that begins a multiline or single line comment block. The continuation pattern defaults to ' * ' for multiline comment blocks or this string for single line comment blocks."
208+
},
209+
{
210+
"type": "object",
211+
"properties": {
212+
"begin": {
213+
"type": "string",
214+
"description": "The pattern that begins a multiline or single line comment block."
215+
},
216+
"continue": {
217+
"type": "string",
218+
"description": "The text that will be inserted on the next line when Enter is pressed inside a multiline or single line comment block."
219+
}
220+
}
221+
}
222+
]
223+
},
224+
"description": "Defines the editor behavior for when the Enter key is pressed inside a multiline or single line comment block.",
225+
"scope": "resource"
197226
}
198227
}
199228
},
@@ -1072,7 +1101,7 @@
10721101
"test": "gulp allTests",
10731102
"tslint": "gulp tslint",
10741103
"unitTests": "gulp unitTests",
1075-
"vscode:prepublish": "node ./src/Support/update.js && npm install && tsc -p ./ && node ./out/src/Support/copyDebuggerDependencies.js",
1104+
"vscode:prepublish": "node ./src/Support/prepublish.js",
10761105
"watch": "tsc -watch -p ./"
10771106
},
10781107
"devDependencies": {

Extension/src/LanguageServer/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { createProtocolFilter } from './protocolFilter';
2121
import { DataBinding } from './dataBinding';
2222
import minimatch = require("minimatch");
2323
import * as logger from '../logger';
24+
import { updateLanguageConfigurations } from './extension';
2425

2526
let ui: UI;
2627

@@ -130,7 +131,7 @@ function collectSettingsForTelemetry(filter: (key: string, val: string, settings
130131
}
131132
let val: any = settings.get(key);
132133
if (val instanceof Object) {
133-
continue; // ignore settings that are objects since tostring on those is not useful (e.g. navigation.length)
134+
val = JSON.stringify(val, null, 2);
134135
}
135136

136137
// Skip values that don't match the setting's enum.
@@ -438,9 +439,12 @@ class DefaultClient implements Client {
438439
let filter: (key: string, val: string) => boolean = (key: string, val: string) => {
439440
return !(key in previousCppSettings) || val !== previousCppSettings[key];
440441
};
441-
let changedSettings: any = collectSettingsForTelemetry(filter, this.RootUri);
442+
let changedSettings: { [key: string] : string} = collectSettingsForTelemetry(filter, this.RootUri);
442443

443444
if (Object.keys(changedSettings).length > 0) {
445+
if (changedSettings["commentContinuationPatterns"]) {
446+
updateLanguageConfigurations();
447+
}
444448
telemetry.logLanguageServerEvent("CppSettingsChange", changedSettings, null);
445449
}
446450
}

Extension/src/LanguageServer/extension.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,20 @@ import { Client } from './client';
1414
import { ClientCollection } from './clientCollection';
1515
import { CppSettings } from './settings';
1616
import { PersistentWorkspaceState } from './persistentState';
17+
import { getLanguageConfig } from './languageConfig';
1718
import * as os from 'os';
1819

1920
let prevCrashFile: string;
2021
let clients: ClientCollection;
2122
let activeDocument: string;
2223
let ui: UI;
2324
let disposables: vscode.Disposable[] = [];
25+
let languageConfigurations: vscode.Disposable[] = [];
2426
let intervalTimer: NodeJS.Timer;
2527
let realActivationOccurred: boolean = false;
2628
let tempCommands: vscode.Disposable[] = [];
2729
let activatedPreviously: PersistentWorkspaceState<boolean>;
2830

29-
// Add ' * ' on new lines after multiline comment with '/**' started
30-
// Copied from vscode/extensions/typescript/src/typescriptMain.ts
31-
const multilineCommentRules: any = {
32-
onEnterRules: [
33-
{
34-
// e.g. /** | */
35-
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
36-
afterText: /^\s*\*\/$/,
37-
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' }
38-
}, {
39-
// e.g. /** ...|
40-
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
41-
action: { indentAction: vscode.IndentAction.None, appendText: ' * ' }
42-
}, {
43-
// e.g. * ...|
44-
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
45-
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
46-
}, {
47-
// e.g. */|
48-
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
49-
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
50-
},
51-
{
52-
// e.g. *-----*/|
53-
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
54-
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
55-
}
56-
]
57-
};
58-
5931
/**
6032
* activate: set up the extension for language services
6133
*/
@@ -128,14 +100,21 @@ function realActivation(): void {
128100
disposables.push(vscode.window.onDidChangeTextEditorSelection(onDidChangeTextEditorSelection));
129101
disposables.push(vscode.window.onDidChangeVisibleTextEditors(onDidChangeVisibleTextEditors));
130102

131-
disposables.push(vscode.languages.setLanguageConfiguration('c', multilineCommentRules));
132-
disposables.push(vscode.languages.setLanguageConfiguration('cpp', multilineCommentRules));
103+
updateLanguageConfigurations();
133104

134105
reportMacCrashes();
135106

136107
intervalTimer = setInterval(onInterval, 2500);
137108
}
138109

110+
export function updateLanguageConfigurations(): void {
111+
languageConfigurations.forEach(d => d.dispose());
112+
languageConfigurations = [];
113+
114+
languageConfigurations.push(vscode.languages.setLanguageConfiguration('c', getLanguageConfig('c', clients.ActiveClient.RootUri)));
115+
languageConfigurations.push(vscode.languages.setLanguageConfiguration('cpp', getLanguageConfig('cpp', clients.ActiveClient.RootUri)));
116+
}
117+
139118
/*********************************************
140119
* workspace events
141120
*********************************************/
@@ -452,6 +431,7 @@ export function deactivate(): Thenable<void> {
452431
telemetry.logLanguageServerEvent("LanguageServerShutdown");
453432
clearInterval(intervalTimer);
454433
disposables.forEach(d => d.dispose());
434+
languageConfigurations.forEach(d => d.dispose());
455435
ui.dispose();
456436
return clients.dispose();
457437
}

0 commit comments

Comments
 (0)