Skip to content
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(commands): Rustc unpretty args[] #194

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.1.0] - 2024-01-29

### Added

- `:Rustc unpretty` command:
Use `rustc -Z unpretty=[mir|hir|...]` to inspect mir and other things,
and achieve an experience similar to Rust Playground.
(currently requires a nightly compiler).
Thanks [saying121](https://github.com/saying121)!
- Config: `tools.rustc_unpretty` arguments for `rustc`.

### Changed

- Improved command completions.
- Filter suggested subcommand arguments based on existing user input.
- When calling, `:RustLsp!`, show only subcommands that change
behaviour with a bang.

### Fixed

- Command completions: Removed completions
for `runnables/debuggables last`.

## [4.0.3] - 2024-01-28

### Fixed
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
or [`codelldb`](https://github.com/vadimcn/codelldb))
and [`nvim-dap`](https://github.com/mfussenegger/nvim-dap),
required for debugging.
- A tree-sitter parser for Rust (required for the `:Rustc unpretty` command).
Can be installed using [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter),
which also provides highlights, etc.

## Installation

Expand Down Expand Up @@ -491,6 +494,26 @@ vim.keymap.set(
vim.cmd.RustLsp { 'view', 'hir' }
vim.cmd.RustLsp { 'view', 'mir' }
```
<details>
<summary>
<b>Rustc Unpretty</b>
</summary>

Opens a buffer with a textual representation of the MIR or others things,
of the function closest to the cursor.
Achieves an experience similar to Rust Playground.

NOTE: This currently requires a tree-sitter parser for Rust,
and a nightly compiler toolchain.

```vimscript
:Rustc unpretty [hir|mir|...]
```
```lua
vim.cmd.Rustc { 'unpretty', 'hir' }
vim.cmd.Rustc { 'unpretty', 'mir' }
-- ...
```
</details>

<!-- markdownlint-restore -->
Expand Down
16 changes: 16 additions & 0 deletions doc/rustaceanvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ It accepts the following subcommands:
Defaults to `flyCheck run` if called without an argument.
`logFile` - Open the rust-analyzer log file.

The `:Rustc` command can be used to interact with rustc.
It accepts the following subcommands:

`unpretty args[]` - Opens a buffer with a textual representation of the MIR or others things,
of the function closest to the cursor.
Achieves an experience similar to Rust Playground.
NOTE: This currently requires a tree-sitter parser for Rust,
and a nightly compiler toolchain.

==============================================================================
plugin configuration *rustaceanvim.config*

Expand Down Expand Up @@ -117,6 +126,7 @@ RustaceanToolsOpts *RustaceanToolsOpts*
{float_win_config?} (table) Options applied to floating windows. See |api-win_config|.
{create_graph?} (RustaceanCrateGraphConfig) Options for showing the crate graph based on graphviz and the dot
{open_url?} (fun(url:string):nil) If set, overrides how to open URLs
{rustc?} (RustcOpts) Options for `rustc`


RustaceanHoverActionsOpts *RustaceanHoverActionsOpts*
Expand Down Expand Up @@ -152,6 +162,12 @@ RustaceanCrateGraphConfig *RustaceanCrateGraphConfig*
{pipe?} (string) Overide the pipe symbol in the shell command. Useful if using a shell that is not supported by this plugin.


RustcOpts *RustcOpts*

Fields: ~
{edition} (string) The edition to use. See https://rustc-dev-guide.rust-lang.org/guides/editions.html. Default '2021'.


RustaceanLspClientOpts *RustaceanLspClientOpts*

Fields: ~
Expand Down
7 changes: 5 additions & 2 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local config = require('rustaceanvim.config.internal')
local types = require('rustaceanvim.types.internal')
local lsp = require('rustaceanvim.lsp')

if not vim.g.did_rustaceanvim_setup_commands then
if not vim.g.did_rustaceanvim_initialize then
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
local runnables = require('rustaceanvim.runnables')
local cached_commands = require('rustaceanvim.cached_commands')
Expand Down Expand Up @@ -36,9 +36,12 @@ if not vim.g.did_rustaceanvim_setup_commands then
local rt_dap = require('rustaceanvim.dap')
rt_dap.start(args)
end

local commands = require('rustaceanvim.commands')
commands.create_rustc_command()
end

vim.g.did_rustaceanvim_setup_commands = true
vim.g.did_rustaceanvim_initialize = true

local auto_attach = types.evaluate(config.server.auto_attach)

Expand Down
Loading
Loading