mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
acf98268f8
The Angular Language Service package is now tested & compiled using ESM. Previously it was a mismatch of CommonJS and ESM. Still the language-service ESM output is transformed into a single UMD bundle to allow for module resolution to be overriden. See `bundles/BUILD`. This is kept as is. To fully ship ESM (language-service is an exception here), we need to: * Update all code to no longer reference typescript via import. Instead typescript needs to be passed around so that the extension can control the version * The VSCode extension/ the TS server needs to be able to load ESM. It looks like the server supports ESM global plugins, but the extension might not yet. This is out of scope for the dev-infra effort as it requires more insight into VSCode & the extension system & the TS language server. PR Close #48521
59 lines
1.9 KiB
TypeScript
59 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
|
|
*/
|
|
|
|
import ts from 'typescript/lib/tsserverlibrary';
|
|
|
|
function isAngularCore(path: string): boolean {
|
|
return isExternalAngularCore(path) || isInternalAngularCore(path);
|
|
}
|
|
|
|
function isExternalAngularCore(path: string): boolean {
|
|
return path.endsWith('@angular/core/core.d.ts') || path.endsWith('@angular/core/index.d.ts');
|
|
}
|
|
|
|
function isInternalAngularCore(path: string): boolean {
|
|
return path.endsWith('angular2/rc/packages/core/index.d.ts');
|
|
}
|
|
|
|
/**
|
|
* This factory is used to disable the built-in rename provider,
|
|
* see `packages/language-service/README.md#override-rename-ts-plugin` for more info.
|
|
*/
|
|
const factory: ts.server.PluginModuleFactory = (): ts.server.PluginModule => {
|
|
return {
|
|
create(info: ts.server.PluginCreateInfo): ts.LanguageService {
|
|
const {project, languageService} = info;
|
|
/** A map that indicates whether Angular could be found in the file's project. */
|
|
const fileToIsInAngularProjectMap = new Map<string, boolean>();
|
|
|
|
return {
|
|
...languageService,
|
|
getRenameInfo: (fileName, position) => {
|
|
let isInAngular: boolean;
|
|
if (fileToIsInAngularProjectMap.has(fileName)) {
|
|
isInAngular = fileToIsInAngularProjectMap.get(fileName)!;
|
|
} else {
|
|
isInAngular = project.getFileNames().some(isAngularCore);
|
|
fileToIsInAngularProjectMap.set(fileName, isInAngular);
|
|
}
|
|
if (isInAngular) {
|
|
return {
|
|
canRename: false,
|
|
localizedErrorMessage: 'Delegating rename to the Angular Language Service.',
|
|
};
|
|
} else {
|
|
return languageService.getRenameInfo(fileName, position);
|
|
}
|
|
},
|
|
};
|
|
}
|
|
};
|
|
};
|
|
|
|
export {factory};
|