-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Suggestions/examples/alternatives/best fit/workaround tips, please, on how to create a VS Code extension for custom macro_rules-based macros (prudent) in Rust. Goal:
- auto-complete (auto-complete Rust expressions matching the type of the relevant position-based "parameters" of the macro), and
- inlay hints (names and types of the macro's positional "parameters")
for "parameters" in a (simple, most likely regex-friendly) input grammar to custom macros in Rust. Preferring to forward the auto-complete/inlay hints for those "parameter" values and types to VS Code/rust-analyzerLSP.
Briefly considered: CompletionItem, embedded language with Request Forwarding, and/or a custom LSP forwarding to another:
- https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-embedded-request-forwarding - I prefer this. Is this (generally) much easier than writing a new LSP (for addressing the same subset of the "outer" + "inner/embedded" language)?
- https://github.com/microsoft/vscode-extension-samples/tree/main/completions-sample - I hope not to need this at this low level.
- https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample and
https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-user-input-sample - How to actually use/trigger the UI? I hope I won't need this low level. - an LSP, and communicating to
rust-analyzerLSP on my own (I hope not to).
I'm completely new to VS Code extensions and/or LSP development. Anything else to consider (or to ignore), please?
Perceived initial problem/milestone: If I follow the above lsp-embedded-request-forwarding sample, or whatever you suggest, can I NOT just scan for fixed substrings/regexes to find my embedded regions (invocations of my macros)? The "problem" with Rust: The consumer code can access my crate's macros under various names/paths, both by aliasing or without. Like
pub fn some_fn() {
prudent::unsafe_fn!(...);
::prudent::unsafe_fn!(...);
use ::prudent as prudentish;
...
prudentish::unsafe_fn!(...);
crate::prudent::unsafe_fn!(...);
crate::prudentish::unsafe_fn!(...);
or even less trivial relative paths through local modules like:
mod inner_module{
fn some_function() {
super::prudentish::unsafe_fn!(...);
}
}So, can I somehow tell VS Code to invoke/apply my extension to regions based on another LSP? Or, if I do have to query the other LSP myself (in order to determine whether the region is "embedded"), is there a way to do this so that I don't query the other LSP everytime the text cursor is moved?
Slint's VS Code extension with LSP can do that: it works even if slint crate is aliased/re-exported. But, from a brief look, I couldn't figure how it does that.
use slint as slintish;
mod m {
super::slintish::slint!{
export component HelloWorld {
Text {
text: "hello world";
color: green;
}
}
}
pub fn main() {
HelloWorld::new().unwrap().run().unwrap();
}
}
use m::main;prudent, the Rust crate with macros involved, is a work in progress, and open to change to accommodate whatever is needed for such a VS Code extension/LSP to work.
It's not enough to "just use" rust-analyzer (rust-lang/rust-analyzer#11323).
If making it VS Code-only would be much less work than a general LSP, then VS Code-only is fine. (Someone else can step up for the whole/universal LSP later.)
Thank you in advance.