posit-dev / positron

Positron, a next-generation data science IDE
Other
2.39k stars 70 forks source link

URL reshaping and proxying for Positron localhost URLs on Posit Workbench #4274

Open jmcphers opened 1 month ago

jmcphers commented 1 month ago

Positron currently uses localhost URLs to serve content in many places.

These URLs won't be visible to browsers by default in Workbench; they will need to get transformed into proxied Posit Workbench URLs at some point so that they can be loaded in the browser.

One way to do this might be to use the resolver API, which is part of VS Code upstream and is defined here:

https://github.com/posit-dev/positron/blob/main/src/vscode-dts/vscode.proposed.resolvers.d.ts

Using this API allows us to request that any registered resolvers process the URL before we load it in Positron. Here's an example of where we call the API on the Positron side:

https://github.com/posit-dev/positron/blob/de62b4ee561390e86d0ea5f0d9c09a40d976a80a/src/vs/workbench/services/languageRuntime/common/languageRuntimeUiClient.ts#L155-L161

So a solution could look like this. Here I'm using "Help Server" as an example, but this is akin to what we need to do for each local URL.

graph TD
he[Help Pane] -- localhost URL --> p[Positron]
hs[Help Server] -- localhost URL --> he
p[Positron] -- localhost URL --> pw[Posit Workbench Extension]
pw -- external URL --> p
p -- external URL --> b[Browser] 
b -- HTTP request --> w[Posit Workbench]
w -- HTTP proxy --> hp
hp[Positron Help Proxy] --> hs
hs -- help content --> hp
hp -- help content --> w
w -- help content --> b
jmcphers commented 1 month ago

There's definitely some overlap here with the existing logic in the Posit Workbench extension, which already has logic for discovering localhost URLs and creating proxies for them. We could choose to re-use some of that code, or refactor that code to use the resolver APIs.