Skip to content

Commit

Permalink
Dont get declaration diagnostics for file from referenced project (#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Apr 26, 2024
1 parent f76727d commit 1db1376
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
getResolvedExternalModuleName,
getSetAccessorValueParameter,
getSourceFileOfNode,
getSourceFilesToEmit,
GetSymbolAccessibilityDiagnostic,
getTextOfNode,
getThisParameter,
Expand Down Expand Up @@ -214,7 +215,16 @@ import {
/** @internal */
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined {
const compilerOptions = host.getCompilerOptions();
const result = transformNodes(resolver, host, factory, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false);
const files = filter(getSourceFilesToEmit(host, file), isSourceFileNotJson);
const result = transformNodes(
resolver,
host,
factory,
compilerOptions,
file ? contains(files, file) ? [file] : emptyArray : files,
[transformDeclarations],
/*allowDtsFiles*/ false,
);
return result.diagnostics;
}

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);
});
});

0 comments on commit 1db1376

Please sign in to comment.