-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
feat(rustc_unpretty): use rustc inspect mir #192
feat(rustc_unpretty): use rustc inspect mir #192
Conversation
Review ChecklistDoes this PR follow the Contribution Guidelines? Following is a partial checklist: Proper conventional commit scoping:
If applicable:
|
Hey 👋 This looks great! Thanks for the PR! 😄 I'll have a closer look at it later today. |
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.
Thanks again for this awesome PR! ❤️
I have left some thoughts and suggestions.
Let me know if you'd like to implement them. If not, I'm happy to merge this into a feature branch and implement them myself 😄
@@ -97,6 +97,27 @@ local command_tbl = { | |||
local cmd = args[1] or 'run' | |||
require('rustaceanvim.commands.fly_check')(cmd) | |||
end, | |||
rustcUnpretty = function(args) |
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.
thought: rust-analyzer
isn't required for this command. Perhaps it would be better to create a separate Rustc
command?
issue: The -Z
option requires a nightly compiler.
So we should document that in the readme and lua docs (which I use to generate vimdoc).
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.
I'm not familiar with the code structure, so I'll pass on this task.
-- Get a compatible vim range (1 index based) from a TS node range. | ||
-- | ||
-- TS nodes start with 0 and the end col is ending exclusive. | ||
-- They also treat a EOF/EOL char as a char ending in the first | ||
-- col of the next row. |
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.
quibble: Doc comments should have a ---
commentstring.
(just relevant for lua-language-server hovers here 😄)
-- Get a compatible vim range (1 index based) from a TS node range. | |
-- | |
-- TS nodes start with 0 and the end col is ending exclusive. | |
-- They also treat a EOF/EOL char as a char ending in the first | |
-- col of the next row. | |
--- Get a compatible vim range (1 index based) from a TS node range. | |
--- | |
--- TS nodes start with 0 and the end col is ending exclusive. | |
--- They also treat a EOF/EOL char as a char ending in the first | |
--- col of the next row. |
pos = { temp[1] - 1, temp[2] } | ||
end | ||
|
||
local node = ts.get_node { pos = pos } |
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.
issue: I tested this (on a line that doesn't contain fn
), and got:
Error executing Lua callback: ...rapped-98a4ed0/share/nvim/runtime/lua/vim/treesitter.lua:392: Invalid position: row and col must be non-negative
with a stack trace that leads to this function call.
local node = ts.get_node { pos = pos } | ||
|
||
if node == nil or node:type() ~= 'function_item' then | ||
vim.notify('not found function or function is uncomplete', vim.log.levels.ERROR) |
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.
quibble
vim.notify('not found function or function is uncomplete', vim.log.levels.ERROR) | |
vim.notify('no function found or function is incomplete', vim.log.levels.ERROR) |
---@param level rustcir_level | ||
function M.rustc_unpretty(level) | ||
if #api.nvim_get_runtime_file('parser/rust.so', true) == 0 then | ||
vim.notify('please install rust parser in nvim-treesitter', vim.log.levels.ERROR) |
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.
suggestion: Technically, nvim-treesitter is not required.
vim.notify('please install rust parser in nvim-treesitter', vim.log.levels.ERROR) | |
vim.notify('a treesitter parser for Rust is required for 'rustc unpretty'', vim.log.levels.ERROR) |
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.
Is there a better way to obtain the function?
I'm not sure what to do.
---settings for rustc -Z unpretty | ||
---@type table | ||
rustc_unpretty = { | ||
---@type string | ||
edition = '2021', | ||
}, |
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.
issue: This is the internal config.
There's another 'meta' module, rustaceanvim/config/init.lua
that contains luacats documentation, from which I generate vimdoc in CI.
1bb620a
to
d0cec19
Compare
bcdbd3b
to
d0cec19
Compare
docs(README): rustc unpretty need nightly
I think I have done all I can do. 😄 |
Thanks 🙏. I'll merge it into the |
@saying121 I've just finished the touchup and pushed a 4.1.0 release. The command is now Thanks again for the awesome contribution 🙏 😄 |
Use
rustc -Z unpretty=mir
to inspect mir and other things,and achieve an experience similar to Rust Playground.
The rust-analyzer view does not support viewing MIR for async blocks,
but rustc can do it.