Skip to content

Don't compute suggestion diagnostics for lib files #26289

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

Merged
merged 1 commit into from
Aug 10, 2018
Merged
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
9 changes: 5 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ namespace ts {
return node && getTypeArgumentConstraint(node);
},
getSuggestionDiagnostics: (file, ct) => {
if (skipTypeChecking(file, compilerOptions)) {
return emptyArray;
}

let diagnostics: DiagnosticWithLocation[] | undefined;
try {
// Record the cancellation token so it can be checked later on during checkSourceElement.
Expand Down Expand Up @@ -26876,10 +26880,7 @@ namespace ts {
function checkSourceFileWorker(node: SourceFile) {
const links = getNodeLinks(node);
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
// If skipLibCheck is enabled, skip type checking if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip type checking if file contains a
// '/// <reference no-default-lib="true"/>' directive.
if (compilerOptions.skipLibCheck && node.isDeclarationFile || compilerOptions.skipDefaultLibCheck && node.hasNoDefaultLib) {
if (skipTypeChecking(node, compilerOptions)) {
return;
}

Expand Down
5 changes: 1 addition & 4 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,7 @@ namespace ts {

function getSemanticDiagnosticsForFileNoCache(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] | undefined {
return runWithCancellationToken(() => {
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
// '/// <reference no-default-lib="true"/>' directive.
if (options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib) {
if (skipTypeChecking(sourceFile, options)) {
return emptyArray;
}

Expand Down
7 changes: 7 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8212,4 +8212,11 @@ namespace ts {
// Include the `<>`
return { pos: typeParameters.pos - 1, end: typeParameters.end + 1 };
}

export function skipTypeChecking(sourceFile: SourceFile, options: CompilerOptions) {
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
// '/// <reference no-default-lib="true"/>' directive.
return options.skipLibCheck && sourceFile.isDeclarationFile || options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib;
}
}