Skip to content

Commit f8c17fe

Browse files
committed
[clangd] fixes semantic highlighting test
Summary: fixes clangd/clangd#176 Patch by liu hui! Reviewers: ilya-biryukov, hokein, sammccall Reviewed By: hokein Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D70078
1 parent 6bcd8d4 commit f8c17fe

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,36 @@ suite('SemanticHighlighting Tests', () => {
8484
return scopeRanges;
8585
};
8686

87+
const fileUri1 = vscode.Uri.parse('file:///file1');
88+
const fileUri2 = vscode.Uri.parse('file:///file2');
89+
const fileUri1Str = fileUri1.toString();
90+
const fileUri2Str = fileUri2.toString();
91+
8792
class MockHighlighter extends semanticHighlighting.Highlighter {
8893
applicationUriHistory: string[] = [];
8994
// Override to make the highlighting calls accessible to the test. Also
9095
// makes the test not depend on visible text editors.
91-
applyHighlights(fileUri: string) {
92-
this.applicationUriHistory.push(fileUri);
96+
applyHighlights(fileUri: vscode.Uri) {
97+
this.applicationUriHistory.push(fileUri.toString());
9398
}
9499
// Override to make it accessible from the test.
95-
getDecorationRanges(fileUri: string) {
100+
getDecorationRanges(fileUri: vscode.Uri) {
96101
return super.getDecorationRanges(fileUri);
97102
}
98103
// Override to make tests not depend on visible text editors.
99-
getVisibleTextEditorUris() { return [ 'file1', 'file2' ]; }
104+
getVisibleTextEditorUris() { return [ fileUri1, fileUri2 ]; }
100105
}
101106
const highlighter = new MockHighlighter(scopeTable);
102107
const tm = new semanticHighlighting.ThemeRuleMatcher([
103108
{scope : 'variable', foreground : '1'},
104109
{scope : 'entity.type', foreground : '2'},
105110
]);
106111
// Recolorizes when initialized.
107-
highlighter.highlight('file1', []);
108-
assert.deepEqual(highlighter.applicationUriHistory, [ 'file1' ]);
112+
highlighter.highlight(fileUri1, []);
113+
assert.deepEqual(highlighter.applicationUriHistory, [ fileUri1Str ]);
109114
highlighter.initialize(tm);
110115
assert.deepEqual(highlighter.applicationUriHistory,
111-
[ 'file1', 'file1', 'file2' ]);
116+
[ fileUri1Str, fileUri1Str, fileUri2Str ]);
112117
// Groups decorations into the scopes used.
113118
let highlightingsInLine: semanticHighlighting.SemanticHighlightingLine[] = [
114119
{
@@ -128,10 +133,10 @@ suite('SemanticHighlighting Tests', () => {
128133
},
129134
];
130135

131-
highlighter.highlight('file1', highlightingsInLine);
136+
highlighter.highlight(fileUri1, highlightingsInLine);
132137
assert.deepEqual(highlighter.applicationUriHistory,
133-
[ 'file1', 'file1', 'file2', 'file1' ]);
134-
assert.deepEqual(highlighter.getDecorationRanges('file1'),
138+
[ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str ]);
139+
assert.deepEqual(highlighter.getDecorationRanges(fileUri1),
135140
createHighlightingScopeRanges(highlightingsInLine));
136141
// Keeps state separate between files.
137142
const highlightingsInLine1:
@@ -141,26 +146,29 @@ suite('SemanticHighlighting Tests', () => {
141146
{character : 2, length : 1, scopeIndex : 0},
142147
]
143148
};
144-
highlighter.highlight('file2', [ highlightingsInLine1 ]);
145-
assert.deepEqual(highlighter.applicationUriHistory,
146-
[ 'file1', 'file1', 'file2', 'file1', 'file2' ]);
147-
assert.deepEqual(highlighter.getDecorationRanges('file2'),
149+
highlighter.highlight(fileUri2, [ highlightingsInLine1 ]);
150+
assert.deepEqual(
151+
highlighter.applicationUriHistory,
152+
[ fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str ]);
153+
assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
148154
createHighlightingScopeRanges([ highlightingsInLine1 ]));
149155
// Does full colorizations.
150-
highlighter.highlight('file1', [ highlightingsInLine1 ]);
151-
assert.deepEqual(highlighter.applicationUriHistory,
152-
[ 'file1', 'file1', 'file2', 'file1', 'file2', 'file1' ]);
156+
highlighter.highlight(fileUri1, [ highlightingsInLine1 ]);
157+
assert.deepEqual(highlighter.applicationUriHistory, [
158+
fileUri1Str, fileUri1Str, fileUri2Str, fileUri1Str, fileUri2Str,
159+
fileUri1Str
160+
]);
153161
// After the incremental update to line 1, the old highlightings at line 1
154162
// will no longer exist in the array.
155163
assert.deepEqual(
156-
highlighter.getDecorationRanges('file1'),
164+
highlighter.getDecorationRanges(fileUri1),
157165
createHighlightingScopeRanges(
158166
[ highlightingsInLine1, ...highlightingsInLine.slice(1) ]));
159167
// Closing a text document removes all highlightings for the file and no
160168
// other files.
161-
highlighter.removeFileHighlightings('file1');
162-
assert.deepEqual(highlighter.getDecorationRanges('file1'), []);
163-
assert.deepEqual(highlighter.getDecorationRanges('file2'),
169+
highlighter.removeFileHighlightings(fileUri1);
170+
assert.deepEqual(highlighter.getDecorationRanges(fileUri1), []);
171+
assert.deepEqual(highlighter.getDecorationRanges(fileUri2),
164172
createHighlightingScopeRanges([ highlightingsInLine1 ]));
165173
});
166174
});

0 commit comments

Comments
 (0)