8000 feat(language-service): support to report the deprecated API in the t… by ivanwonder · Pull Request #62054 · angular/angular · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

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
10 changes: 10 additions & 0 deletions packages/compiler-cli/src/ngtsc/perf/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export enum PerfPhase {
*/
TtcDiagnostics,

/**
* Time spent computing template type-checking suggestion diagnostics.
*/
TtcSuggestionDiagnostics,

/**
* Time spent getting a `Symbol` from the `TemplateTypeChecker`.
*/
Expand Down Expand Up @@ -138,6 +143,11 @@ export enum PerfPhase {
*/
LsDiagnostics,

/**
* Time spent by the Angular Language Service calculating suggestion diagnostics.
*/
LsSuggestionDiagnostics,

/**
* Time spent by the Angular Language Service calculating a "get component locations for template"
* operation.
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/ngtsc/typecheck/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type TypeCheckId = string & {__brand: 'TypeCheckId'};
* A `ts.Diagnostic` with additional information about the diagnostic related to template
* type-checking.
*/
export interface TemplateDiagnostic extends ts.Diagnostic {
export interface TemplateDiagnostic extends ts.DiagnosticWithLocation {
/**
* The component with the template that resulted in this diagnostic.
*/
Expand Down
24 changes: 24 additions & 0 deletions packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ export interface TemplateTypeChecker {
*/
getDiagnosticsForFile(sf: ts.SourceFile, optimizeFor: OptimizeFor): ts.Diagnostic[];

/**
* Gets suggestion diagnostics for the given `ts.SourceFile`. These diagnostics tend to
* proactively suggest deprecated, as opposed to diagnostics that indicate
* potentially incorrect runtime behavior.
*/
getSuggestionDiagnosticsForFile(
sf: ts.SourceFile,
tsLs: ts.LanguageService,
optimizeFor: OptimizeFor,
): ts.DiagnosticWithLocation[];

/**
* Given a `shim` and position within the file, returns information for mapping back to a source
* location.
Expand All @@ -109,6 +120,19 @@ export interface TemplateTypeChecker {
*/
getDiagnosticsForComponent(component: ts.ClassDeclaration): ts.Diagnostic[];

/**
* Gets suggestion diagnostics for the given component. These diagnostics tend to
* proactively suggest deprecated, as opposed to diagnostics that indicate
* potentially incorrect runtime behavior.
*
*
* This method always runs in `OptimizeFor.SingleFile` mode.
*/
getSuggestionDiagnosticsForComponent(
component: ts.ClassDeclaration,
tsLs: ts.LanguageService,
): ts.DiagnosticWithLocation[];

/**
* Ensures shims for the whole program are generated. This type of operation would be required by
* operations like "find references" and "refactor/rename" because references may appear in type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ import {
SourceMapping,
} from '../../api';

interface DeprecatedDiagnosticInfo {
reportsDeprecated: {} | undefined;
relatedMessages: ts.DiagnosticRelatedInformation[] | undefined;
}

/**
* Constructs a `ts.Diagnostic` for a given `ParseSourceSpan` within a template.
*
* @param deprecatedDiagInfo Optional information about deprecation and related messages.
*/
export function makeTemplateDiagnostic(
id: TypeCheckId,
Expand All @@ -34,11 +41,11 @@ export function makeTemplateDiagnostic(
end: number;
sourceFile: ts.SourceFile;
}[],
deprecatedDiagInfo?: DeprecatedDiagnosticInfo,
): TemplateDiagnostic {
if (mapping.type === 'direct') {
let relatedInformation: ts.DiagnosticRelatedInformation[] | undefined = undefined;
let relatedInformation: ts.DiagnosticRelatedInformation[] | undefined = [];
if (relatedMessages !== undefined) {
relatedInformation = [];
for (const relatedMessage of relatedMessages) {
relatedInformation.push({
category: ts.DiagnosticCategory.Message,
Expand All @@ -50,6 +57,11 @@ export function makeTemplateDiagnostic(
});
}
}

if (deprecatedDiagInfo !== undefined) {
relatedInformation.push(...(deprecatedDiagInfo.relatedMessages ?? []));
}

// For direct mappings, the error is shown inline as ngtsc was able to pinpoint a string
// constant within the `@Component` decorator for the template. This allows us to map the error
// directly into the bytes of the source file.
Expand All @@ -64,6 +76,7 @@ export function makeTemplateDiagnostic(
start: span.start.offset,
length: span.end.offset - span.start.offset,
relatedInformation,
reportsDeprecated: deprecatedDiagInfo?.reportsDeprecated,
};
} else if (mapping.type === 'indirect' || mapping.type === 'external') {
// For indirect mappings (template was declared inline, but ngtsc couldn't map it directly
Expand Down Expand Up @@ -114,9 +127,14 @@ export function makeTemplateDiagnostic(
start: mapping.node.getStart(),
length: mapping.node.getEnd() - mapping.node.getStart(),
relatedInformation,
reportsDeprecated: deprecatedDiagInfo?.reportsDeprecated,
};
}

if (deprecatedDiagInfo !== undefined) {
relatedInformation.push(...(deprecatedDiagInfo.relatedMessages ?? []));
}

relatedInformation.push({
category: ts.DiagnosticCategory.Message,
code: 0,
Expand All @@ -140,6 +158,7 @@ export function makeTemplateDiagnostic(
length: span.end.offset - span.start.offset,
// Show a secondary message indicating the component whose template contains the error.
relatedInformation,
reportsDeprecated: deprecatedDiagInfo?.reportsDeprecated,
};
} else {
throw new Error(`Unexpected source mapping type: ${(mapping as {type: string}).type}`);
Expand Down
Loading
0