GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adds experimental support for running TS Server in a web worker by mjbvz · Pull Request #39656 · microsoft/TypeScript

Conversation

@mjbvz

@mjbvz Matt Bierner (mjbvz) commented Jul 18, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This change makes it possible to run a syntax based TS server in a webworker. This is will let serverless versions of VS Code web run the TypeScript extension with minimal changes.

Screen Shot 2020-07-17 at 11 49 06 PM

Overview
I made the changes in server.ts in order to share as much code as possible between the web and node based servers. However adding web server support require some significant rewriting, so the diff on server.ts is difficult to parse. Here's an overview of the changes:

  • Introduce the concept of a Runtime. Valid values are Node and Web.
  • Move calls to require into the functions that use these modules
  • Wrap existing server logic into startNodeServer
  • Introduce web server with startWebServer. This uses a WorkerSession
  • Add a custom version of ts.sys for web
  • Have the worker server start when it is passed an array of arguments in a message

In order to make the server logic more clear, this change also tries to reduce the reliance on closures and better group declarations vs the logic for starting the server.

Next Steps
I'd like someone from the TS team to help get these changes into a shippable state. This will involve:

  • Adddress todo comments
  • Code cleanup
  • Make sure these changes do not regress node servers
  • Determine if we should add a new tsserver.web.js file instead of having the web worker logic all live in tsserver.js

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iagobruno and hacke2 reacted with thumbs up emoji DanielRosenwasser, SpencerSharkey, tonivj5, Aaaaash, shixin-guo, maltenuhn, btoo, iagobruno, and styfle reacted with heart emoji worstpractice reacted with rocket emoji
All reactions
  • 👍 2 reactions
  • ❤️ 9 reactions
  • 🚀 1 reaction
@mjbvz Matt Bierner (mjbvz) mentioned this pull request Jul 21, 2020
Enable web TS Server microsoft/vscode#102990
Merged
1 of 2 tasks
Matt Bierner (mjbvz) pushed a commit to mjbvz/vscode that referenced this pull request Jul 21, 2020
Matt Bierner
Enable TS extension for web
8be7d5c
This enables running the TS Server on web. This currently requires a special version of the TypeScript server (microsoft/TypeScript#39656)

TODO:

- [ ] Fix commented code in `versionProvider` and `spawner` and `typescriptServiceClient`(they import `fs`)
- [ ] Sync with TS team about how tsserver work will be shipped
@mjbvz

Matt Bierner (mjbvz) commented Jul 21, 2020

Copy link
Copy Markdown
Contributor Author

Ryan Cavanaugh (@RyanCavanaugh) Let's sync tomorrow on the next steps for this work. I've done work on the VS Code side to pull in my forked typescript version (microsoft/vscode#102990) for web builds. This unblocks us but is only a short term workaround

My proposal is that during the start of TS 4.1 development, we collaborate on getting this PR merged into master. In order to keep package sizes down, I think we probably want to ship web support in tsserver.js instead of introducing a new tsserver.web.js. Once the PR is merged, VS Code could then pull the web server from master using nightly builds

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mjbvz Matt Bierner (mjbvz) mentioned this pull request Jul 22, 2020
Running TS Server in a web worker #39707
Closed
4 tasks
@typescript-bot TypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 23, 2020
Matt Bierner added 5 commits August 31, 2020 16:03
Matt Bierner
Adds experimental support for running TS Server in a web worker
e50aedc
This change makes it possible to run a syntax old TS server in a webworker. This is will let serverless versions of VS Code web run the TypeScript extension with minimal changes.

As the diff on `server.ts` is difficult to parse, here's an overview of the changes:

- Introduce the concept of a `Runtime`. Valid values are `Node` and `Web`.
- Move calls to `require` into the functions that use these modules
- Wrap existing server logic into `startNodeServer`
- Introduce web server with `startWebServer`. This uses a `WorkerSession`
- Add a custom version of `ts.sys` for web
- Have the worker server start when it is passed an array of arguments in a message

In order to make the server logic more clear, this change also tries to reduce the reliance on closures and better group function declarations vs the server spawning logic.

**Next Steps**
I'd like someone from the TS team to help get these changes into a shippable state. This will involve:

- Adddress todo comments
- Code cleanup
- Make sure these changes do not regress node servers
- Determine if we should add a new `tsserver.web.js` file instead of having the web worker logic all live in `tsserver.js`
Matt Bierner
Shim out directoryExists
30cb1a6
Matt Bierner
Add some regions
fb900a0
Matt Bierner
Remove some inlined note types
4ce8d4a
Use import types instead
Matt Bierner
Use switch case for runtime
94faf66
@mjbvz
Matt Bierner (mjbvz) force-pushed the web-worker-server branch from 90e38eb to 94faf66 Compare August 31, 2020 23:15
@mjbvz

Matt Bierner (mjbvz) commented Sep 3, 2020

Copy link
Copy Markdown
Contributor Author

Here's how to test these changes in a web build of VS Code:

  • To build VS code's extensions for the web, simply run yarn watch-web in the VS Code codebase

  • Start the web version of VS code with yarn web.

    Chrome or modern Edge works best for testing

  • VS Code picks up the web version of tsserver from extensions/typescript-language-features/dist/browser/typescript-web

    By default, VS Code pulls in a prebuilt version of TypeScript using an npm install for git://github.com/mjbvz/ts-server-web-build

  • To use your local build instead, build your local copy of TypeScript and then replace the tsserver.web.js file under dist/browser/typescript-web with your built one.

    You can also use a symbolic link so you can iterate more quickly on the TypeScript changes. On MacOS, the command to create this link this would be something like:

    ln -s ~/projects/typescript/built/local/tsserver.js \
        extensions/typescript-language-features/dist/browser/typescript-web/tsserver.web.js
  • To make sure your linked TS version does not get replaced automatically on rebuild, comment out the two CopyPlugin parts of this webpack config

Sheetal Nandi (@sheetalkamat)

sheetalkamat and sinoon reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat
Merge branch 'master' into web-worker-server
f6c0749
@sheetalkamat
Sheetal Nandi (sheetalkamat) force-pushed the web-worker-server branch from 7a69aeb to e1122d2 Compare September 23, 2020 02:10
@sheetalkamat

Sheetal Nandi (sheetalkamat) commented Sep 23, 2020

Copy link
Copy Markdown
Member

Looked at the changes and have updated them:
The things that we need to consider is how to find newLine, useCaseSensitive, readFile (will be needed for lib files in patial semantic mode.. I have gone through rest of the sys methods and have updated them/added comment accordingly. Have set things to some default for now and added TODOs
https://github.com/microsoft/TypeScript/pull/39656/files#diff-7703eaf5820d0a2af1ac3f7dde491b0aR54

newLine: "\r\n", // TODO::
            useCaseSensitiveFileNames: false, // TODO::
            readFile: returnUndefined, // TODO:: read lib Files

            write: postMessage,
            watchFile: returnNoopFileWatcher,
            watchDirectory: returnNoopFileWatcher,

            getExecutingFilePath: returnEmptyString, // TODO:: Locale, lib locations, typesmap location, plugins
            getCurrentDirectory: returnEmptyString, // For inferred project root if projectRoot path is not set, normalizing the paths

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat
Review and updates
f3178b6
@sheetalkamat
Sheetal Nandi (sheetalkamat) force-pushed the web-worker-server branch from e1122d2 to f3178b6 Compare September 23, 2020 18:03
Matt Bierner
Enable loading std library d.ts files
6202c51
This implements enough of `ServerHost` that we can load the standard d.ts files using synchronous XMLHttpRequests.

I also had to patch some code in `editorServices`. I don't know if these changes are correct and need someone on the TS team to review
@mjbvz

Matt Bierner (mjbvz) commented Sep 25, 2020

Copy link
Copy Markdown
Contributor Author

Sheetal Nandi (@sheetalkamat) Just pushed 6202c51 that enables support for loading the standard d.ts files that TypeScript ships with. I had to make some changes in editorServices.ts that I am not sure are correct.

The problem is that the standard library files have filenames such as http://localhost:8080/static/extensions/typescript-language-features/dist/browser/typescript-web/lib.dom.d.ts which were being ignored by the host. I don't know if the logic in editorServices needs to be updated or if we try changing the resolved file paths for the standard d.ts files

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Sep 28, 2020
View reviewed changes
Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Sep 28, 2020
View reviewed changes
Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Sep 28, 2020
View reviewed changes
Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Sep 28, 2020
View reviewed changes
Comment thread src/server/editorServices.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Sheetal Nandi (sheetalkamat) and others added 5 commits September 28, 2020 12:09
@sheetalkamat
Update src/tsserver/webServer.ts
b6e8137
Matt Bierner @sheetalkamat
Update src/tsserver/webServer.ts
dd331e2
Co-authored-by: Sheetal Nandi <[email protected]>
Matt Bierner
Addressing feedback
2d4c726
Matt Bierner
Allow passing in explicit executingFilePath
69a6523
This is required for cases where `self.location` does not point to the directory where all the typings are stored
Matt Bierner
Adding logging support
5185f6e
@mjbvz

Matt Bierner (mjbvz) commented Sep 30, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Sheetal Nandi (@sheetalkamat) Just pushed changes that enables TS Server logging on web. You'll also need to use the latest VS Code build from our main branch to use this

Right now the logger prints to the console. Here's what that looks like:

Screen Shot 2020-09-29 at 6 00 48 PM

As you can see, not ideal for grouped messages but it gets the job done. Let me know if we should look into logging into a VS Code output window instead. For that, we'd likely want to post special logging messages back to VS Code that it can append onto the output

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sheetal Nandi (sheetalkamat) added 2 commits November 13, 2020 16:37
@sheetalkamat
Map the paths back to https:
0edf650
// TODO: is this really needed or can vscode take care of this
How do we handle when opening lib.d.ts as response to goto def in open files
@sheetalkamat
If files are not open dont schedule open file project ensure
0820519
@sheetalkamat
Sheetal Nandi (sheetalkamat) force-pushed the web-worker-server branch from 80cbd9c to 0820519 Compare November 14, 2020 00:43
@sheetalkamat Sheetal Nandi (sheetalkamat) mentioned this pull request Nov 14, 2020
If there are no open files, do not schedule ensureProjectForOpenFiles #41537
Merged
@sheetalkamat
Should also check if there are no external projects before skipping s…
7e49390
…cheduling

Fixes failing tests
Megan Rogge (meganrogge) pushed a commit to microsoft/vscode that referenced this pull request Nov 18, 2020
Matt Bierner @meganrogge
Add support for web TS Server logging over postMessage
eafed3c
For microsoft/TypeScript#39656
Sheetal Nandi (sheetalkamat) added 3 commits November 18, 2020 10:49
@sheetalkamat
Revert "Map the paths back to https:"
16ff1ce
This reverts commit 0edf650.
@sheetalkamat
Revert "TODO"
9952bab
This reverts commit 04a4fe7.
@sheetalkamat
Revert "Should also check if there are no external projects before sk…
2bf35c9
…ipping scheduling"

This reverts commit 7e49390.
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Nov 19, 2020
TypeScript 4.2 Iteration Plan #41601
Closed
@sheetalkamat
Merge branch 'master' into web-worker-server
3c94c98
@sheetalkamat
Sheetal Nandi (sheetalkamat) marked this pull request as ready for review November 21, 2020 00:20
@typescript-bot

TypeScript Bot (typescript-bot) commented Nov 21, 2020

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat
Sheetal Nandi (sheetalkamat) requested review from Ryan Cavanaugh (RyanCavanaugh), Andrew Casey (amcasey) and Andrew Branch (andrewbranch) November 21, 2020 00:20
@sheetalkamat
Refactoring so we can test the changes out
542a8b0
sheetalkamat
Sheetal Nandi (sheetalkamat) approved these changes Nov 21, 2020
View reviewed changes
amcasey
Andrew Casey (amcasey) reviewed Nov 24, 2020
View reviewed changes

@amcasey Andrew Casey (amcasey) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

First round of comments.

Also, does this create a new output file? Should it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/server/session.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/server/session.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/tsserver/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/webServer/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/webServer/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/webServer/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/webServer/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/webServer/webServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Sheetal Nandi (sheetalkamat) added 2 commits December 1, 2020 18:20
@sheetalkamat
Feedback
245e49d
@sheetalkamat
Merge branch 'master' into web-worker-server
9704738
@sheetalkamat

Sheetal Nandi (sheetalkamat) commented Dec 2, 2020

Copy link
Copy Markdown
Member

Also, does this create a new output file? Should it?

My understanding is that the goal is to have tsserver.js support webWorker. The delta is not huge (15K) so seems like good option:

12/01/2020  06:26 PM         9,661,335 tsserver.js     <<< Built from master branch
12/01/2020  06:24 PM         9,677,119 tsserver.web.js << Built from this fork

Will let Ryan Cavanaugh (@RyanCavanaugh) Matt Bierner (@mjbvz) Daniel Rosenwasser (@DanielRosenwasser) Mine Starks (@minestarks) chime in their thoughts.

amcasey reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sheetalkamat
Sheetal Nandi (sheetalkamat) requested a review from Andrew Casey (amcasey) December 2, 2020 02:32
amcasey
Andrew Casey (amcasey) approved these changes Dec 7, 2020
View reviewed changes

@amcasey Andrew Casey (amcasey) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'll probably add some more organizational notes, but this approach looks fine.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
amcasey
Andrew Casey (amcasey) reviewed Dec 7, 2020
View reviewed changes
Comment thread src/tsserver/server.ts
unknownServerMode?: string;
startSession: (option: StartSessionOptions, logger: Logger, cancellationToken: ServerCancellationToken) => void;
}
function start({ args, logger, cancellationToken, serverMode, unknownServerMode, startSession: startServer }: StartInput, platform: string) {

@amcasey Andrew Casey (amcasey) Dec 7, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This seems like a convoluted way to share this initialization code. For example, serverMode is extracted from the StartInput and then passed back into startServer. It might be tidier to extract some initialization helpers (e.g. logHeader) and then have each code path (i.e. web and node) call them separately. Such an exercise might also reveal bits that shouldn't be shared (e.g. why does the web server need to print out the node version in its header?).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sheetalkamat
Sheetal Nandi (sheetalkamat) merged commit 49d7de1 into microsoft:master Dec 9, 2020
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Feb 11, 2021
TypeScript 4.3 Iteration Plan #42762
Closed
@weswigham Wesley Wigham (weswigham) mentioned this pull request Nov 30, 2021
Allow loading custom typescript.tsdk settings on web hosts microsoft/vscode#138211
Closed
@orta Orta Therox (orta) mentioned this pull request Dec 1, 2021
Explore running the TypeScript Playground as a vscode extension inside vscode.dev microsoft/TypeScript-Website#2156
Closed
@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.

Reviewers

@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat approved these changes
@andrewbranch Andrew Branch (andrewbranch) Awaiting requested review from andrewbranch
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh
+1 more reviewer
@amcasey Andrew Casey (amcasey) amcasey approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@sheetalkamat Sheetal Nandi (sheetalkamat)

Labels

Experiment A fork with an experimental idea which might not make it into master For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@mjbvz @sheetalkamat @typescript-bot @amcasey @sandersn
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.