Index: package.json =================================================================== --- package.json +++ package.json @@ -2,7 +2,7 @@ "name": "vscode-clangd", "displayName": "vscode-clangd", "description": "Clang Language Server", - "version": "0.0.18", + "version": "0.0.19", "publisher": "llvm-vs-code-extensions", "homepage": "https://clang.llvm.org/extra/clangd.html", "engines": { Index: src/semantic-highlighting.ts =================================================================== --- src/semantic-highlighting.ts +++ src/semantic-highlighting.ts @@ -114,17 +114,17 @@ this.loadCurrentTheme(); // Event handling for handling with TextDocuments/Editors lifetimes. this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors( - (editors: vscode.TextEditor[]) => - editors.forEach((e) => this.highlighter.applyHighlights( - e.document.uri.toString())))); + (editors: vscode.TextEditor[]) => editors.forEach( + (e) => this.highlighter.applyHighlights(e.document.uri)))); this.subscriptions.push(vscode.workspace.onDidCloseTextDocument( - (doc) => this.highlighter.removeFileHighlightings(doc.uri.toString()))); + (doc) => this.highlighter.removeFileHighlightings(doc.uri))); } handleNotification(params: SemanticHighlightingParams) { const lines: SemanticHighlightingLine[] = params.lines.map( (line) => ({line : line.line, tokens : decodeTokens(line.tokens)})); - this.highlighter.highlight(params.textDocument.uri, lines); + this.highlighter.highlight(vscode.Uri.parse(params.textDocument.uri), + lines); } // Disposes of all disposable resources used by this object. public dispose() { @@ -199,19 +199,21 @@ // Adds incremental highlightings to the current highlightings for the file // with fileUri. Also applies the highlightings to any associated // TextEditor(s). - public highlight(fileUri: string, + public highlight(fileUri: vscode.Uri, highlightingLines: SemanticHighlightingLine[]) { - if (!this.files.has(fileUri)) { - this.files.set(fileUri, new Map()); + const fileUriStr = fileUri.toString(); + if (!this.files.has(fileUriStr)) { + this.files.set(fileUriStr, new Map()); } - const fileHighlightings = this.files.get(fileUri); + const fileHighlightings = this.files.get(fileUriStr); highlightingLines.forEach((line) => fileHighlightings.set(line.line, line)); this.applyHighlights(fileUri); } // Applies all the highlightings currently stored for a file with fileUri. - public applyHighlights(fileUri: string) { - if (!this.files.has(fileUri)) + public applyHighlights(fileUri: vscode.Uri) { + const fileUriStr = fileUri.toString(); + if (!this.files.has(fileUriStr)) // There are no highlightings for this file, must return early or will get // out of bounds when applying the decorations below. return; @@ -224,7 +226,7 @@ // TextEditorDecorationType is used per scope. const ranges = this.getDecorationRanges(fileUri); vscode.window.visibleTextEditors.forEach((e) => { - if (e.document.uri.toString() !== fileUri) + if (e.document.uri.toString() !== fileUriStr) return; this.decorationTypes.forEach((d, i) => e.setDecorations(d, ranges[i])); }); @@ -232,27 +234,27 @@ // Called when a text document is closed. Removes any highlighting entries for // the text document that was closed. - public removeFileHighlightings(fileUri: string) { + public removeFileHighlightings(fileUri: vscode.Uri) { // If there exists no entry the call to delete just returns false. - this.files.delete(fileUri); + this.files.delete(fileUri.toString()); } // Gets the uris as strings for the currently visible text editors. - protected getVisibleTextEditorUris(): string[] { - return vscode.window.visibleTextEditors.map((e) => - e.document.uri.toString()); + protected getVisibleTextEditorUris(): vscode.Uri[] { + return vscode.window.visibleTextEditors.map((e) => e.document.uri); } // Returns the ranges that should be used when decorating. Index i in the // range array has the decoration type at index i of this.decorationTypes. - protected getDecorationRanges(fileUri: string): vscode.Range[][] { - if (!this.files.has(fileUri)) + protected getDecorationRanges(fileUri: vscode.Uri): vscode.Range[][] { + const fileUriStr = fileUri.toString(); + if (!this.files.has(fileUriStr)) // this.files should always have an entry for fileUri if we are here. But // if there isn't one we don't want to crash the extension. This is also // useful for tests. return []; const lines: SemanticHighlightingLine[] = - Array.from(this.files.get(fileUri).values()); + Array.from(this.files.get(fileUriStr).values()); const decorations: vscode.Range[][] = this.decorationTypes.map(() => []); lines.forEach((line) => { line.tokens.forEach((token) => {