Skip to content
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

Dont get declaration diagnostics for file from referenced project #58333

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}

function getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): readonly DiagnosticWithLocation[] {
if (sourceFile && isSourceOfProjectReferenceRedirect(sourceFile.fileName)) return emptyArray;
sheetalkamat marked this conversation as resolved.
Show resolved Hide resolved
const options = program.getCompilerOptions();
// collect diagnostics from the program only once if either no source file was specified or out/outFile is set (bundled emit)
if (!sourceFile || options.outFile) {
Expand Down
62 changes: 60 additions & 2 deletions src/testRunner/unittests/tsserver/projectReferenceErrors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import * as ts from "../../_namespaces/ts";
import { dedent } from "../../_namespaces/Utils";
import { jsonToReadableText } from "../helpers";
import { libContent } from "../helpers/contents";
import {
baselineTsserverLogs,
GetErrForProjectDiagnostics,
openFilesForSession,
TestSession,
verifyGetErrScenario,
} from "../helpers/tsserver";
import { File } from "../helpers/virtualFileSystemWithWatch";
import {
File,
libFile,
TestServerHost,
} from "../helpers/virtualFileSystemWithWatch";

describe("unittests:: tsserver:: with project references and error reporting", () => {
describe("unittests:: tsserver:: projectReferenceErrors:: with project references and error reporting", () => {
const dependecyLocation = `/user/username/projects/myproject/dependency`;
const usageLocation = `/user/username/projects/myproject/usage`;

Expand Down Expand Up @@ -133,4 +143,52 @@ fnErr();
};
verifyUsageAndDependency("with non module", dependencyTs, dependencyConfig, usageTs, usageConfig);
});

it("when options for dependency project are different from usage project", () => {
const host = new TestServerHost({
"/home/src/projects/project/a/index.ts": dedent`
export function f2() {
return console.log()
}
`,
"/home/src/projects/project/a/tsconfig.json": jsonToReadableText({
compilerOptions: {
composite: true,
outDir: "../dist/a",
},
include: ["."],
}),
"/home/src/projects/project/b/index.ts": dedent`
import { f2 } from '../a/index.js'
export function f() {
f2()
return console.log('')
}
`,
"/home/src/projects/project/b/tsconfig.json": jsonToReadableText({
compilerOptions: {
composite: true,
isolatedDeclarations: true,
outDir: "../dist/b",
},
references: [{ path: "../a/" }],
include: ["."],
}),
[libFile.path]: libContent,
});
const session = new TestSession(host);
openFilesForSession(["/home/src/projects/project/b/index.ts"], session);

session.executeCommandSeq<ts.server.protocol.GeterrForProjectRequest>({
command: ts.server.protocol.CommandTypes.GeterrForProject,
arguments: { delay: 0, file: "/home/src/projects/project/b/index.ts" },
});
host.runQueuedTimeoutCallbacks();
host.runQueuedImmediateCallbacks();
host.runQueuedImmediateCallbacks();
host.runQueuedTimeoutCallbacks();
host.runQueuedImmediateCallbacks();
host.runQueuedImmediateCallbacks();
baselineTsserverLogs("projectReferenceErrors", "when options for dependency project are different from usage project", session);
});
});
Loading