angular/packages/language-service
Andrew Scott 08482f2c7d fix(language-service): Retain correct language service when ts.Project reloads (#51912)
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
2023-10-04 11:27:43 -07:00
..
bundles build: switch all instances from ng_rollup_bundle to app_bundle (#44490) 2022-01-04 12:14:14 -08:00
src fix(language-service): Retain correct language service when ts.Project reloads (#51912) 2023-10-04 11:27:43 -07:00
test feat(language-service): Enable go to definition of styleUrl (#51746) 2023-09-18 10:37:19 +02:00
testing feat(core): support TypeScript 5.2 (#51334) 2023-08-18 07:55:16 -07:00
api.ts fix(language-service): Retain correct language service when ts.Project reloads (#51912) 2023-10-04 11:27:43 -07:00
BUILD.bazel fix(language-service): ship /api entry-point (#48670) 2023-01-09 10:13:34 -08:00
build.sh fix(language-service): update packages/language-service/build.sh script to work with vscode-ng-language-service's new Bazel build (#48663) 2023-01-09 10:13:06 -08:00
index.d.ts refactor: update language-service package and tests to work with ESM (#48521) 2022-12-19 19:50:44 +00:00
index.js refactor: update language-service package and tests to work with ESM (#48521) 2022-12-19 19:50:44 +00:00
override_rename_ts_plugin.ts refactor: update language-service package and tests to work with ESM (#48521) 2022-12-19 19:50:44 +00:00
package.json build: remove support for Node.js v16 (#51755) 2023-09-13 10:49:06 -07:00
plugin-factory.ts refactor: update language-service package and tests to work with ESM (#48521) 2022-12-19 19:50:44 +00:00
README.md feat(language-service): Provide plugin to delegate rename requests to Angular (#44696) 2022-01-21 11:18:48 -08:00

Override Rename Ts Plugin

When the user wants to rename a symbol in the ts file VSCode will ask the rename providers for the answer in turn. If the first extension returns the result, the VSCode will break the loop and apply the result. If the first extension cannot rename the symbol, VSCode will ask the second extension in the list (built-in TS/JS extension, Angular LS extension, etc.). In other words, VSCode takes the result from only one rename provider and the order depends on registration timing, scoring.

Because the built-in ts extension and Angular extension have the same high score, if the built-in ts extension is the first(depends on the time the extension was registered), the result will be provided by the built-in extension. We want Angular to provide it, so this plugin will delegate rename requests and reject the request for the built-in ts server.

The Angular LS only provides the rename info when working within an Angular project. If we cannot locate Angular sources in the project files, the built-in extension should provide the rename info.

This plugin will apply to the built-in TS/JS extension and delegate rename requests to the Angular LS. It provides the rename info only when it is an Angular project. Otherwise, it will return info by the default built-in ts server rename provider.

See here for more info.