Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): use single entry point for Ivy and View Engine #40967

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/language-service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ ts_library(
name = "api",
srcs = [
"api.ts",
"index.ts",
],
deps = [
"@npm//@types/node",
kyliau marked this conversation as resolved.
Show resolved Hide resolved
"@npm//typescript",
],
)

ts_library(
name = "language-service",
srcs = ["index.ts"] + glob(
srcs = glob(
[
"src/**/*.ts",
],
Expand Down Expand Up @@ -54,8 +56,7 @@ pkg_npm(
"//integration:__pkg__",
],
deps = [
":language-service",
"//packages/language-service/ivy",
":api",
# min bundle is not used at the moment; omit from package to speed up build
"//packages/language-service/bundles:language-service.js",
"//packages/language-service/bundles:ivy.js",
Expand Down
13 changes: 13 additions & 0 deletions packages/language-service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

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.
Expand Down
2 changes: 1 addition & 1 deletion packages/language-service/bundles/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("//dev-infra/benchmark/ng_rollup_bundle:ng_rollup_bundle.bzl", "ng_rollup_b
ng_rollup_bundle(
name = "language-service",
build_optimizer = False,
entry_point = "//packages/language-service:index.ts",
entry_point = "//packages/language-service:src/ts_plugin.ts",
format = "amd",
globals = {
"fs": "fs",
Expand Down
30 changes: 29 additions & 1 deletion packages/language-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,33 @@
* found in the LICENSE file at https://angular.io/license
*/

import * as ts from 'typescript/lib/tsserverlibrary';
import {NgLanguageService, NgLanguageServiceConfig} from './api';

export * from './api';
export {create, getExternalFiles} from './src/ts_plugin';

interface PluginModule extends ts.server.PluginModule {
create(createInfo: ts.server.PluginCreateInfo): NgLanguageService;
onConfigurationChanged?(config: NgLanguageServiceConfig): void;
}

const factory: ts.server.PluginModuleFactory = (tsModule): PluginModule => {
let plugin: PluginModule;

return {
create(info: ts.server.PluginCreateInfo): NgLanguageService {
const config: NgLanguageServiceConfig = info.config;
const bundleName = config.ivy ? 'ivy.js' : 'language-service.js';
plugin = require(`./bundles/${bundleName}`)(tsModule);
return plugin.create(info);
},
getExternalFiles(project: ts.server.Project): string[] {
return plugin?.getExternalFiles?.(project) ?? [];
},
onConfigurationChanged(config: NgLanguageServiceConfig): void {
plugin?.onConfigurationChanged?.(config);
},
};
};

module.exports = factory;
2 changes: 1 addition & 1 deletion packages/language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@angular/language-service",
"version": "0.0.0-PLACEHOLDER",
"description": "Angular - language services",
"main": "./bundles/language-service.js",
"main": "./index.js",
"typings": "./index.d.ts",
"author": "angular",
"license": "MIT",
Expand Down