Skip to content

Commit 3dd53d0

Browse files
committed
feat(language-service): Disable the rename provide in the built-in extension of vscode
If the Angular LS starts before the built-in TS/JS extension, the result is that renames will not work correctly from TS files in the Angular project. The plugin in this PR will reject the rename request for build-in TS/JS extension from vscode and the vscode will ask the Angular LS to provide the rename info.
1 parent 9a5ecd9 commit 3dd53d0

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

client/src/client.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,7 @@ export class AngularLanguageClient implements vscode.Disposable {
6565
prepareRename: async (
6666
document: vscode.TextDocument, position: vscode.Position,
6767
token: vscode.CancellationToken, next: lsp.PrepareRenameSignature) => {
68-
// We are able to provide renames for many types of string literals: template strings,
69-
// pipe names, and hopefully in the future selectors and input/output aliases. Because
70-
// TypeScript isn't able to provide renames for these, we can more or less
71-
// guarantee that the Angular Language service will be called for the rename as the
72-
// fallback. We specifically do not provide renames outside of string literals
73-
// because we cannot ensure our extension is prioritized for renames in TS files (see
74-
// https://github.com/microsoft/vscode/issues/115354) we disable renaming completely so we
75-
// can provide consistent expectations.
76-
if (await this.isInAngularProject(document) &&
77-
isInsideStringLiteral(document, position)) {
68+
if (await this.isInAngularProject(document)) {
7869
return next(document, position, token);
7970
}
8071
},

override_rename_ts_plugin/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
If the Angular LS starts before the built-in TS/JS extension, the result is that renames will not work correctly from TS files in the Angular project. This plugin will reject the rename request for build-in TS/JS extension from vscode and the vscode will ask the Angular LS to provide the rename info.
2+
3+
See [here](https://github.com/microsoft/vscode/issues/115354) for more info

override_rename_ts_plugin/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
module.exports = require("@angular/language-service/override_rename_ts_plugin").factory;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@angular/override-rename-ts-plugin",
3+
"version": "0.0.1",
4+
"main": "./index.js",
5+
"private": "true"
6+
}

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@
165165
"path": "./syntaxes/expression.json",
166166
"scopeName": "expression.ng"
167167
}
168+
],
169+
"typescriptServerPlugins": [
170+
{
171+
"name": "@angular/override-rename-ts-plugin",
172+
"enableForWorkspaceTypeScriptVersions": true
173+
}
168174
]
169175
},
170176
"activationEvents": [
@@ -188,6 +194,7 @@
188194
"test:syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
189195
},
190196
"dependencies": {
197+
"@angular/override-rename-ts-plugin": "file:override_rename_ts_plugin",
191198
"@angular/language-service": "14.0.0-next.0",
192199
"typescript": "4.5.4",
193200
"vscode-jsonrpc": "6.0.0",

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cp package.json angular.png CHANGELOG.md README.md dist/npm
5353
# Copy files to server directory
5454
cp -r server/package.json server/README.md server/bin dist/npm/server
5555
cp -r v12_language_service dist/npm/v12_language_service
56+
cp -r override_rename_ts_plugin dist/npm/override_rename_ts_plugin
5657
# Build and copy files to syntaxes directory
5758
yarn run build:syntaxes
5859
mkdir dist/npm/syntaxes

yarn.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-14.0.0-next.0.tgz#644e73e03810559079c29192c0eb1f59c2dfbd11"
5858
integrity sha512-jiN1XQQI4sFWUIsDpBQtWNLDCoYfAYwDG/LQqjmgR1yAgDEKQDZRHEbbccDVgcWp7jI3H0QRv9mUE9XlfjJZPg==
5959

60+
"@angular/override-rename-ts-plugin@file:override_rename_ts_plugin":
61+
version "0.0.1"
62+
6063
"@babel/code-frame@^7.0.0":
6164
version "7.12.13"
6265
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.13.tgz#dcfc826beef65e75c50e21d3837d7d95798dd658"

0 commit comments

Comments
 (0)