Currently there are two entry points for the `@angular/language-service` package: - `@angular/language-service` This default entry point is for View Engine LS. Through the redirection of `main` field in `package.json`, it resolves to `./bundles/language-service.js`. - `@angular/language-service/bundles/ivy.js` This secondary entry point is for Ivy LS. TypeScript recently changed the behavior of tsserver to allow only package names as plugin names [1] for security reasons. This means the secondary entry point for Ivy LS can no longer be used. We implemented a quick hack in the module resolver (in the extension repo) to fix this, but the long term fix should be in `@angular/language-service`. Here, the `main` field in `package.json` is changed to `index.js`, and in the index file we conditionally load View Engine or Ivy based on the input config. This eliminates the need for multiple entry points. As part of this PR, I also removed all source code for View Engine and Ivy included in the NPM package. Consumers of this package should run the bundled output and nothing else. This would help us prevent an accidental import that results in execution of unbundled code. [1]: https://github.com/microsoft/TypeScript/pull/42713 PR Close #40967
64 lines
1.9 KiB
TypeScript
64 lines
1.9 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 * as ts from 'typescript';
|
|
|
|
export interface NgLanguageServiceConfig {
|
|
/**
|
|
* If true, return only Angular results. Otherwise, return Angular + TypeScript
|
|
* results.
|
|
*/
|
|
angularOnly: boolean;
|
|
/**
|
|
* If true, return factory function for Ivy LS during plugin initialization.
|
|
* Otherwise return factory function for View Engine LS.
|
|
*/
|
|
ivy: boolean;
|
|
}
|
|
|
|
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[];
|
|
|
|
/**
|
|
* `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;
|
|
}
|
|
|
|
export function isNgLanguageService(ls: ts.LanguageService|
|
|
NgLanguageService): ls is NgLanguageService {
|
|
return 'getTcb' in ls;
|
|
}
|