MCPcopy Create free account
hub / github.com/angular/angular / getTemplateTcb

Function getTemplateTcb

vscode-ng-language-service/client/src/commands.ts:89–127  ·  view source on GitHub ↗

* Command getTemplateTcb displays a typecheck block for the template a user has * an active selection over, if any. * @param ngClient LSP client for the active session * @param context extension context to which disposables are pushed

(
  ngClient: AngularLanguageClient,
  context: vscode.ExtensionContext,
)

Source from the content-addressed store, hash-verified

87 * @param context extension context to which disposables are pushed
88 */
89function getTemplateTcb(
90 ngClient: AngularLanguageClient,
91 context: vscode.ExtensionContext,
92): Command {
93 const TCB_HIGHLIGHT_DECORATION = vscode.window.createTextEditorDecorationType({
94 // See https://code.visualstudio.com/api/references/theme-color#editor-colors
95 backgroundColor: new vscode.ThemeColor('editor.selectionHighlightBackground'),
96 });
97
98 const tcbProvider = new TcbContentProvider();
99 const disposable = vscode.workspace.registerTextDocumentContentProvider(
100 ANGULAR_SCHEME,
101 tcbProvider,
102 );
103 context.subscriptions.push(disposable);
104
105 return {
106 id: 'angular.getTemplateTcb',
107 isTextEditorCommand: true,
108 async execute(textEditor: vscode.TextEditor) {
109 tcbProvider.clear();
110 const response = await ngClient.getTcbUnderCursor(textEditor);
111 if (response === undefined) {
112 return undefined;
113 }
114 // Change the scheme of the URI from `file` to `ng` so that the document
115 // content is requested from our own `TcbContentProvider`.
116 const tcbUri = response.uri.with({
117 scheme: ANGULAR_SCHEME,
118 });
119 tcbProvider.update(tcbUri, response.content);
120 const editor = await vscode.window.showTextDocument(tcbUri, {
121 viewColumn: vscode.ViewColumn.Beside,
122 preserveFocus: true, // cursor remains in the active editor
123 });
124 editor.setDecorations(TCB_HIGHLIGHT_DECORATION, response.selections);
125 },
126 };
127}
128
129/**
130 * Command goToComponentWithTemplateFile finds components which reference an external template in

Callers 1

registerCommandsFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected