rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.09k stars 1.57k forks source link

Adopt Vscode Native Notebooks (with evcxr) #5141

Closed Matelasse closed 1 year ago

Matelasse commented 4 years ago

Hi. Not sure if supporting this feature would be inline with the philosophy of the rust-analyzer extension, but for what's it worth this is the single best extension we have for Rust now. Vscode has been shipping its native API for notebooks and supporting an Evcxr rust kernel should be possible. Python and Julia extensions are working on jupyter notebook support now and I think everyone would love to see Rust notebooks. (in case you aren't familiar with the Native Notebooks API, it's basically Vscode providing UI/notebook functionality for free, and the extension's responsibility would be to hook up the vscode notebook to evcxr kernel if i'm not oversimplifying it by too much).

Would you be against seeing this added in rust-analyzer @matklad ?

matklad commented 4 years ago

cc @davidlattimore

At the moment, rust-analyzer doesn't do compilation and execution of rust code, and that's going to be the case for forseeable future. rust-analyzer can expose some additional static analysis API (like we do for higlighitng) and can maybe shell out to some external tool to (like we do for cargo check), but I am not familiar enough with the domain to understand if that is something that makes sense.

davidlattimore commented 4 years ago

Would it work to create a separate vscode extension to do this?

If both extensions were installed, then hopefully it'd be possible to still have rust-analyzer process the Jupyter cells as Rust code. Although I guess if rust-analyzer wasn't aware of some Evcxr-specific things it might get somewhat confused. Specifically:

I'd been meaning for a long time to try and make use of rust-analyzer from evcxr, but as yet haven't done any work.

A moderate amount of the work would probably involve dealing with the above evcxr-specific things. The approach I was thinking of assumes that rust-analyzer wouldn't be aware of evcxr and evcxr would need to present the user's code as though it were a regular Rust program. Evcxr already does this with the Rust compiler. :dep adds a dependency to Cargo.toml. The user's code is split into items and statements and the statements are wrapped in a function. Variables are stored and loaded to and from a map etc. Those same manipulations could be applied to the Jupyter cell that the user is currently editing and present the resulting wrapped code to rust-analyzer. You'd then need to map the spans of any errors back to the original source so that they could be shown correctly in vscode.

@Matelasse if you'd like to do any such integration, that'd be awesome and I'd of course provide whatever assistance I could.

HKalbasi commented 1 year ago

Currently vscode jupyter works with evcxr out of the box. The intellisence support in jupyter notebooks is tracked in #9343 so I think we can close this issue.