-
Notifications
You must be signed in to change notification settings - Fork 94
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
Provide typing for global accessor of the Positron API for multi-IDE extensions #809
Comments
Example of how this is done for the VSCode API exposed to web views: https://www.npmjs.com/package/@types/vscode-webview?activeTab=code |
This is now Kind Of Implemented. You can call
The main problem left to be solved is how to get typings for the API to load correctly in extensions (i.e. we need to somehow tell Typescript that this function returns the |
It is the case that I can't really use this yet then (at least w/ Typescript) b/c there isn't a ready way to "cast" an object to a module? I could also just get it working w/ |
Yeah, I was trying to figure out if there was a way to tell Typescript that the return value is a module but didn't figure it out (there may be a way that I missed). You certainly can use it with |
I would certainly prefer typing! If you think you'll figure out a solution soon I'll wait for that. In the case that we can't figure out a solution, we may need to do something more like VS Code where |
I guess for now I can just cast the return value to an interface that I hand create? (Which I'm doing anyway in this case) |
Yeah, that'll work just fine for typing. It might be simpler to cast specific namespaces to interfaces instead of trying to cast the entire value (e.g. |
Here's how I declared the types: https://github.com/quarto-dev/quarto/blob/main/apps/vscode/src/%40types/hooks.d.ts Then also declared: declare global {
function acquirePositronApi() : positron.PositronApi;
} |
Extensions that are built exclusively for Positron can do this to bring in the Positron API:
This works in Positron, but will fail at runtime in VS Code since the thing that makes it work is the require interceptor (https://github.com/rstudio/positron/blob/main/src/vs/workbench/api/common/extHostRequireInterceptor.ts).
We need a way to load the Positron API safely for extensions that could run in either Positron or VS Code. Proposal:
window.
) that returns this interface in PositronIn this way, Positron-specific extensions can keep using
import * as positron
, and multi-IDE extensions can call something safer liketry { api = getPositronApi() } ...
to access the API.The text was updated successfully, but these errors were encountered: