Skip to content

Commit fd7b691

Browse files
authored
Inactive region highlight (#1505)
* Add intermediary type to safely construct vscode.Ranges for use * Fix incorrect object definition * Fix file empty edge case; refactor + comment out code while testing * Use InputRegions (lines only); Remove commented out code * Commenting * Fix linter error from merge with master
1 parent 42ddf18 commit fd7b691

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ interface OutputNotificationBody {
7171

7272
interface InactiveRegionParams {
7373
uri: string;
74-
ranges: InputRange[];
74+
regions: InputRegion[];
7575
}
7676

77-
interface InputRange {
78-
start: { line: number; character: number };
79-
end: { line: number; character: number };
77+
interface InputRegion {
78+
startLine: number;
79+
endLine: number;
8080
}
8181

8282
interface DecorationRangesPair {
@@ -137,8 +137,9 @@ function collectSettingsForTelemetry(filter: (key: string, val: string, settings
137137
let curSetting: any = util.packageJson.contributes.configuration.properties["C_Cpp." + key];
138138
if (curSetting) {
139139
let curEnum: any[] = curSetting["enum"];
140-
if (curEnum && curEnum.indexOf(val) === -1)
140+
if (curEnum && curEnum.indexOf(val) === -1) {
141141
continue;
142+
}
142143
}
143144

144145
if (filter(key, val, settings)) {
@@ -699,24 +700,22 @@ class DefaultClient implements Client {
699700
};
700701
let decoration: vscode.TextEditorDecorationType = vscode.window.createTextEditorDecorationType(renderOptions);
701702

702-
// As InactiveRegionParams.ranges is deserialized as POD, we must convert to vscode.Ranges in order to make use of the API's
703+
// We must convert to vscode.Ranges in order to make use of the API's
703704
let ranges: vscode.Range[] = [];
704-
params.ranges.forEach(element => {
705-
ranges.push(new vscode.Range(element.start.line, element.start.character, element.end.line, element.end.character));
705+
params.regions.forEach(element => {
706+
let newRange : vscode.Range = new vscode.Range(element.startLine, 0, element.endLine, 0);
707+
ranges.push(newRange);
706708
});
707709

708-
// Recycle the active text decorations when we receive a new set of inactive regions
710+
// Find entry for cached file and act accordingly
709711
let valuePair: DecorationRangesPair = this.inactiveRegionsDecorations.get(params.uri);
710712
if (valuePair) {
711-
// The language server will send notifications regardless of whether the ranges have changed, so we must check to see if the new data reflects a change
712-
if (!this.areRangesEqual(valuePair.ranges, ranges)) {
713-
// Disposing of and resetting the decoration will undo previously applied text decorations
714-
valuePair.decoration.dispose();
715-
valuePair.decoration = decoration;
716-
717-
// As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range for when another editor becomes visible
718-
valuePair.ranges = ranges;
719-
}
713+
// Disposing of and resetting the decoration will undo previously applied text decorations
714+
valuePair.decoration.dispose();
715+
valuePair.decoration = decoration;
716+
717+
// As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range for when another editor becomes visible
718+
valuePair.ranges = ranges;
720719
} else { // The entry does not exist. Make a new one
721720
let toInsert: DecorationRangesPair = {
722721
decoration: decoration,
@@ -732,21 +731,6 @@ class DefaultClient implements Client {
732731
}
733732
}
734733

735-
// Helper method to compare two ranges arrays for equality
736-
private areRangesEqual(r1: vscode.Range[], r2: vscode.Range[]): boolean {
737-
if (r1.length !== r2.length) {
738-
return false;
739-
}
740-
741-
for (let i: number = 0; i < r1.length; ++i) {
742-
if (!r1[i].isEqual(r2[i])) {
743-
return false;
744-
}
745-
}
746-
747-
return true;
748-
}
749-
750734
/*********************************************
751735
* requests to the language server
752736
*********************************************/

0 commit comments

Comments
 (0)