Skip to content

feat(language-service): support to report the deprecated API in the t… #2192

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions server/src/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ function tsDiagnosticCategoryToLspDiagnosticSeverity(category: ts.DiagnosticCate
* @param scriptInfo Used to compute proper offset.
*/
export function tsDiagnosticToLspDiagnostic(
tsDiag: ts.Diagnostic, scriptInfo: ts.server.ScriptInfo): lsp.Diagnostic {
tsDiag: ts.Diagnostic, projectService: ts.server.ProjectService): lsp.Diagnostic {
const textSpan: ts.TextSpan = {
start: tsDiag.start || 0,
length: tsDiag.length || 0,
};
return lsp.Diagnostic.create(
tsTextSpanToLspRange(scriptInfo, textSpan),
ts.flattenDiagnosticMessageText(tsDiag.messageText, '\n'),
tsDiagnosticCategoryToLspDiagnosticSeverity(tsDiag.category),
tsDiag.code,
tsDiag.source,
tsRelatedInformationToLspRelatedInformation(scriptInfo, tsDiag.relatedInformation),
);

const diagScriptInfo =
tsDiag.file !== undefined ? projectService.getScriptInfo(tsDiag.file.fileName) : undefined;
const range = diagScriptInfo !== undefined ? tsTextSpanToLspRange(diagScriptInfo, textSpan) :
lsp.Range.create(0, 0, 0, 0);
const diag = lsp.Diagnostic.create(
range, ts.flattenDiagnosticMessageText(tsDiag.messageText, '\n'),
tsDiagnosticCategoryToLspDiagnosticSeverity(tsDiag.category), tsDiag.code, tsDiag.source,
tsRelatedInformationToLspRelatedInformation(projectService, tsDiag.relatedInformation));
diag.tags = tsDiag.reportsDeprecated !== undefined ? [lsp.DiagnosticTag.Deprecated] : undefined;

return diag;
}
12 changes: 11 additions & 1 deletion server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,11 +710,21 @@ export class Session {
if (isDebugMode) {
console.timeEnd(label);
}

const suggestionLabel = `${reason} - getSuggestionDiagnostics for ${fileName}`;
if (isDebugMode) {
console.time(suggestionLabel);
}
diagnostics.push(...result.languageService.getSuggestionDiagnostics(fileName));
if (isDebugMode) {
console.timeEnd(suggestionLabel);
}

// Need to send diagnostics even if it's empty otherwise editor state will
// not be updated.
this.connection.sendDiagnostics({
uri: filePathToUri(fileName),
diagnostics: diagnostics.map(d => tsDiagnosticToLspDiagnostic(d, result.scriptInfo)),
diagnostics: diagnostics.map(d => tsDiagnosticToLspDiagnostic(d, this.projectService)),
});
if (this.diagnosticsTimeout) {
// There is a pending request to check diagnostics for all open files,
Expand Down
4 changes: 3 additions & 1 deletion server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ export function lspRangeToTsPositions(
* @param relatedInfo
*/
export function tsRelatedInformationToLspRelatedInformation(
scriptInfo: ts.server.ScriptInfo,
projectService: ts.server.ProjectService,
relatedInfo?: ts.DiagnosticRelatedInformation[]): lsp.DiagnosticRelatedInformation[]|undefined {
if (relatedInfo === undefined) return;
const lspRelatedInfo: lsp.DiagnosticRelatedInformation[] = [];
for (const info of relatedInfo) {
if (info.file === undefined || info.start === undefined || info.length === undefined) continue;
const scriptInfo = projectService.getScriptInfo(info.file.fileName);
if (scriptInfo === undefined) continue;
const textSpan: ts.TextSpan = {
start: info.start,
length: info.length,
Expand Down
Loading