Address remaining comments

This commit is contained in:
Nathan Shively-Sanders
2022-06-14 11:02:16 -07:00
parent b31aaf3eef
commit 32e4795624
5 changed files with 29 additions and 27 deletions

View File

@@ -507,7 +507,7 @@ interface Array<T> { length: number; [n: number]: T; }`
throw new Error(this.exitMessage);
}
override getEnvironmentVariable(name: string) {
getEnvironmentVariable(name: string) {
return this.environmentVariables && this.environmentVariables.get(name) || "";
}
}

View File

@@ -29,14 +29,28 @@ namespace ts.projectSystem {
return `// some copy right notice
${file.fileContent}`;
}
function baselineFileSystem(scenario: string, subScenario: string, requests: [string, (() => void) | Partial<protocol.Request>][], host: TestServerHost, fshost: VirtualFS.VirtualServerHost, session: TestSession) {
function verifyTsc(
scenario: string,
subScenario: string,
requests: [string, ((host: TestServerHost, fshost: VirtualFS.VirtualServerHost) => void) | Partial<protocol.Request>][],
) {
const host = VirtualFS.createServerHost({ executingFilePath: "/host/tsc.js" });
const fshost = VirtualFS.createVirtualServerHost({ executingFilePath: "/fshost/tsc.js" });
const session = createSession(host, { fshost, logger: createLoggerWithInMemoryLogs(), canUseEvents: true });
const history: string[] = [];
VirtualFS.createWatcher(fshost.fsWatches, "/host/b/app.ts" as Path, {
cb: (_, relativeFileName) => {
assert.fail("The watcher for /host/b/app.ts should not be called at all. Called with " + relativeFileName);
},
directoryName: "/host/b",
inode: undefined,
});
let prev = VirtualFS.snap(fshost);
let prev2 = VirtualFS.snap(host);
for (const [name, request] of requests) {
if (typeof request === "function") {
request();
request(host, fshost);
}
else {
session.executeCommandSeq(request);
@@ -58,10 +72,7 @@ ${file.fileContent}`;
}
it("with updateFileSystem request", () => {
const host = VirtualFS.createServerHost({ executingFilePath: "/host/tsc.js" });
const fshost = VirtualFS.createVirtualServerHost({ executingFilePath: "/fshost/tsc.js" });
const session = createSession(host, { fshost, logger: createLoggerWithInMemoryLogs(), canUseEvents: true });
const requests: [string, (() => void) | Partial<protocol.Request>][] = [
const requests: [string, ((host: TestServerHost, fshost: VirtualFS.VirtualServerHost) => void) | Partial<protocol.Request>][] = [
["Initial updateFileSystem", {
command: protocol.CommandTypes.UpdateFileSystem,
arguments:{
@@ -100,19 +111,19 @@ ${file.fileContent}`;
deleted: [],
},
}],
["ensure /host/app.ts exists", () => host.ensureFileOrFolder({
["ensure /host/app.ts exists", (host) => host.ensureFileOrFolder({
path: "/host/b/app.ts",
content: 'console.log("hello")'
})],
["modify /host/app.ts", () => host.modifyFile(
["modify /host/app.ts", (host) => host.modifyFile(
"/host/b/app.ts",
"console.log('goodbye')"
)],
["ensure /fshost/file4.ts exists", () => fshost.ensureFileOrFolder({
["ensure /fshost/file4.ts exists", (_, fshost) => fshost.ensureFileOrFolder({
path:"/fshost/b/file4.ts",
content: "console.log('file4 exists')",
})],
["modify /fshost/file4", () => fshost.modifyFile(
["modify /fshost/file4", (_, fshost) => fshost.modifyFile(
"/fshost/b/file4.ts",
"console.log('file4 modified')"
)],
@@ -129,17 +140,10 @@ ${file.fileContent}`;
arguments: { file: app.file }
}],
];
VirtualFS.createWatcher(fshost.fsWatches, "/host/b/app.ts" as Path, {
cb: (_, relativeFileName) => {
assert.fail("The watcher for /host/b/app.ts should not be called at all. Called with " + relativeFileName);
},
directoryName: "/host/b",
inode: undefined,
});
const scenario = "updateFileSystem";
const subScenario = "open and close files";
baselineFileSystem(scenario, subScenario, requests, host, fshost, session);
verifyTsc(scenario, subScenario, requests);
});
});
}

View File

@@ -42,7 +42,7 @@ namespace ts.projectSystem {
if (isVfs) {
serverMode = LanguageServiceMode.Semantic;
fshost = VirtualFS.createVirtualServerHost({ executingFilePath: "/a/lib/tsc.js" });
(fshost).ensureFileOrFolder(libFile);
fshost.ensureFileOrFolder(libFile);
}
const logger = logLevel !== undefined ? new server.MainProcessLogger(logLevel, webHost) : nullLogger();
const session = new TestWorkerSession(webSys, fshost, webHost, { serverMode }, logger);

View File

@@ -16,7 +16,6 @@ namespace ts.server {
};
function parseServerMode(): LanguageServiceMode | string | undefined {
if (hasArgument("--vfs")) return LanguageServiceMode.Semantic;
const mode = findArgument("--serverMode");
if (!mode) return undefined;
switch (mode.toLowerCase()) {
@@ -24,6 +23,9 @@ namespace ts.server {
return LanguageServiceMode.PartialSemantic;
case "syntactic":
return LanguageServiceMode.Syntactic;
case "semantic":
if (hasArgument("--vfs")) return LanguageServiceMode.Semantic;
// fallthrough
default:
return mode;
}
@@ -56,8 +58,8 @@ namespace ts.server {
args,
logger,
cancellationToken: nullCancellationToken,
// Webserver defaults to partial semantic mode
serverMode: serverMode ?? LanguageServiceMode.PartialSemantic,
// Webserver defaults to partial semantic mode unless VFS is turned on
serverMode: serverMode ?? (hasArgument("--vfs") ? LanguageServiceMode.Semantic : LanguageServiceMode.PartialSemantic),
unknownServerMode,
startSession: startWebSession
};

View File

@@ -649,10 +649,6 @@ namespace ts.VirtualFS {
baseline.push("");
return baseline;
}
getEnvironmentVariable(_name: string) {
return "";
}
}
function serializeTestFsWatcher({ directoryName, inode }: VirtualFsWatcher) {