Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore running the TypeScript Playground as a vscode extension inside vscode.dev #2156

Closed
orta opened this issue Nov 18, 2021 · 8 comments
Closed
Labels
Idea A way we can improve the site Playground Issues that affect the Playground

Comments

@orta
Copy link
Contributor

orta commented Nov 18, 2021

Take the concept of the playground, and remove our custom UI - have that run inside vscode.dev.

Proof of concept: https://github.com/orta/vscode-typescript-playground

@DanielRosenwasser DanielRosenwasser added Idea A way we can improve the site Playground Issues that affect the Playground labels Nov 18, 2021
@orta
Copy link
Contributor Author

orta commented Dec 1, 2021

VSCode Powered Playgrounds Roadmap

The above proof of concept has been hooked up fully to vscode.dev now, and we've taken a step back to figure out how this can work structurally.

Today, the playground has its own copy of the TypeScript compiler API which is used to generate things like the .js, .d.ts, grab errors etc, it is used for introspection in the docs. We extract this TS version from Monaco's globals and pass it around to other tools.

We wonder if instead of the playground having a full copy of the typescript compiler, it instead sets up and makes requests to the tsserver provided by the default vscode typescript extension. Leaving the playground to effectively be a smart wrapper around the existing tsserver, with useful introspection tooling in the extension.

This solution has this nice balance of the TS team controlling the tsserver side (so TS can add extra tsserver commands for introspection when needed ) and the vscode team mostly focusing on the IDE side with a fully fleshed out vfs for testing stuff in provided by ts playground extension.

To make that work, we'd need a few things:

This leaves a few holes where the ts API was used (e.g. the compiler UI dropdown) but that's solvable by knowing the TS version and knowing when a flag was added and pre-baking this info into the extension probably, and/or we add a tsservice command for info about the compiler's settings.

Examples

All of the code samples are available in JSON dumps by the TS website: https://www.typescriptlang.org/js/examples/en.json / https://www.typescriptlang.org/js/examples/ja.json - the playground just needs to ask for the hosted file: https://www.typescriptlang.org/js/examples/en/3-7/Syntax%20and%20Messaging/Flattened%20Error%20Reporting.ts

Running Code

vscode has a lot of security tooling set up in the JS environment which makes it hard to arbitrarily execute the user's JS, perhaps the debugging extension gives us a route for that. If not we can run it in a webworker, but capturing logs might get complicated then.

TS Version Support

Because we're looking at relying on the vscode side to handle the IDE integration, in theory we can only use versions which include this PR: microsoft/TypeScript#39656 ( 4.3+ ) out of the box. To handle backwards compat we can make builds of older versions of TypeScript which have this PR in user-land code to replicate the same behavior and put it in our CDN.

@orta
Copy link
Contributor Author

orta commented Dec 7, 2021

microsoft/vscode#138621 would hook up the full tsserver (supporting multifile/ ATA at a bare minimum) to vscode ts playgrounds

@orta
Copy link
Contributor Author

orta commented Dec 9, 2021

Confirming that the tsserver requests work well now that it's available in the nightlies. The files in our vfs have paths like ^/playfs/index.tsx, so I can call:

vscode.commands.executeCommand('typescript.tsserverRequest', 'emit-output', { file: "^/playfs/index.tsx" }).then(r => {
    console.log("Got", r)
})

Which would return the .ts and .js files if the TSServer was not in partial mode. microsoft/vscode#138621

@orta
Copy link
Contributor Author

orta commented Dec 9, 2021

I've been exploring using the setting UI to showcase the tsconfig vars, this kinda works OK for prototyping:

Screen Shot 2021-12-09 at 3 38 03 PM

But once I put in the full tsconfig the lack of subheadings and the single column really started to make it a bit unweidly, I might need to implement a custom settings page

Screen Shot 2021-12-09 at 3 38 52 PM

@orta
Copy link
Contributor Author

orta commented Jan 5, 2022

The codebase which it runs on is https://github.com/orta/vscode-typescript-playground - but I built out a monorepo for many vscode extensions in https://github.com/microsoft/TypeScript-VSCode-Extensions (for example me/Ron/Andrew branch have TS related extensions). The version on my account is further along than the version in the MS org.

We already have a typescript marketplace account, probably for the VS side, but I've not figured out how I can get access to a write token to be able to deploy with it though, so it's a bit stunted in usage.

I think the next major thing which needs building is for the vscode tsserver extension to use the vscode file system. I have a hunch that the web tsservice doesn't touch any user-land files and probably only gets given a file contents via the openFiles part of the protocol. This would mean that providing a vfs to vscode is not reflected in the tsserver APIs.

@orta
Copy link
Contributor Author

orta commented Jan 11, 2022

Been exploring how to get the full server running in vsocde.dev - microsoft/vscode#138621 - right now there's a small change needed in vscode:

export const semanticSupportedSchemes = [
	file,
	untitled,
	walkThroughSnippet,
	vscodeNotebookCell,
];

and then in TS we need to change https://github.com/microsoft/TypeScript/blob/ed014db864165cab3f568eb8e2a0b6ea1ba5f624/src/tsserver/webServer.ts#L47 to be a semantic versions ( microsoft/TypeScript#47401 )

Next to work around the TSSrrver not having access to the vfs files. TSServer currently has all open tabs in memory but nothing else.

@orta
Copy link
Contributor Author

orta commented Jan 12, 2022

Made a request about setting the URL from an extension to vscode: https://github.com/microsoft/vscode/issues/140559

@typescript-bot
Copy link
Collaborator

Hello! As per #2804, we are automatically closing all open issues. Please see #2804 for a description of what issues and PRs can be accepted going forward.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Idea A way we can improve the site Playground Issues that affect the Playground
Projects
None yet
Development

No branches or pull requests

3 participants