Skip to content

Use node ipc for TS Server - #46418

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 6 commits into
microsoft:mainfrom
mjbvz:use-node-ipc
Jan 6, 2022
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 6 commits into
microsoft:mainfrom
mjbvz:use-node-ipc

Conversation

@mjbvz

Copy link
Copy Markdown

For #46417

This lets us use Node's built-in ipc for passing messages to/from the typescript server instead of using stdio

Needs review from the TS team because there are still a few todo comments and I'm pretty sure I've overlooked some things

For microsoft#46417

This lets us use Node's built-in ipc for passing messages to/from the typescript server instead of using stdio
@typescript-bot TypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 18, 2021
@mjbvz
Matt Bierner (mjbvz) marked this pull request as ready for review November 29, 2021 11:51
@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Comment thread src/tsserver/nodeServer.ts Outdated
Comment thread src/tsserver/nodeServer.ts Outdated
Comment on lines +726 to +728
// TODO: Do we need any perf stuff here?
// const msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
// perfLogger.logEvent(`Response message size: ${msgText.length}`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the answer here might be yes, or at least the portion that formatMessage does in verboseLogging mode as a side effect.

@jakebailey

Copy link
Copy Markdown
Member

The PR looks good to me as it is now (I don't see any gotchas), though I don't know if it's ready or if the VS Code side is done to test.

@mjbvz

Copy link
Copy Markdown
Author

Jake Bailey (@jakebailey) This new flow should only be enabled if the client passes in the --useNodeIpc flag so I it can be merged whenever the TS changes look good. I have a separate change to adopt this on the VS Code side

Comment thread src/tsserver/nodeServer.ts Outdated
}

public send(msg: protocol.Message) {
if (useNodeIpc) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider refactoring. The repeated flag check is a good indicator that you actually want method overrides. Maybe we're looking at a third subclass of Session (WorkerSession, IOSession and maybe NodeIpcSession?)

parseMessage and toStringMessage are the same as in the WorkerSession implementation.

send seems to be different for all three implementations, but does it need to be? That msg.type === "event" check and logging code applies to all implementations so it may as well live in the base class. Then you probably want to pull out the writeMessage call into a protected method to make it specific to the subclass, since that's the part that actually differs between the three.

(I don't know if we want to follow these OOP patterns all across the codebase, but since the session code is written that way, my advice is following that pattern.).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. Made the fix

@DanielRosenwasser

Copy link
Copy Markdown
Member

You'll need to accept the baseline for the public API. It seems like I don't have rights to change this branch though.

@mjbvz

Copy link
Copy Markdown
Author

Daniel Rosenwasser (@DanielRosenwasser) When I run gulp baseline-accept I don't see any changes. Is that expected since this commit only changes the flags passed to the server and not any d.ts apis?

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Jan 4, 2022 •

Copy link
Copy Markdown
Member

Maybe you're only doing a partial test-run? I think CI is correctly pointing out a change in api/tsserverlibrary.d.ts.

         private projectsUpdatedInBackgroundEvent;
         logError(err: Error, cmd: string): void;
         private logErrorWorker;
         send(msg: protocol.Message): void;
+        protected writeMessage(msg: protocol.Message): void;
         event<T extends object>(body: T, eventName: string): void;
         /** @deprecated */
         output(info: any, cmdName: string, reqSeq?: number, errorMsg?: string): void;
         private doOutput;

@mjbvz

Copy link
Copy Markdown
Author

Thanks! After running full tests I as able to run baseline-accept

@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) merged commit 6966209 into microsoft:main Jan 6, 2022
@DanielRosenwasser

Copy link
Copy Markdown
Member

Thanks Matt!

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants