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 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
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);
sheetalkamat marked this conversation as resolved.
Show resolved Hide resolved
const result = transformNodes(
resolver,
host,
factory,
compilerOptions,
file ? contains(files, file) ? [file] : emptyArray : files,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readability nit, but I have a real hard time trying to read this one; is there another way to put this?

let files = filter(getSourceFilesToEmit(host, file), isSourceFileNotJson);
if (file) {
   files = contains(files, file) ? [file] : emptyArray;
}

Maybe? If not, no worries, I just have problems reading ternaries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry its hard to read for you. I prefer consts over let for this. Do you think having it multi line will be more readable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine as it is, no worries.

[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