Skip to content

feat: support user defined macro snippet for completion - #23058

Open
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:custom-macro-snippet
Open

feat: support user defined macro snippet for completion#23058
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:custom-macro-snippet

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Aug 6, 2026

Copy link
Copy Markdown
Member

This feature can improve the completion details of macros

And this feature can be utilized to implement excellent DSL completion

Example

#[rust_analyzer::macro_style(snippet = "${path}!($1, $2)")]
macro_rules! assert_eq { ($($t:tt)*) => {} }

fn main() { a$0 }

Before this PR

fn main() { assert_eq!() }

After this PR

fn main() { assert_eq!($1, $2) }

macro_rules! html {
    (<div>$($t:tt)*) => {
        /* ... */
    };
    ($($t:tt)*) => {{
        #[rust_analyzer::macro_style(snippet = "<div>\n    $1\n</div>")]
        macro_rules! div { () => {} }
        $($t)*
    }}
}

fn main() {
    html! {
        d$0
    }
}

->

fn main() {
    html! {
        <div>
            $1
        </div>
    }
}

This feature can improve the completion details of macros

And this feature can be utilized to implement excellent DSL completion

Example
---
```rust
#[rust_analyzer::macro_style(snippet = "${path}!($1, $2)")]
macro_rules! assert_eq { ($($t:tt)*) => {} }

fn main() { a$0 }
```

**Before this PR**

```rust
fn main() { assert_eq!() }
```

**After this PR**

```rust
fn main() { assert_eq!($1, $2) }
```

---

```rust
macro_rules! html {
    (<div>$($t:tt)*) => {
        /* ... */
    };
    ($($t:tt)*) => {{
        #[rust_analyzer::macro_style(snippet = "<div>\n    $1\n</div>")]
        macro_rules! div { () => {} }
        $($t)*
    }}
}

fn main() {
    html! {
        d$0
    }
}
```

->

```rust
fn main() {
    html! {
        <div>
            $1
        </div>
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor

This feature needs design discussions.

Theoretically, if we make it clear that there are absolutely no stability guarantees, it wouldn't, but I suspect people will still complain, so I don't want that.

@A4-Tacks

A4-Tacks commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

This feature needs design discussions.

On zulip? or this PR?

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Zulip is better.

@A4-Tacks

A4-Tacks commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants