From bb00916cd4b782c71baf3dcd166ca169cbe83195 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 31 Mar 2022 08:37:27 -0700 Subject: [PATCH] clean up oodate TODOs --- src/harness/fakesHosts.ts | 10 +++++----- src/server/editorServices.ts | 7 +------ src/server/protocol.ts | 11 ++++++----- src/server/session.ts | 26 ++++++++++++-------------- src/tsserver/server.ts | 2 +- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/harness/fakesHosts.ts b/src/harness/fakesHosts.ts index 9db661b7399..b4b52f182c9 100644 --- a/src/harness/fakesHosts.ts +++ b/src/harness/fakesHosts.ts @@ -214,9 +214,9 @@ namespace fakes { } } - /** - * A fake `ts.CompilerHost` that leverages a virtual file system. - */ + /** + * A fake `ts.CompilerHost` that leverages a virtual file system. + */ export class CompilerHost implements ts.CompilerHost { public readonly sys: System; public readonly defaultLibLocation: string; @@ -416,7 +416,7 @@ namespace fakes { diagnostic: ts.Diagnostic; } - function indentedText(indent: number, text: string) { + function indentedText(indent: number, text: string) { if (!indent) return text; let indentText = ""; for (let i = 0; i < indent; i++) { @@ -427,7 +427,7 @@ ${indentText}${text}`; } function expectedDiagnosticMessageToText([message, ...args]: ExpectedDiagnosticMessage) { - let text = ts.getLocaleSpecificMessage(message); + let text = ts.getLocaleSpecificMessage(message); if (args.length) { text = ts.formatStringFromArgs(text, args); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 4a4fcd4c048..5a5df3881b4 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1830,8 +1830,6 @@ namespace ts.server { if (this.serverMode !== LanguageServiceMode.Semantic) { return undefined; } - // TODO: My code leaves deleted files as: the scriptinfo doesn't list a containing project, but the contianing ProjectService.openFiles still has the file - // OR maybe vice versa Debug.assert(!isOpenScriptInfo(info) || this.openFiles.has(info.path)); const projectRootPath = this.openFiles.get(info.path); const scriptInfo = Debug.checkDefined(this.getScriptInfo(info.path)); @@ -3691,10 +3689,7 @@ namespace ts.server { /* @internal */ updateFileSystem(createdFiles: Iterator | undefined, updatedFiles?: Iterator, deletedFiles?: string[]) { - // TODO: Maybe it is somehow gauche or verboten to use protocol types but the translation in applyChangesInOpenFiles seems stupid - // 2. update vfs - // I THINK that only vfs needs to update, because none of these files should be open. - // (I guess files could update from the filesystem while they are still open, but that's something to solve at the end of prototyping I think) + // TODO: Not sure it's OK to use protocol.FileSystemRequestArgs here const fs = this.host as TestFSWithWatch.VirtualServerHost; if (createdFiles) { let it; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 34cff9b8c29..8bb1fee5136 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -1806,7 +1806,6 @@ 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 */ export interface UpdateOpenRequest extends Request { command: CommandTypes.UpdateOpen; @@ -1836,14 +1835,17 @@ namespace ts.server.protocol { arguments: UpdateFileSystemRequestArgs; } + /** + * Arguments to UpdateFileSystemRequest. Tracks changes to non-opened files. + */ export 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 */ + /** List of newly created or newly available files. */ created: FileSystemRequestArgs[]; - /** Just-deleted files. Also needs to trigger and then remove file watchers (I think) */ + /** Names of just-deleted files. */ deleted: string[]; - /** Needs to replace what file watchers would normally listen to */ + /** List of updated files. */ updated: FileSystemRequestArgs[]; } @@ -1856,7 +1858,6 @@ namespace ts.server.protocol { /** * 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; } diff --git a/src/server/session.ts b/src/server/session.ts index c1dbd72bb0b..103c6d82873 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -665,7 +665,6 @@ namespace ts.server { export class Session implements EventSender { private readonly gcTimer: GcTimer; - // TODO: This will need to be replaced too protected projectService: ProjectService; private changeSeq = 0; @@ -674,7 +673,6 @@ namespace ts.server { private currentRequestId!: number; private errorCheck: MultistepOperation; - // TODO: Replace this one? protected host: ServerHost; private readonly cancellationToken: ServerCancellationToken; protected readonly typingsInstaller: ITypingsInstaller; @@ -2675,16 +2673,16 @@ namespace ts.server { [CommandNames.UpdateOpen]: (request: protocol.UpdateOpenRequest) => { this.changeSeq++; this.projectService.applyChangesInOpenFiles( - request.arguments.openFiles && mapIterator(arrayIterator(request.arguments.openFiles), ({ file, fileContent, scriptKindName, projectRootPath }) => ({ - fileName: file, - content: fileContent, - scriptKind: scriptKindName, - projectRootPath + request.arguments.openFiles && mapIterator(arrayIterator(request.arguments.openFiles), file => ({ + fileName: file.file, + content: file.fileContent, + scriptKind: file.scriptKindName, + projectRootPath: file.projectRootPath })), - request.arguments.changedFiles && mapIterator(arrayIterator(request.arguments.changedFiles), ({ fileName, textChanges}) => ({ - fileName, - changes: mapDefinedIterator(arrayReverseIterator(textChanges), change => { - const scriptInfo = Debug.checkDefined(this.projectService.getScriptInfo(fileName)); + request.arguments.changedFiles && mapIterator(arrayIterator(request.arguments.changedFiles), file => ({ + fileName: file.fileName, + changes: mapDefinedIterator(arrayReverseIterator(file.textChanges), change => { + const scriptInfo = Debug.checkDefined(this.projectService.getScriptInfo(file.fileName)); const start = scriptInfo.lineOffsetToPosition(change.start.line, change.start.offset); const end = scriptInfo.lineOffsetToPosition(change.end.line, change.end.offset); return start >= 0 ? { span: { start, length: end - start }, newText: change.newText } : undefined; @@ -2711,9 +2709,9 @@ namespace ts.server { [CommandNames.UpdateFileSystem]: (request: protocol.UpdateFileSystemRequest) => { this.changeSeq++; this.projectService.updateFileSystem( - request.arguments.created && arrayIterator(request.arguments.created), // open - request.arguments.updated && arrayIterator(request.arguments.updated), //change - request.arguments.deleted, // close + request.arguments.created && arrayIterator(request.arguments.created), + request.arguments.updated && arrayIterator(request.arguments.updated), + request.arguments.deleted, ); return this.requiredResponse(/*response*/ true); }, diff --git a/src/tsserver/server.ts b/src/tsserver/server.ts index 084bea62e1d..036dcf4c0ea 100644 --- a/src/tsserver/server.ts +++ b/src/tsserver/server.ts @@ -79,7 +79,7 @@ namespace ts.server { if (typeof process !== "undefined") { start(initializeNodeSystem(), require("os").platform()); } - // TODO: Learn how to pass arguments to server + // TODO: Not sure this is right else if (findArgument("vfs")) { // Get args from first message const listener = (e: any) => {