mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
When the `ts.Project` creates the language service plugin (in this case, the Angular Language Service), it sets the project's language service to the new language service returned by the plugin create: https://sourcegraph.com/github.com/microsoft/TypeScript@b12af0fa2bbd4b015e59adcfb49988cea7f919a1/-/blob/src/server/project.ts?L2035-2044 The project may be reloaded in response to various events, such as a change to the tsconfig file, which then recreates the plugin. When this happens, the language service that gets passed to the plugin `create` function will not be the typescript language service, but rather the previous instance of the new language service returned by the last call to `create`. This commit ensures that subsequent calls to `create` for the `NgLanguageService` plugin for a project after the first call are able to retrieve and hold on to the _TypeScript_ language service. fixes https://github.com/angular/vscode-ng-language-service/issues/1923 PR Close #51912
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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
|
|
*/
|
|
|
|
/**
|
|
* @module
|
|
* @description
|
|
* Entry point for all public APIs of the language service package.
|
|
*/
|
|
|
|
import ts from 'typescript';
|
|
|
|
export interface PluginConfig {
|
|
/**
|
|
* If true, return only Angular results. Otherwise, return Angular + TypeScript
|
|
* results.
|
|
*/
|
|
angularOnly: boolean;
|
|
/**
|
|
* If true, enable `strictTemplates` in Angular compiler options regardless
|
|
* of its value in tsconfig.json.
|
|
*/
|
|
forceStrictTemplates?: true;
|
|
}
|
|
|
|
export type GetTcbResponse = {
|
|
/**
|
|
* The filename of the SourceFile this typecheck block belongs to.
|
|
* The filename is entirely opaque and unstable, useful only for debugging
|
|
* purposes.
|
|
*/
|
|
fileName: string,
|
|
/** The content of the SourceFile this typecheck block belongs to. */
|
|
content: string,
|
|
/**
|
|
* Spans over node(s) in the typecheck block corresponding to the
|
|
* TS code generated for template node under the current cursor position.
|
|
*
|
|
* When the cursor position is over a source for which there is no generated
|
|
* code, `selections` is empty.
|
|
*/
|
|
selections: ts.TextSpan[],
|
|
};
|
|
|
|
export type GetComponentLocationsForTemplateResponse = ts.DocumentSpan[];
|
|
export type GetTemplateLocationForComponentResponse = ts.DocumentSpan|undefined;
|
|
|
|
/**
|
|
* `NgLanguageService` describes an instance of an Angular language service,
|
|
* whose API surface is a strict superset of TypeScript's language service.
|
|
*/
|
|
export interface NgLanguageService extends ts.LanguageService {
|
|
getTcb(fileName: string, position: number): GetTcbResponse|undefined;
|
|
getComponentLocationsForTemplate(fileName: string): GetComponentLocationsForTemplateResponse;
|
|
getTemplateLocationForComponent(fileName: string, position: number):
|
|
GetTemplateLocationForComponentResponse;
|
|
getTypescriptLanguageService(): ts.LanguageService;
|
|
}
|
|
|
|
export function isNgLanguageService(ls: ts.LanguageService|
|
|
NgLanguageService): ls is NgLanguageService {
|
|
return 'getTcb' in ls;
|
|
}
|