Get rid of separate init call for VirtualServerHost

Also move vfs -> Semantic mode parsing.
This commit is contained in:
Nathan Shively-Sanders
2022-05-25 10:18:12 -07:00
parent d5a9736607
commit c2d45f9ad4
5 changed files with 36 additions and 35 deletions
+2 -7
View File
@@ -55,7 +55,6 @@ interface Array<T> { length: number; [n: number]: T; }`
export function createVirtualServerHost(params: VirtualServerHostCreationParameters): VirtualServerHost {
const host = new VirtualServerHost(params);
host.init();
// Just like sys, patch the host to use writeFile
patchWriteFileEnsuringDirectory(host);
return host;
@@ -303,7 +302,7 @@ interface Array<T> { length: number; [n: number]: T; }`
export const timeIncrements = 1000;
export class TestServerHost extends VirtualServerHost implements server.ServerHost {
export class TestServerHost extends VirtualServerBaseHost implements server.ServerHost {
readonly screenClears: number[] = [];
private readonly output: string[] = [];
private time = timeIncrements;
@@ -332,11 +331,6 @@ interface Array<T> { length: number; [n: number]: T; }`
this.runWithoutRecursiveWatches = runWithoutRecursiveWatches;
this.runWithFallbackPolling = !!runWithFallbackPolling;
this.environmentVariables = environmentVariables;
this.init();
this.reloadFS(fileOrFolderOrSymLinkList);
}
override init() {
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
@@ -364,6 +358,7 @@ interface Array<T> { length: number; [n: number]: T; }`
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
this.reloadFS(fileOrFolderOrSymLinkList);
}
getTime() {
-1
View File
@@ -65,7 +65,6 @@ namespace ts.server {
executingFilePath: "", // TODO: "" is the default..maybe this should be vfs, vfs:// or .
newLine: sys.newLine,
});
fshost.init();
}
else {
fshost = sys as ServerHost;
+2
View File
@@ -16,6 +16,7 @@ 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()) {
@@ -72,6 +73,7 @@ namespace ts.server {
},
writeMessage,
};
// Do this after sys has been set as findArguments is going to work only then
const sys = server.createWebSystem(webHost, args, () => findArgument("--executingFilePath") || location + "");
setSys(sys);
+32 -26
View File
@@ -117,9 +117,12 @@ namespace ts.VirtualFS {
}
/**
* Use TestServerHost for tests or VirtualServerHost for virtual file systems.
* This is a base for those two classes.
*
* also implements {server.ServerHost} but that would create a circular dependency
*/
export class VirtualServerHost implements FormatDiagnosticsHost, ModuleResolutionHost {
export abstract class VirtualServerBaseHost implements FormatDiagnosticsHost, ModuleResolutionHost {
args: string[] = [];
protected fs: ESMap<Path, FSEntry> = new Map();
@@ -152,31 +155,6 @@ namespace ts.VirtualFS {
this.currentDirectory = this.getHostSpecificPath(currentDirectory);
}
init() {
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
// into watchedFiles for easier testing
pollingWatchFile: this.watchFileWorker.bind(this),
getModifiedTime: this.getModifiedTime.bind(this),
setTimeout: this.setTimeout.bind(this),
clearTimeout: this.clearTimeout.bind(this),
fsWatch: this.fsWatch.bind(this),
fileExists: this.fileExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: true,
directoryExists: this.directoryExists.bind(this),
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
tscWatchFile: undefined,
tscWatchDirectory: undefined,
defaultWatchFileKind: () => undefined,
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
}
getNewLine() {
return this.newLine;
}
@@ -640,6 +618,34 @@ namespace ts.VirtualFS {
}
}
export class VirtualServerHost extends VirtualServerBaseHost {
constructor(options: VirtualServerHostCreationParameters) {
super(options)
const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
// it is essentially fsWatch but lets get that separate from fsWatch and
// into watchedFiles for easier testing
pollingWatchFile: this.watchFileWorker.bind(this),
getModifiedTime: this.getModifiedTime.bind(this),
setTimeout: this.setTimeout.bind(this),
clearTimeout: this.clearTimeout.bind(this),
fsWatch: this.fsWatch.bind(this),
fileExists: this.fileExists.bind(this),
useCaseSensitiveFileNames: this.useCaseSensitiveFileNames,
getCurrentDirectory: this.getCurrentDirectory.bind(this),
fsSupportsRecursiveFsWatch: true,
directoryExists: this.directoryExists.bind(this),
getAccessibleSortedChildDirectories: path => this.getDirectories(path),
realpath: this.realpath.bind(this),
tscWatchFile: undefined,
tscWatchDirectory: undefined,
defaultWatchFileKind: () => undefined,
});
this.watchFile = watchFile;
this.watchDirectory = watchDirectory;
}
}
function diffFsFile(baseline: string[], fsEntry: FsFile) {
baseline.push(`//// [${fsEntry.fullPath}]\r\n${fsEntry.content}`, "");
}
-1
View File
@@ -184,7 +184,6 @@ namespace ts.server {
fshost,
cancellationToken,
...options,
serverMode: fshost instanceof VirtualFS.VirtualServerHost ? LanguageServiceMode.Semantic : options.serverMode,
typingsInstaller: nullTypingsInstaller,
byteLength: notImplemented, // Formats the message text in send of Session which is overriden in this class so not needed
hrtime,