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 3 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
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 @@
getResolvedExternalModuleName,
getSetAccessorValueParameter,
getSourceFileOfNode,
getSourceFilesToEmit,
GetSymbolAccessibilityDiagnostic,
getTextOfNode,
getThisParameter,
Expand Down Expand Up @@ -184,6 +185,7 @@
setTextRange,
some,
SourceFile,
sourceFileMayBeEmitted,

Check warning on line 188 in src/compiler/transformers/declarations.ts

View workflow job for this annotation

GitHub Actions / lint

'sourceFileMayBeEmitted' is defined but never used. Allowed unused vars must match /^(_+$|_[^_])/u
Statement,
StringLiteral,
Symbol,
Expand Down Expand Up @@ -214,7 +216,15 @@
/** @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 result = transformNodes(
resolver,
host,
factory,
compilerOptions,
filter(getSourceFilesToEmit(host, file), isSourceFileNotJson),
[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);
});
});
Loading
Loading