-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support expandMacro for rust-analyzer lsp #761
Conversation
settings/rust-analyzer.vim
Outdated
setlocal bufhidden=hide | ||
setlocal nobuflisted | ||
setlocal buftype=nofile | ||
setlocal ft=rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, Thank you for great work!
I've try this and love it. But I have some feed backs.
I use g:lsp_diagnostics_virtual_text_enabled = true
.
Execute :LspRustExpandMacro
and move to preview window.
Shows a lot of errors and bit a annoying 😰
Kapture.2024-07-12.22.44.43.mp4
I'm not sure my suggestion is right or not, but set no filetype and enable syntax for preview looks good to me.
diff --git a/settings/rust-analyzer.vim b/settings/rust-analyzer.vim
index b71d6eb..dde8fd7 100644
--- a/settings/rust-analyzer.vim
+++ b/settings/rust-analyzer.vim
@@ -194,10 +194,13 @@ function! s:on_expand_macro(x) abort
setlocal bufhidden=hide
setlocal nobuflisted
setlocal buftype=nofile
- setlocal ft=rust
setlocal noswapfile
%d
call setline(1, l:lines)
+
+ let l:win_id = win_getid()
+ call win_execute(l:win_id, $'setlocal syntax=rust')
+
execute "normal \<c-w>p"
call winrestview(l:view)
let @#=l:alternate
Kapture.2024-07-12.22.42.22.mp4
@mattn Do you have any good solutions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! I don't have the virtual diagnostics enabled but definitely see how it's rough. I think the syntax set to rust works. I've added those changes.
I was curios why the expansions always yield Poking around, some folks may want the macro to expand inline (rust-lang/rust-analyzer#11888 (comment)). 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 |
e9a31a8
to
131c63c
Compare
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 |
@mattn Ping. Any requests on this PR? I find the feature pretty useful. |
Thank you |
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.