diff --git a/src/harness/virtualFileSystemWithWatch.ts b/src/harness/virtualFileSystemWithWatch.ts index ff3e6654ed2..7d7f405b9bd 100644 --- a/src/harness/virtualFileSystemWithWatch.ts +++ b/src/harness/virtualFileSystemWithWatch.ts @@ -55,7 +55,6 @@ interface Array { 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 { 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 { 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 { length: number; [n: number]: T; }` }); this.watchFile = watchFile; this.watchDirectory = watchDirectory; + this.reloadFS(fileOrFolderOrSymLinkList); } getTime() { diff --git a/src/tsserver/server.ts b/src/tsserver/server.ts index 522e135ff90..64847ea1ae6 100644 --- a/src/tsserver/server.ts +++ b/src/tsserver/server.ts @@ -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; diff --git a/src/tsserver/webServer.ts b/src/tsserver/webServer.ts index 4a6512318b4..a3ea20191b4 100644 --- a/src/tsserver/webServer.ts +++ b/src/tsserver/webServer.ts @@ -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); diff --git a/src/vfs/virtualFileSystemWithWatch.ts b/src/vfs/virtualFileSystemWithWatch.ts index fc7645d5ada..dc4f48cdaee 100644 --- a/src/vfs/virtualFileSystemWithWatch.ts +++ b/src/vfs/virtualFileSystemWithWatch.ts @@ -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 = 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}`, ""); } diff --git a/src/webServer/webServer.ts b/src/webServer/webServer.ts index ad1361be966..adc3a10b8b2 100644 --- a/src/webServer/webServer.ts +++ b/src/webServer/webServer.ts @@ -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,