Add build target for packaging tsserver as a library#3513
Conversation
|
Hi @weswigham, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
|
@weswigham, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
There was a problem hiding this comment.
these are only used in the session object, i do not see the point of the additional abstraction, just pass them as constructor paramters.
There was a problem hiding this comment.
That's pretty much what this is doing, it was just bundling the two parameters into one argument. I'll split it out into multiple arguments.
|
@weswigham can you split this into two, pre b8f6ada and 9a3fead, i would want to discuss them first. |
Specifically, adds
jake lssl(language service server library). The goal was to export theSessiontype which, in turn, has necessitated exporting most of the types ineditorServices.tsby extension.Additionally, I've made some changes to enable this library to function outside node - (
node.d.tsis no longer compiled into thelssltarget by any of the files included in it). Specifically, the two features of Node which Session used -Buffer.byteLengthandprocess.hrtime, I've offloaded to a newEnvironmentinterface, and created a node implementation of it fortsserver-server\nodeimpl.ts. I was considering that they may be better provided by theSysteminterface, and would like feedback on this - changing theSysteminterface seemed like a farther reaching change than was desired.On top of this, to make
Session(or trivial subclasses) actually instantiate at runtime in non-node environments, I removedSession's meager dependency onts.sys- which only gets set in node or in windows script host. For the most part, this simply meant calling the host whichSessionwas constructed with, but in one instance this meant that thehosthad to be passed along to a static function -ScriptVersionCache.fromString. Additionally, the staticCompilerService.defaultFormatCodeOptionshad to be made aware thatts.sysmay not be set at static initialization time if not running in either node or windows script host.The remaining changes, b8f6ada and 9a3fead, are less critical to exporting the
Sessiontype as a library, but do provide quality improvements in the exported interface.Sessionclass to subclass and overrideonMessageand still call theonMessageParsedimplementation - or just callonMessageParseddirectly. This is useful in situations where the service is capable of receiving message objects as objects directly, rather than as json strings, thereby allowing consumers to remove (de)serialization overhead.onMessageParsedfunction to handle arbitrary messages, rather than throwing immediately if the massive switch statement falls all the way through. (IMO, it may be nicer to register all message handlers this way and remove the switch entirely.) This is incredibly useful in situations when the session communication channel is intended to the the primary communication channel between a client and a server, and allows a server to provide extended functionality (or, in the case of running in a browser worker thread, allows a client to send the server content with which to build a virtual filesystem and external edits to the files therein). This is the least required of the changes herein, so if too much issue is taken with it, it is not necessarily required if the prior commit is still accepted.