Skip to content

Commit 3d26adb

Browse files
author
git apple-llvm automerger
committed
Merge commit 'b4f46a9bb429' from llvm.org/master into apple/master
2 parents b7b658c + b4f46a9 commit 3d26adb

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

clang-tools-extra/clangd/clients/clangd-vscode/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clang-tools-extra/clangd/clients/clangd-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-clangd",
33
"displayName": "vscode-clangd",
44
"description": "Clang Language Server",
5-
"version": "0.0.18",
5+
"version": "0.0.19",
66
"publisher": "llvm-vs-code-extensions",
77
"homepage": "https://clang.llvm.org/extra/clangd.html",
88
"engines": {

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ export class SemanticHighlightingFeature implements vscodelc.StaticFeature {
114114
this.loadCurrentTheme();
115115
// Event handling for handling with TextDocuments/Editors lifetimes.
116116
this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
117-
(editors: vscode.TextEditor[]) =>
118-
editors.forEach((e) => this.highlighter.applyHighlights(
119-
e.document.uri.toString()))));
117+
(editors: vscode.TextEditor[]) => editors.forEach(
118+
(e) => this.highlighter.applyHighlights(e.document.uri))));
120119
this.subscriptions.push(vscode.workspace.onDidCloseTextDocument(
121-
(doc) => this.highlighter.removeFileHighlightings(doc.uri.toString())));
120+
(doc) => this.highlighter.removeFileHighlightings(doc.uri)));
122121
}
123122

124123
handleNotification(params: SemanticHighlightingParams) {
125124
const lines: SemanticHighlightingLine[] = params.lines.map(
126125
(line) => ({line : line.line, tokens : decodeTokens(line.tokens)}));
127-
this.highlighter.highlight(params.textDocument.uri, lines);
126+
this.highlighter.highlight(vscode.Uri.parse(params.textDocument.uri),
127+
lines);
128128
}
129129
// Disposes of all disposable resources used by this object.
130130
public dispose() {
@@ -199,19 +199,21 @@ export class Highlighter {
199199
// Adds incremental highlightings to the current highlightings for the file
200200
// with fileUri. Also applies the highlightings to any associated
201201
// TextEditor(s).
202-
public highlight(fileUri: string,
202+
public highlight(fileUri: vscode.Uri,
203203
highlightingLines: SemanticHighlightingLine[]) {
204-
if (!this.files.has(fileUri)) {
205-
this.files.set(fileUri, new Map());
204+
const fileUriStr = fileUri.toString();
205+
if (!this.files.has(fileUriStr)) {
206+
this.files.set(fileUriStr, new Map());
206207
}
207-
const fileHighlightings = this.files.get(fileUri);
208+
const fileHighlightings = this.files.get(fileUriStr);
208209
highlightingLines.forEach((line) => fileHighlightings.set(line.line, line));
209210
this.applyHighlights(fileUri);
210211
}
211212

212213
// Applies all the highlightings currently stored for a file with fileUri.
213-
public applyHighlights(fileUri: string) {
214-
if (!this.files.has(fileUri))
214+
public applyHighlights(fileUri: vscode.Uri) {
215+
const fileUriStr = fileUri.toString();
216+
if (!this.files.has(fileUriStr))
215217
// There are no highlightings for this file, must return early or will get
216218
// out of bounds when applying the decorations below.
217219
return;
@@ -224,35 +226,35 @@ export class Highlighter {
224226
// TextEditorDecorationType is used per scope.
225227
const ranges = this.getDecorationRanges(fileUri);
226228
vscode.window.visibleTextEditors.forEach((e) => {
227-
if (e.document.uri.toString() !== fileUri)
229+
if (e.document.uri.toString() !== fileUriStr)
228230
return;
229231
this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i]));
230232
});
231233
}
232234

233235
// Called when a text document is closed. Removes any highlighting entries for
234236
// the text document that was closed.
235-
public removeFileHighlightings(fileUri: string) {
237+
public removeFileHighlightings(fileUri: vscode.Uri) {
236238
// If there exists no entry the call to delete just returns false.
237-
this.files.delete(fileUri);
239+
this.files.delete(fileUri.toString());
238240
}
239241

240242
// Gets the uris as strings for the currently visible text editors.
241-
protected getVisibleTextEditorUris(): string[] {
242-
return vscode.window.visibleTextEditors.map((e) =>
243-
e.document.uri.toString());
243+
protected getVisibleTextEditorUris(): vscode.Uri[] {
244+
return vscode.window.visibleTextEditors.map((e) => e.document.uri);
244245
}
245246

246247
// Returns the ranges that should be used when decorating. Index i in the
247248
// range array has the decoration type at index i of this.decorationTypes.
248-
protected getDecorationRanges(fileUri: string): vscode.Range[][] {
249-
if (!this.files.has(fileUri))
249+
protected getDecorationRanges(fileUri: vscode.Uri): vscode.Range[][] {
250+
const fileUriStr = fileUri.toString();
251+
if (!this.files.has(fileUriStr))
250252
// this.files should always have an entry for fileUri if we are here. But
251253
// if there isn't one we don't want to crash the extension. This is also
252254
// useful for tests.
253255
return [];
254256
const lines: SemanticHighlightingLine[] =
255-
Array.from(this.files.get(fileUri).values());
257+
Array.from(this.files.get(fileUriStr).values());
256258
const decorations: vscode.Range[][] = this.decorationTypes.map(() => []);
257259
lines.forEach((line) => {
258260
line.tokens.forEach((token) => {

0 commit comments

Comments
 (0)