All Projects → simrat39 → rust-tools.nvim

simrat39 / rust-tools.nvim

Licence: MIT license
Tools for better development in rust using neovim's builtin lsp

Programming Languages

lua
6591 projects
dart
5743 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to rust-tools.nvim

dotfiles
i3, Vim, Bash, Ruby, Typescript & React, Elixir, Golang & more!
Stars: ✭ 22 (-98.2%)
Mutual labels:  nvim
code runner.nvim
Neovim plugin.The best code runner you could have, it is like the one in vscode but with super powers, it manages projects like in intellij but without being slow
Stars: ✭ 234 (-80.84%)
Mutual labels:  nvim
firvish.nvim
WIP
Stars: ✭ 31 (-97.46%)
Mutual labels:  nvim
dotfiles
Salonia Matteo's dotfiles (GNU/Linux configuration)
Stars: ✭ 19 (-98.44%)
Mutual labels:  nvim
deoplete-elm
Deoplete plugin for elm-oracle.
Stars: ✭ 23 (-98.12%)
Mutual labels:  nvim
awesome-neovim
Awesome Configurations for C/C++,Zig,Web and Lua development in NeoVim
Stars: ✭ 54 (-95.58%)
Mutual labels:  nvim
angr.vim
A pleasant, mild, dark (n)vim theme.
Stars: ✭ 53 (-95.66%)
Mutual labels:  nvim
dotfiles
A place to store config files so I can revert when my entire system crashes from entering the wrong character
Stars: ✭ 25 (-97.95%)
Mutual labels:  nvim
Neovim-from-scratch
📚 A Neovim config designed from scratch to be understandable
Stars: ✭ 3,825 (+213.27%)
Mutual labels:  nvim
tabby.nvim
A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
Stars: ✭ 232 (-81%)
Mutual labels:  nvim
toml-bombadil
A dotfile manager with templating
Stars: ✭ 127 (-89.6%)
Mutual labels:  rust-tools
nvim-hclipboard
Hijack your clipboard in Neovim
Stars: ✭ 19 (-98.44%)
Mutual labels:  nvim
nightfox.nvim
🦊A highly customizable theme for vim and neovim with support for lsp, treesitter and a variety of plugins.
Stars: ✭ 1,489 (+21.95%)
Mutual labels:  nvim
nvim-metals
A Metals plugin for Neovim
Stars: ✭ 265 (-78.3%)
Mutual labels:  nvim
bubbly.nvim
Bubbly statusline for neovim
Stars: ✭ 185 (-84.85%)
Mutual labels:  nvim
vim-colors-sketching
A minimal light colorscheme for Vim/Neovim
Stars: ✭ 21 (-98.28%)
Mutual labels:  nvim
neovim-lua-plugin-boilerplate
Starter template for creating Neovim Lua plugins
Stars: ✭ 28 (-97.71%)
Mutual labels:  nvim
nvim
❤️ A neovim config repo.
Stars: ✭ 33 (-97.3%)
Mutual labels:  nvim
dots
Code Smell Dotfiles
Stars: ✭ 163 (-86.65%)
Mutual labels:  nvim
cargo-limit
Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
Stars: ✭ 105 (-91.4%)
Mutual labels:  nvim

rust-tools.nvim

A plugin to improve your rust experience in neovim.

Quick Links

Prerequisites

  • neovim 0.7
  • nvim-lspconfig
  • rust-analyzer
  • dot from graphviz (only for crate graph)

Installation

using packer.nvim

use 'neovim/nvim-lspconfig'
use 'simrat39/rust-tools.nvim'

-- Debugging
use 'nvim-lua/plenary.nvim'
use 'mfussenegger/nvim-dap'

Look at the configuration information below to get started.

Setup

This plugin automatically sets up nvim-lspconfig for rust_analyzer for you, so don't do that manually, as it causes conflicts.

Put this in your init.lua or any lua file that is sourced.

For most people, the defaults are fine, but for advanced configuration, see Configuration.

Example config:

local rt = require("rust-tools")

rt.setup({
  server = {
    on_attach = function(_, bufnr)
      -- Hover actions
      vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
      -- Code action groups
      vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
    end,
  },
})

Usage

Debugging

debugging

Inlay Hints

inlay hints

-- Commands:
-- RustEnableInlayHints
-- RustDisableInlayHints
-- RustSetInlayHints
-- RustUnsetInlayHints

-- Set inlay hints for the current buffer
require('rust-tools').inlay_hints.set()
-- Unset inlay hints for the current buffer
require('rust-tools').inlay_hints.unset()

-- Enable inlay hints auto update and set them for all the buffers
require('rust-tools').inlay_hints.enable()
-- Disable inlay hints auto update and unset them for all buffers
require('rust-tools').inlay_hints.disable()
Runnables

runnables

-- Command:
-- RustRunnables
require('rust-tools').runnables.runnables()
Expand Macros Recursively

expand macros

-- Command:
-- RustExpandMacro  
require'rust-tools'.expand_macro.expand_macro()
Move Item Up/Down

move items

-- Command:
-- RustMoveItemUp    
-- RustMoveItemDown    
local up = true -- true = move up, false = move down
require'rust-tools'.move_item.move_item(up)
Hover Actions

hover actions Note: To activate hover actions, run the command twice (or your hover keymap if you have hover_with_actions set to true AND are using vim.lsp.buf.hover()). This will move you into the window, then press enter on the selection you want. Alternatively, you can set auto_focus to true in your config and you will automatically enter the hover actions window.

-- Command:
-- RustHoverActions 
require'rust-tools'.hover_actions.hover_actions()
Hover Range

Note: Requires rust-analyzer version after 2021-08-02. Shows the type in visual mode when hovering.

-- Command:
-- RustHoverRange 
require'rust-tools'.hover_range.hover_range()
Open Cargo.toml

open cargo

-- Command:
-- RustOpenCargo
require'rust-tools'.open_cargo_toml.open_cargo_toml()
Parent Module

parent module

-- Command:
-- RustParentModule 
require'rust-tools'.parent_module.parent_module()
Join Lines

join lines

-- Command:
-- RustJoinLines  
require'rust-tools'.join_lines.join_lines()
Structural Search Replace
-- Command:
-- RustSSR [query]
require'rust-tools'.ssr.ssr(query)
View Crate Graph
-- Command:
-- RustViewCrateGraph [backend [output]]
require'rust-tools'.crate_graph.view_crate_graph(backend, output)

Configuration

The options shown below are the defaults. You only need to pass the keys to the setup function that you want to be changed, because the defaults are applied for keys that are not provided.

local opts = {
  tools = { -- rust-tools options

    -- how to execute terminal commands
    -- options right now: termopen / quickfix
    executor = require("rust-tools/executors").termopen,

    -- callback to execute once rust-analyzer is done initializing the workspace
    -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
    on_initialized = nil,

    -- automatically call RustReloadWorkspace when writing to a Cargo.toml file.
    reload_workspace_from_cargo_toml = true,

    -- These apply to the default RustSetInlayHints command
    inlay_hints = {
      -- automatically set inlay hints (type hints)
      -- default: true
      auto = true,

      -- Only show inlay hints for the current line
      only_current_line = false,

      -- whether to show parameter hints with the inlay hints or not
      -- default: true
      show_parameter_hints = true,

      -- prefix for parameter hints
      -- default: "<-"
      parameter_hints_prefix = "<- ",

      -- prefix for all the other hints (type, chaining)
      -- default: "=>"
      other_hints_prefix = "=> ",

      -- whether to align to the length of the longest line in the file
      max_len_align = false,

      -- padding from the left if max_len_align is true
      max_len_align_padding = 1,

      -- whether to align to the extreme right or not
      right_align = false,

      -- padding from the right if right_align is true
      right_align_padding = 7,

      -- The color of the hints
      highlight = "Comment",
    },

    -- options same as lsp hover / vim.lsp.util.open_floating_preview()
    hover_actions = {

      -- the border that is used for the hover window
      -- see vim.api.nvim_open_win()
      border = {
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
        { "", "FloatBorder" },
      },

      -- whether the hover action window gets automatically focused
      -- default: false
      auto_focus = false,
    },

    -- settings for showing the crate graph based on graphviz and the dot
    -- command
    crate_graph = {
      -- Backend used for displaying the graph
      -- see: https://graphviz.org/docs/outputs/
      -- default: x11
      backend = "x11",
      -- where to store the output, nil for no output stored (relative
      -- path from pwd)
      -- default: nil
      output = nil,
      -- true for all crates.io and external crates, false only the local
      -- crates
      -- default: true
      full = true,

      -- List of backends found on: https://graphviz.org/docs/outputs/
      -- Is used for input validation and autocompletion
      -- Last updated: 2021-08-26
      enabled_graphviz_backends = {
        "bmp",
        "cgimage",
        "canon",
        "dot",
        "gv",
        "xdot",
        "xdot1.2",
        "xdot1.4",
        "eps",
        "exr",
        "fig",
        "gd",
        "gd2",
        "gif",
        "gtk",
        "ico",
        "cmap",
        "ismap",
        "imap",
        "cmapx",
        "imap_np",
        "cmapx_np",
        "jpg",
        "jpeg",
        "jpe",
        "jp2",
        "json",
        "json0",
        "dot_json",
        "xdot_json",
        "pdf",
        "pic",
        "pct",
        "pict",
        "plain",
        "plain-ext",
        "png",
        "pov",
        "ps",
        "ps2",
        "psd",
        "sgi",
        "svg",
        "svgz",
        "tga",
        "tiff",
        "tif",
        "tk",
        "vml",
        "vmlz",
        "wbmp",
        "webp",
        "xlib",
        "x11",
      },
    },
  },

  -- all the opts to send to nvim-lspconfig
  -- these override the defaults set by rust-tools.nvim
  -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
  server = {
    -- standalone file support
    -- setting it to false may improve startup time
    standalone = true,
  }, -- rust-analyzer options

  -- debugging stuff
  dap = {
    adapter = {
      type = "executable",
      command = "lldb-vscode",
      name = "rt_lldb",
    },
  },
}

require('rust-tools').setup(opts)

Related Projects

Inspiration

This plugin draws inspiration from akinsho/flutter-tools.nvim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].