Skip to content

Commit 1db1376

Browse files
authored
Dont get declaration diagnostics for file from referenced project (#58333)
1 parent f76727d commit 1db1376

File tree

3 files changed

+511
-3
lines changed

3 files changed

+511
-3
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import {
7070
getResolvedExternalModuleName,
7171
getSetAccessorValueParameter,
7272
getSourceFileOfNode,
73+
getSourceFilesToEmit,
7374
GetSymbolAccessibilityDiagnostic,
7475
getTextOfNode,
7576
getThisParameter,
@@ -214,7 +215,16 @@ import {
214215
/** @internal */
215216
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined {
216217
const compilerOptions = host.getCompilerOptions();
217-
const result = transformNodes(resolver, host, factory, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false);
218+
const files = filter(getSourceFilesToEmit(host, file), isSourceFileNotJson);
219+
const result = transformNodes(
220+
resolver,
221+
host,
222+
factory,
223+
compilerOptions,
224+
file ? contains(files, file) ? [file] : emptyArray : files,
225+
[transformDeclarations],
226+
/*allowDtsFiles*/ false,
227+
);
218228
return result.diagnostics;
219229
}
220230

src/testRunner/unittests/tsserver/projectReferenceErrors.ts

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
import * as ts from "../../_namespaces/ts";
2+
import { dedent } from "../../_namespaces/Utils";
13
import { jsonToReadableText } from "../helpers";
4+
import { libContent } from "../helpers/contents";
25
import {
6+
baselineTsserverLogs,
37
GetErrForProjectDiagnostics,
8+
openFilesForSession,
9+
TestSession,
410
verifyGetErrScenario,
511
} from "../helpers/tsserver";
6-
import { File } from "../helpers/virtualFileSystemWithWatch";
12+
import {
13+
File,
14+
libFile,
15+
TestServerHost,
16+
} from "../helpers/virtualFileSystemWithWatch";
717

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

@@ -133,4 +143,52 @@ fnErr();
133143
};
134144
verifyUsageAndDependency("with non module", dependencyTs, dependencyConfig, usageTs, usageConfig);
135145
});
146+
147+
it("when options for dependency project are different from usage project", () => {
148+
const host = new TestServerHost({
149+
"/home/src/projects/project/a/index.ts": dedent`
150+
export function f2() {
151+
return console.log()
152+
}
153+
`,
154+
"/home/src/projects/project/a/tsconfig.json": jsonToReadableText({
155+
compilerOptions: {
156+
composite: true,
157+
outDir: "../dist/a",
158+
},
159+
include: ["."],
160+
}),
161+
"/home/src/projects/project/b/index.ts": dedent`
162+
import { f2 } from '../a/index.js'
163+
export function f() {
164+
f2()
165+
return console.log('')
166+
}
167+
`,
168+
"/home/src/projects/project/b/tsconfig.json": jsonToReadableText({
169+
compilerOptions: {
170+
composite: true,
171+
isolatedDeclarations: true,
172+
outDir: "../dist/b",
173+
},
174+
references: [{ path: "../a/" }],
175+
include: ["."],
176+
}),
177+
[libFile.path]: libContent,
178+
});
179+
const session = new TestSession(host);
180+
openFilesForSession(["/home/src/projects/project/b/index.ts"], session);
181+
182+
session.executeCommandSeq<ts.server.protocol.GeterrForProjectRequest>({
183+
command: ts.server.protocol.CommandTypes.GeterrForProject,
184+
arguments: { delay: 0, file: "/home/src/projects/project/b/index.ts" },
185+
});
186+
host.runQueuedTimeoutCallbacks();
187+
host.runQueuedImmediateCallbacks();
188+
host.runQueuedImmediateCallbacks();
189+
host.runQueuedTimeoutCallbacks();
190+
host.runQueuedImmediateCallbacks();
191+
host.runQueuedImmediateCallbacks();
192+
baselineTsserverLogs("projectReferenceErrors", "when options for dependency project are different from usage project", session);
193+
});
136194
});

0 commit comments

Comments
 (0)