Skip to content

Slint-like VS-Code extension and/or LSP #2

@peter-lyons-kehl

Description

@peter-lyons-kehl

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-analyzer LSP.

Briefly considered: CompletionItem, embedded language with Request Forwarding, and/or a custom LSP forwarding to another:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions