Skip to content

Commit 69ceb25

Browse files
ivanwonderatscott
authored andcommitted
feat(language-service): support to report the deprecated API in the template
In the Typescript Language Service, these diagnostics are reported as suggestion diagnostics. This will report the deprecated `Component`, `Directive`, etc.
1 parent 641f878 commit 69ceb25

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=974837034
5-
pnpm-lock.yaml=1752070694
6-
yarn.lock=1122184668
7-
package.json=-1728624161
5+
pnpm-lock.yaml=400619548
6+
yarn.lock=-443465396
7+
package.json=-2035752261
88
pnpm-workspace.yaml=1711114604

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
"test:legacy-syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine dist/syntaxes/test/driver.js"
270270
},
271271
"dependencies": {
272-
"@angular/language-service": "20.1.0-rc.0",
272+
"@angular/language-service": "20.2.0-next.3",
273273
"typescript": "^5.8.1",
274274
"vscode-html-languageservice": "^4.2.5",
275275
"vscode-jsonrpc": "6.0.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ngserver": "./bin/ngserver"
1616
},
1717
"dependencies": {
18-
"@angular/language-service": "20.1.0-rc.0",
18+
"@angular/language-service": "20.2.0-next.3",
1919
"vscode-html-languageservice": "^4.2.5",
2020
"vscode-jsonrpc": "6.0.0",
2121
"vscode-languageserver": "7.0.0",

server/src/diagnostic.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@ function tsDiagnosticCategoryToLspDiagnosticSeverity(category: ts.DiagnosticCate
3535
* @param scriptInfo Used to compute proper offset.
3636
*/
3737
export function tsDiagnosticToLspDiagnostic(
38-
tsDiag: ts.Diagnostic, scriptInfo: ts.server.ScriptInfo): lsp.Diagnostic {
38+
tsDiag: ts.Diagnostic, projectService: ts.server.ProjectService): lsp.Diagnostic {
3939
const textSpan: ts.TextSpan = {
4040
start: tsDiag.start || 0,
4141
length: tsDiag.length || 0,
4242
};
43-
return lsp.Diagnostic.create(
44-
tsTextSpanToLspRange(scriptInfo, textSpan),
45-
ts.flattenDiagnosticMessageText(tsDiag.messageText, '\n'),
46-
tsDiagnosticCategoryToLspDiagnosticSeverity(tsDiag.category),
47-
tsDiag.code,
48-
tsDiag.source,
49-
tsRelatedInformationToLspRelatedInformation(scriptInfo, tsDiag.relatedInformation),
50-
);
43+
44+
const diagScriptInfo =
45+
tsDiag.file !== undefined ? projectService.getScriptInfo(tsDiag.file.fileName) : undefined;
46+
const range = diagScriptInfo !== undefined ? tsTextSpanToLspRange(diagScriptInfo, textSpan) :
47+
lsp.Range.create(0, 0, 0, 0);
48+
const diag = lsp.Diagnostic.create(
49+
range, ts.flattenDiagnosticMessageText(tsDiag.messageText, '\n'),
50+
tsDiagnosticCategoryToLspDiagnosticSeverity(tsDiag.category), tsDiag.code, tsDiag.source,
51+
tsRelatedInformationToLspRelatedInformation(projectService, tsDiag.relatedInformation));
52+
diag.tags = tsDiag.reportsDeprecated !== undefined ? [lsp.DiagnosticTag.Deprecated] : undefined;
53+
54+
return diag;
5155
}

server/src/session.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,21 @@ export class Session {
710710
if (isDebugMode) {
711711
console.timeEnd(label);
712712
}
713+
714+
const suggestionLabel = `${reason} - getSuggestionDiagnostics for ${fileName}`;
715+
if (isDebugMode) {
716+
console.time(suggestionLabel);
717+
}
718+
diagnostics.push(...result.languageService.getSuggestionDiagnostics(fileName));
719+
if (isDebugMode) {
720+
console.timeEnd(suggestionLabel);
721+
}
722+
713723
// Need to send diagnostics even if it's empty otherwise editor state will
714724
// not be updated.
715725
this.connection.sendDiagnostics({
716726
uri: filePathToUri(fileName),
717-
diagnostics: diagnostics.map(d => tsDiagnosticToLspDiagnostic(d, result.scriptInfo)),
727+
diagnostics: diagnostics.map(d => tsDiagnosticToLspDiagnostic(d, this.projectService)),
718728
});
719729
if (this.diagnosticsTimeout) {
720730
// There is a pending request to check diagnostics for all open files,

server/src/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ export function lspRangeToTsPositions(
113113
* @param relatedInfo
114114
*/
115115
export function tsRelatedInformationToLspRelatedInformation(
116-
scriptInfo: ts.server.ScriptInfo,
116+
projectService: ts.server.ProjectService,
117117
relatedInfo?: ts.DiagnosticRelatedInformation[]): lsp.DiagnosticRelatedInformation[]|undefined {
118118
if (relatedInfo === undefined) return;
119119
const lspRelatedInfo: lsp.DiagnosticRelatedInformation[] = [];
120120
for (const info of relatedInfo) {
121121
if (info.file === undefined || info.start === undefined || info.length === undefined) continue;
122+
const scriptInfo = projectService.getScriptInfo(info.file.fileName);
123+
if (scriptInfo === undefined) continue;
122124
const textSpan: ts.TextSpan = {
123125
start: info.start,
124126
length: info.length,

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@
173173
uuid "^8.3.2"
174174
yargs "^17.0.0"
175175

176-
"@angular/language-service@20.1.0-rc.0":
177-
version "20.1.0-rc.0"
178-
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-20.1.0-rc.0.tgz#6d4e8a45e6716410778f42ce8c0d54e3e7912d02"
179-
integrity sha512-8iXIiBGOD4fUulzhH1yEZIQhlwTsY3Kbj1N8wpS1uV1sH2DSgHNq4WR5k3fQYUx7VYbF3VyTCjdBzjh7s2Xcsg==
176+
"@angular/language-service@20.2.0-next.3":
177+
version "20.2.0-next.3"
178+
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-20.2.0-next.3.tgz#9090992ec15dee68c85091cedc109abf0d934009"
179+
integrity sha512-PveyzuR4PsuHLIRr2OfzatsRj6G3kzjU/EBiMgFjvWn8xsC+VJmiuvaEReLBtOoAuGnXA7pmeWyjrDFr5lNNQA==
180180

181181
"@assemblyscript/loader@^0.10.1":
182182
version "0.10.1"

0 commit comments

Comments
 (0)