Allow dynamic files without external project and also use file names starting with ^ as dynamic file
Fixes #21204
This commit is contained in:
parent
588716926d
commit
146256b7dc
|
@ -2846,6 +2846,45 @@ namespace ts.projectSystem {
|
|||
const options = project.getCompilerOptions();
|
||||
assert.equal(options.outDir, "C:/a/b", "");
|
||||
});
|
||||
|
||||
it("dynamic file without external project", () => {
|
||||
const file: FileOrFolder = {
|
||||
path: "^walkThroughSnippet:/Users/UserName/projects/someProject/out/someFile#1.js",
|
||||
content: "var x = 10;"
|
||||
};
|
||||
const host = createServerHost([libFile], { useCaseSensitiveFileNames: true });
|
||||
const projectService = createProjectService(host);
|
||||
projectService.setCompilerOptionsForInferredProjects({
|
||||
module: ModuleKind.CommonJS,
|
||||
allowJs: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
allowNonTsExtensions: true
|
||||
});
|
||||
projectService.openClientFile(file.path, "var x = 10;");
|
||||
|
||||
projectService.checkNumberOfProjects({ inferredProjects: 1 });
|
||||
const project = projectService.inferredProjects[0];
|
||||
checkProjectRootFiles(project, [file.path]);
|
||||
checkProjectActualFiles(project, [file.path, libFile.path]);
|
||||
|
||||
assert.strictEqual(projectService.getDefaultProjectForFile(server.toNormalizedPath(file.path), /*ensureProject*/ true), project);
|
||||
const indexOfX = file.content.indexOf("x");
|
||||
assert.deepEqual(project.getLanguageService(/*ensureSynchronized*/ true).getQuickInfoAtPosition(file.path, indexOfX), {
|
||||
kind: ScriptElementKind.variableElement,
|
||||
kindModifiers: "",
|
||||
textSpan: { start: indexOfX, length: 1 },
|
||||
displayParts: [
|
||||
{ text: "var", kind: "keyword" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "x", kind: "localName" },
|
||||
{ text: ":", kind: "punctuation" },
|
||||
{ text: " ", kind: "space" },
|
||||
{ text: "number", kind: "keyword" }
|
||||
],
|
||||
documentation: [],
|
||||
tags: []
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsserverProjectSystem Proper errors", () => {
|
||||
|
|
|
@ -898,7 +898,7 @@ namespace ts.server {
|
|||
|
||||
const project = this.getOrCreateInferredProjectForProjectRootPathIfEnabled(info, projectRootPath) ||
|
||||
this.getOrCreateSingleInferredProjectIfEnabled() ||
|
||||
this.createInferredProject(getDirectoryPath(info.path));
|
||||
this.createInferredProject(info.isDynamic ? this.currentDirectory : getDirectoryPath(info.path));
|
||||
|
||||
project.addRoot(info);
|
||||
project.updateGraph();
|
||||
|
@ -1655,7 +1655,7 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
private getOrCreateInferredProjectForProjectRootPathIfEnabled(info: ScriptInfo, projectRootPath: NormalizedPath | undefined): InferredProject | undefined {
|
||||
if (!this.useInferredProjectPerProjectRoot) {
|
||||
if (info.isDynamic || !this.useInferredProjectPerProjectRoot) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ namespace ts.server {
|
|||
|
||||
/*@internal*/
|
||||
export function isDynamicFileName(fileName: NormalizedPath) {
|
||||
return getBaseFileName(fileName)[0] === "^";
|
||||
return fileName[0] === "^" || getBaseFileName(fileName)[0] === "^";
|
||||
}
|
||||
|
||||
export class ScriptInfo {
|
||||
|
|
Loading…
Reference in a new issue