From eb22b4f8c4cc1f29d564523a3f1f3bc2c7cf8ee0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 1 Mar 2022 10:18:22 -0800 Subject: [PATCH] Everything builds and tests pass Except for the new test I added. --- src/server/editorServices.ts | 54 +++++++++---------- src/testRunner/tsconfig.json | 1 + src/vfs/vfsUtil.ts | 19 ------- .../reference/api/tsserverlibrary.d.ts | 31 ++++++++++- 4 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 6edfb6adb8a..0c7f116bc18 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -3693,33 +3693,33 @@ namespace ts.server { // ugggggggggg have to copy over all that stuff to here // (though I probably need to create a vfs project anyway, so why not) - const fs = new vfs.FileSystem(/*ignoreCase*/ true, { - files: { - [builtFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "built/local"), resolver), - [testLibFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "tests/lib"), resolver), - [projectsFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "tests/projects"), resolver), - [srcFolder]: {} - }, - cwd: srcFolder, - meta: { defaultLibLocation: builtFolder } - }) - if (!this.fs) - this.fs = fs - if (createdFiles) { - for (const document of Array.from(createdFiles)) { - fs.mkdirpSync(vpath.dirname(document.file)); - fs.writeFileSync(document.file, document.text, "utf8"); - fs.filemeta(document.file).set("document", document); - // Add symlinks - const symlink = document.meta.get("symlink"); - if (symlink) { - for (const link of symlink.split(",").map(link => link.trim())) { - fs.mkdirpSync(vpath.dirname(link)); - fs.symlinkSync(vpath.resolve(fs.cwd(), document.file), link); - } - } - } - } + // const fs = new vfs.FileSystem(/*ignoreCase*/ true, { + // files: { + // [builtFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "built/local"), resolver), + // [testLibFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "tests/lib"), resolver), + // [projectsFolder]: new Mount(vpath.resolve(host.getWorkspaceRoot(), "tests/projects"), resolver), + // [srcFolder]: {} + // }, + // cwd: srcFolder, + // meta: { defaultLibLocation: builtFolder } + // }) + // if (!this.fs) + // this.fs = fs + // if (createdFiles) { + // for (const document of Array.from(createdFiles)) { + // fs.mkdirpSync(vpath.dirname(document.file)); + // fs.writeFileSync(document.file, document.text, "utf8"); + // fs.filemeta(document.file).set("document", document); + // // Add symlinks + // const symlink = document.meta.get("symlink"); + // if (symlink) { + // for (const link of symlink.split(",").map(link => link.trim())) { + // fs.mkdirpSync(vpath.dirname(link)); + // fs.symlinkSync(vpath.resolve(fs.cwd(), document.file), link); + // } + // } + // } + // } // 1. set some internal tsserver state for mocked FS (if it hasn't already been set, this might not be the first message) // - change this.host at least diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 2caa9873f29..88c3d75a668 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -22,6 +22,7 @@ { "path": "../server", "prepend": true }, { "path": "../webServer", "prepend": true }, { "path": "../typingsInstallerCore", "prepend": true }, + { "path": "../vfs", "prepend": true }, { "path": "../harness", "prepend": true }, { "path": "../loggedIO", "prepend": true } ], diff --git a/src/vfs/vfsUtil.ts b/src/vfs/vfsUtil.ts index 5eca1ce30bb..592681bd627 100644 --- a/src/vfs/vfsUtil.ts +++ b/src/vfs/vfsUtil.ts @@ -1598,23 +1598,4 @@ namespace vfs { } return text; } - - export function iteratePatch(patch: FileSet | undefined): IterableIterator<[string, string]> | null { - // eslint-disable-next-line no-null/no-null - return patch ? Harness.Compiler.iterateOutputs(iteratePatchWorker("", patch)) : null; - } - - function* iteratePatchWorker(dirname: string, container: FileSet): IterableIterator { - for (const name of Object.keys(container)) { - const entry = normalizeFileSetEntry(container[name]); - const file = dirname ? vpath.combine(dirname, name) : name; - if (entry instanceof Directory) { - yield* ts.arrayFrom(iteratePatchWorker(file, entry.files)); - } - else if (entry instanceof File) { - const content = typeof entry.data === "string" ? entry.data : entry.data.toString("utf8"); - yield new documents.TextDocument(file, content); - } - } - } } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 234e340a859..11909023903 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -6970,6 +6970,7 @@ declare namespace ts.server.protocol { OpenExternalProjects = "openExternalProjects", CloseExternalProject = "closeExternalProject", UpdateOpen = "updateOpen", + UpdateFileSystem = "updateFileSystem", GetOutliningSpans = "getOutliningSpans", TodoComments = "todoComments", Indentation = "indentation", @@ -8216,6 +8217,7 @@ declare namespace ts.server.protocol { } /** * Request to synchronize list of open files with the client + * TODO: Lots of unit tests refer to this too, a good starting point for UpdateFileSystemRequest */ interface UpdateOpenRequest extends Request { command: CommandTypes.UpdateOpen; @@ -8230,7 +8232,7 @@ declare namespace ts.server.protocol { */ openFiles?: OpenRequestArgs[]; /** - * List of open files files that were changes + * List of open files files that were changed */ changedFiles?: FileCodeEdits[]; /** @@ -8238,6 +8240,33 @@ declare namespace ts.server.protocol { */ closedFiles?: string[]; } + interface UpdateFileSystemRequest extends Request { + command: CommandTypes.UpdateFileSystem; + arguments: UpdateFileSystemRequestArgs; + } + interface UpdateFileSystemRequestArgs { + /** For now, only 'memfs', initially for exclusive in-memory operation, but it could be other in-memory names later */ + fileSystem: string; + /** For now, a list of newly created or newly available files. Probably need to ADD mocked file watchers */ + created: FileSystemRequestArgs[]; + /** Just-deleted files. Also needs to trigger and then remove file watchers (I think) */ + deleted: string[]; + /** Needs to replace what file watchers would normally listen to */ + updated: FileSystemRequestArgs[]; + } + interface FileSystemRequestArgs extends FileRequestArgs { + /** + * Used to replace the content that would be on disk. + * Then the known content will be used upon opening instead of the disk copy + */ + fileContent?: string; + /** + * Used to specify the script kind of the file explicitly. It could be one of the following: + * "TS", "JS", "TSX", "JSX" + * TODO: Not 100% sure this is needed. + */ + scriptKindName?: ScriptKindName; + } /** * External projects have a typeAcquisition option so they need to be added separately to compiler options for inferred projects. */