mattn / vim-lsp-settings

Auto configurations for Language Server for vim-lsp
MIT License
1.28k stars 229 forks source link

Support expandMacro for rust-analyzer lsp #761

Open simlay opened 1 month ago

simlay commented 1 month ago

There are a bunch of LSP extensions rust-analyzer has. This project implements a few of them. One that it doesn't is rust-analyzer/expandMacro.

Full disclosure, I'm a novice at vimL. I copied the on_rust_analyzer_status function and modified it for the response handler. I won't feel bad about a strong constructive critique.

Below is an example of what my vim looks like when I expand the println! macro. I've got a powerbar plugin at the bottom. The split for the expanded macro yields source that frequently has more macros. Unfortunately, there's no file for that source so I'm not sure it's macro-expandable? I'd love to be able to expand each macro down the chain but my vimscript/vimL is weak.

image
simlay commented 1 month ago

I was curios why the expansions always yield $crate but that crate is different depending on where the macro came from. $crate from println! is std, but with log::info!/trace::info!, it's log or trace. In any case, I don't think the client is suppose to swap those. https://github.com/rust-lang/rust-analyzer/issues/7532 is the issue.

Poking around, some folks may want the macro to expand inline (https://github.com/rust-lang/rust-analyzer/issues/11888#issuecomment-1890985494). That may be a feature for the future as it'd help with being able to manually recurse through the expansions. Given that the macro expansions have $crate in them, I think putting them in a separate/preview split is best for now.

simlay commented 1 month ago

I was about to author a Rust Analyzer LSP Extensions tracking issue (really just a matrix of extensions) when I realized it should probably just go in the notes section of the README along with an example of a .vim-lsp-settings/settings.json. Thoughts?