mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 19:27:35 -06:00
Fix detecting default project when file is part for more than one project but not part of default configured project (eg because its output of that projet) (#38429)
Fixes #38366
This commit is contained in:
parent
3f06adf662
commit
5d6a5d04ea
@ -1743,7 +1743,9 @@ namespace ts.server {
|
||||
|
||||
return project?.isSolution() ?
|
||||
project.getDefaultChildProjectFromSolution(info) :
|
||||
project;
|
||||
project && projectContainsInfoDirectly(project, info) ?
|
||||
project :
|
||||
undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -15,6 +15,13 @@ namespace ts.tscWatch {
|
||||
return ts.createSolutionBuilder(host, rootNames, defaultOptions || {});
|
||||
}
|
||||
|
||||
export function ensureErrorFreeBuild(host: WatchedSystem, rootNames: readonly string[]) {
|
||||
// ts build should succeed
|
||||
const solutionBuilder = createSolutionBuilder(host, rootNames, {});
|
||||
solutionBuilder.build();
|
||||
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
|
||||
}
|
||||
|
||||
type OutputFileStamp = [string, Date | undefined, boolean];
|
||||
function transformOutputToOutputFileStamp(f: string, host: TsBuildWatchSystem): OutputFileStamp {
|
||||
return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp;
|
||||
|
||||
@ -1050,6 +1050,64 @@ declare var console: {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("when default configured project does not contain the file", () => {
|
||||
const barConfig: File = {
|
||||
path: `${tscWatch.projectRoot}/bar/tsconfig.json`,
|
||||
content: "{}"
|
||||
};
|
||||
const barIndex: File = {
|
||||
path: `${tscWatch.projectRoot}/bar/index.ts`,
|
||||
content: `import {foo} from "../foo/lib";
|
||||
foo();`
|
||||
};
|
||||
const fooBarConfig: File = {
|
||||
path: `${tscWatch.projectRoot}/foobar/tsconfig.json`,
|
||||
content: barConfig.path
|
||||
};
|
||||
const fooBarIndex: File = {
|
||||
path: `${tscWatch.projectRoot}/foobar/index.ts`,
|
||||
content: barIndex.content
|
||||
};
|
||||
const fooConfig: File = {
|
||||
path: `${tscWatch.projectRoot}/foo/tsconfig.json`,
|
||||
content: JSON.stringify({
|
||||
include: ["index.ts"],
|
||||
compilerOptions: {
|
||||
declaration: true,
|
||||
outDir: "lib"
|
||||
}
|
||||
})
|
||||
};
|
||||
const fooIndex: File = {
|
||||
path: `${tscWatch.projectRoot}/foo/index.ts`,
|
||||
content: `export function foo() {}`
|
||||
};
|
||||
const host = createServerHost([barConfig, barIndex, fooBarConfig, fooBarIndex, fooConfig, fooIndex, libFile]);
|
||||
tscWatch.ensureErrorFreeBuild(host, [fooConfig.path]);
|
||||
const fooDts = `${tscWatch.projectRoot}/foo/lib/index.d.ts`;
|
||||
assert.isTrue(host.fileExists(fooDts));
|
||||
const session = createSession(host);
|
||||
const service = session.getProjectService();
|
||||
service.openClientFile(barIndex.path);
|
||||
checkProjectActualFiles(service.configuredProjects.get(barConfig.path)!, [barIndex.path, fooDts, libFile.path, barConfig.path]);
|
||||
service.openClientFile(fooBarIndex.path);
|
||||
checkProjectActualFiles(service.configuredProjects.get(fooBarConfig.path)!, [fooBarIndex.path, fooDts, libFile.path, fooBarConfig.path]);
|
||||
service.openClientFile(fooIndex.path);
|
||||
checkProjectActualFiles(service.configuredProjects.get(fooConfig.path)!, [fooIndex.path, libFile.path, fooConfig.path]);
|
||||
service.openClientFile(fooDts);
|
||||
session.executeCommandSeq<protocol.GetApplicableRefactorsRequest>({
|
||||
command: protocol.CommandTypes.GetApplicableRefactors,
|
||||
arguments: {
|
||||
file: fooDts,
|
||||
startLine: 1,
|
||||
startOffset: 1,
|
||||
endLine: 1,
|
||||
endOffset: 1
|
||||
}
|
||||
});
|
||||
assert.equal(service.tryGetDefaultProjectForFile(server.toNormalizedPath(fooDts)), service.configuredProjects.get(barConfig.path));
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories listed in config file input array", () => {
|
||||
|
||||
@ -469,9 +469,7 @@ ${appendDts}`
|
||||
const host = createServerHost([libFile, tsbaseJson, buttonConfig, buttonSource, siblingConfig, siblingSource], { useCaseSensitiveFileNames: true });
|
||||
|
||||
// ts build should succeed
|
||||
const solutionBuilder = tscWatch.createSolutionBuilder(host, [siblingConfig.path], {});
|
||||
solutionBuilder.build();
|
||||
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
|
||||
tscWatch.ensureErrorFreeBuild(host, [siblingConfig.path]);
|
||||
const sourceJs = changeExtension(siblingSource.path, ".js");
|
||||
const expectedSiblingJs = host.readFile(sourceJs);
|
||||
|
||||
|
||||
@ -2,12 +2,8 @@ namespace ts.projectSystem {
|
||||
describe("unittests:: tsserver:: with project references and tsbuild", () => {
|
||||
function createHost(files: readonly TestFSWithWatch.FileOrFolderOrSymLink[], rootNames: readonly string[]) {
|
||||
const host = createServerHost(files);
|
||||
|
||||
// ts build should succeed
|
||||
const solutionBuilder = tscWatch.createSolutionBuilder(host, rootNames, {});
|
||||
solutionBuilder.build();
|
||||
assert.equal(host.getOutput().length, 0, JSON.stringify(host.getOutput(), /*replacer*/ undefined, " "));
|
||||
|
||||
tscWatch.ensureErrorFreeBuild(host, rootNames);
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user