-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Command to view template typecheck block
This patch adds a command to retrieve and display the typecheck block for a template under the user's active selections (if any), and highlights the span of the node(s) in the typecheck block that correspond to the template node under the user's active selection (if any). The typecheck block is made available via a dedicated text document provider that queries fresh typecheck block content whenever the `getTemplateTcb` command is invoked. See also angular/angular#39974, which provides the language service implementations needed for this feature.
- Loading branch information
Showing
9 changed files
with
239 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
export const ANGULAR_SCHEME = 'ng'; | ||
|
||
/** | ||
* Allocate a provider of documents corresponding to the `ng` URI scheme, | ||
* which we will use to provide a virtual document with the TCB contents. | ||
* | ||
* We use a virtual document provider rather than opening an untitled file to | ||
* ensure the buffer remains readonly (https://github.com/microsoft/vscode/issues/4873). | ||
*/ | ||
export class TcbContentProvider implements vscode.TextDocumentContentProvider { | ||
/** | ||
* Event emitter used to notify VSCode of a change to the TCB virtual document, | ||
* prompting it to re-evaluate the document content. This is needed to bust | ||
* VSCode's document cache if someone requests a TCB that was previously opened. | ||
* https://code.visualstudio.com/api/extension-guides/virtual-documents#update-virtual-documents | ||
*/ | ||
private readonly onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>(); | ||
/** | ||
* Name of the typecheck file. | ||
*/ | ||
private tcbFile: vscode.Uri|null = null; | ||
/** | ||
* Content of the entire typecheck file. | ||
*/ | ||
private tcbContent: string|null = null; | ||
|
||
/** | ||
* This callback is invoked only when user explicitly requests to view or | ||
* update typecheck file. We do not automatically update the typecheck document | ||
* when the source file changes. | ||
*/ | ||
readonly onDidChange = this.onDidChangeEmitter.event; | ||
|
||
provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): | ||
vscode.ProviderResult<string> { | ||
if (uri.toString() !== this.tcbFile?.toString()) { | ||
return null; | ||
} | ||
return this.tcbContent; | ||
} | ||
|
||
update(uri: vscode.Uri, content: string) { | ||
this.tcbFile = uri; | ||
this.tcbContent = content; | ||
this.onDidChangeEmitter.fire(uri); | ||
} | ||
|
||
clear() { | ||
this.tcbFile = null; | ||
this.tcbContent = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as lsp from 'vscode-languageserver-protocol'; | ||
|
||
export interface GetTcbParams { | ||
textDocument: lsp.TextDocumentIdentifier; | ||
position: lsp.Position; | ||
} | ||
|
||
export const GetTcbRequest = | ||
new lsp.RequestType<GetTcbParams, GetTcbResponse|null, /* error */ void>('angular/getTcb'); | ||
|
||
export interface GetTcbResponse { | ||
uri: lsp.DocumentUri; | ||
content: string; | ||
selections: lsp.Range[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters