Git Product home page Git Product logo

rust-tools.nvim's Introduction

Note

Due to lack of time, this plugin has been archived. Please switch to mrcjkb/rustaceanvim.

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 / toggleterm / vimux
    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" },
      },

      -- Maximal width of the hover window. Nil means no max.
      max_width = nil,

      -- Maximal height of the hover window. Nil means no max.
      max_height = nil,

      -- 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

rust-tools.nvim's People

Contributors

1024bees avatar 5c077m4n avatar arinal avatar avimitin avatar baz avatar cairijun avatar danigutsch avatar disrupted avatar frefreak avatar gbrlsnchs avatar indianboy42 avatar kedom1337 avatar krady21 avatar lfdominguez avatar lvim-tech avatar m-lima avatar matze avatar mdietrich16 avatar nesaro avatar p00f avatar rodrigodd avatar samclercky avatar simonboots avatar simrat39 avatar spaarmann avatar sveatlo avatar thehamsta avatar tomtomjhj avatar williamboman avatar zmtq05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-tools.nvim's Issues

turn off treesitter in hover window

I noticed that the hover window treats the entire content as Rust because I believe it uses Treesitter for the entire hover window. Is it possible to turn it off? Ideally it would be great if it only inject TS inside the codeblock but I think TS can only work on buffer level.

with rust-tools:

image

without rust-tools:

image

No commands, and no clippy

Loading lspconfig and rust-tools via Packer. Not running setup with lspconfig and rust-analyzer, but letting rust-tools do it all. I neither get :Commands, nor does clippy work with the config below. It works without rust-tools, setting it up directly with lspconfig. Ideas?

Here's the config:

Packer use:

	-- Rust tools
	use({
		"simrat39/rust-tools.nvim",
                config = function() require('plugins.rust-tools') end,
		disable = false,
	})

This is rust-tools.lua:

local opts = {
	tools = { -- rust-tools options
		-- automatically set inlay hints (type hints)
		-- There is an issue due to which the hints are not applied on the first
		-- opened file. For now, write to the file to trigger a reapplication of
		-- the hints or just run :RustSetInlayHints.
		-- default: true
		autoSetHints = true,

		-- whether to show hover actions inside the hover window
		-- this overrides the default hover handler
		-- default: true
		hover_with_actions = true,

		runnables = {
			-- whether to use telescope for selection menu or not
			-- default: true
			use_telescope = true,

			-- rest of the opts are forwarded to telescope
		},

		inlay_hints = {
			-- wheter 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 lenght 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,
		},

		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" },
			},
		},
	},

	-- 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/CONFIG.md#rust_analyzer
	server = {
		cmd = { "rust-analyzer" },
		on_attach = require("lsp").common_on_attach,
		filetypes = { "rust" },
		root_dir = require("lspconfig.util").root_pattern("Cargo.toml", "rust-project.json"),
		settings = {
			["rust-analyzer"] = {
				checkOnSave = {
					allFeatures = true,
					overrideCommand = {
						"cargo",
						"clippy",
						"--workspace",
						"--message-format=json",
						"--all-targets",
						"--all-features",
					},
				},
			},
		},
	}, -- rust-analyer options
}

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

Manage command arguments that contains shell special characters

The command :RustRunnable is not able to run doctests of the form `XX<[T]>::foo'. I believe '[' is interpreted by the shell as a special character.

The work around I have found is to quote values of args.executableArgs in runnable.lua:44:

   ret = ret .. "'" .. value .. "'" .. " "

(That's the work of a none lua/vim coder.)

Vim commands are no longer defined

Since the last refactor, I am no longer able to call the vim commands defined by rust-tools.nvim (RustRunnables, RustSetInlayHints, etc). I've tried with both my personal config and the one shown in the README. Mine looks like this:

require('rust-tools').setup {
  tools = {
    autoSetHints = false,
    hover_with_actions = false,
    runnables = { use_telescope = false },
  },
}

Am I doing something wrong or am I now supposed to define my own commands for the lua functions?

on_attach not triggering

I've got the following config:

local lsp_on_attach = function(_, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end

  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', { noremap=true, silent=true })
end

require('packer').startup(function(use)
  use {
    'simrat39/rust-tools.nvim',
    requires = {
      {'mattn/webapi-vim'},
      {'neovim/nvim-lspconfig'}
    },
    config = function()
      require('rust-tools').setup {
        -- 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/CONFIG.md#rust_analyzer
        server = {
          on_attach = lsp_on_attach,
          flags = {
            debounce_text_changes = 150,
          }
        }, -- rust-analyer options
      }
    end
  }
end)

When I open a Rust file, I can see that rust-tools is loaded (I can, for example, run runnables), but the key binding K is missing. I've pieces this together from the different docs on packer and lspconfig, but there appears to be something that makes on_attach not work as expected?

Run :RustViewCrateGraph failed

HI @simrat39

Thanks for this useful plugin.

I got an issue.

cd tmp
cargo new hello_cargo
cd hello_cargo
nvim src/main.rs

and run :RustViewCrateGraph command.
image

:RustViewCrateGraph doesn't work well.

Some Info
rust-tools.nvim: eb6ac6c

NVIM v0.6.0-dev+355-g187e3a3b7raph. This may take a while...
Build type: Release
LuaJIT 2.1.0-beta3

cargo 1.48.0 (65cbdd2dc 2020-10-14)
rust: stable 1.55.0 (bottled), HEAD

macOS Big Sur Version 11.6 with XQuartz installed.

nvim for rust config

-- setup rust-tools
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.resolveSupport = {
  properties = {
    'documentation',
    'detail',
    'additionalTextEdits',
  }
}
capabilities = vim.tbl_extend('keep', capabilities or {}, lsp_status.capabilities)

capabilities.experimental = {}
capabilities.experimental.hoverActions = true

local opts = {
    tools = {
      autoSetHints = true,
      hover_with_actions = true,
      runnables = {
          use_telescope = true
      },
      debuggables = {
          use_telescope = true
      },
      inlay_hints = {
          show_parameter_hints = true,
          parameter_hints_prefix = "<-",
          other_hints_prefix  = "=>",
      },
      hover_actions = {
        border = {
          {"", "FloatBorder"}, {"", "FloatBorder"},
          {"", "FloatBorder"}, {"", "FloatBorder"},
          {"", "FloatBorder"}, {"", "FloatBorder"},
          {"", "FloatBorder"}, {"", "FloatBorder"}
        },
        -- whether the hover action window gets automatically focused
        auto_focus = true
      },
      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,
        -- 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"
        -- }
      }
    },
    server = { -- setup rust_analyzer
      on_attach = lsp_on_attach,
      capabilities = capabilities,
    },
    -- dap = {
    --   adapter = {
    --     type = 'executable',
    --     command = 'lldb-vscode',
    --     name = "rt_lldb"
    --   }
    -- }
}

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

If my config or something is wrong, please let me know.

Thank you.

Format after RustExpandMacro

It would be nice to be able to format the code in the expanded, I've tried running lua vim.lsp.buf.formatting_sync() but didn't affect the code

Convert to manual impl puts `$0` in front of generated fn

Hello,

Convert to manual impl puts $0 in front of generated fn.

#[derive(Debug, Clone)]
pub struct Foo {
    pub value: u32,
}

After calling "Convert to manual ..." code action, I get this:

pub struct Foo {
    pub value: u32,
}

impl std::fmt::Debug for Foo {
    $0fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Foo").field("value", &self.value).finish()
    }
}

impl Clone for Foo {
    $0fn clone(&self) -> Self {
        Self { value: self.value.clone() }
    }
}

That $0 in front of fn seems strange and I don't know where it came from.

Random error in lua/rust-tools/inlay_hints.lua line 85

Hi,
I am randomly getting an error that the parameter to len is 'nil' instead of a string. It seems to happen when I switch from a Rust buffer to a non-rust one.

I will try to give you a better repro if I can. In the meantime perhaps you can check for nil at that point in the code? It seems a good improvement anyhow.

Sorry I can't do it myself but I don't speak Lua and don't want to mess things up.

Error when executing RustRunnable or RustDebuggable

I have the following error:

E5108: Error executing lua ...plugged/rust-tools.nvim/lua/rust-tools/runnables.lua:39:
  bad argument #1 to 'ipairs' (table expected, got nil)

I am still running on the linux distro where the lua jit compiler does not support goto statements, maybe another lua compat trouble?

LSP only starts after editing a file twice

Hello,

I'm using the default configuration found on the main github page within my rust.lua file.

However, for some reason the LSP only attaches after I enter another buffer (usually the same file), after which LspInfo correctly shows it as being attached to the rust analyzer.

Is this a configuration ordering problem? the plugin isn't broken, but having to open a file twice to get LSP started is getting old. especially when you mix that with the fact that inlay hints don't always leave after I solve the problem and it makes for a cumbersome experience.

Don't get me wrong, I LOVE your plugin and this is more of an annoyance than a show-stopping bug, but i'm just having trouble understanding how such strange behavior could be happening. if this is an lspconfig thing I can bring it over there because it seems that MOST of rust-tools work before I edit the file a second time, it just doesn't show the inlay hints and inlay types until I actually get it all configured.

Thank you for your hard work and any time or knowledge you may have on this subject.

RustRunnables not work on Windows

On windows, when hitting the items in RustRunnables popup, some errors occurred. The following code caused the problem:

ret = string.format("cd '%s' && cargo ", dir)

The default SHELL of neovim on Windows is cmd.exe, and the single quotes are not valid for quoting path, you can test quickly by using the following commands in cmd window:

cd 'C:'

or:

cd 'C:\'

Both are invalid, there should be some extra checks to construct commands.

DAP debugging not working

This is most likely a user error but hoping you have some insight. I’m running Arch on an old T410 and when I just start a bare bones cargo project ‘cargo new —lib foo’. I’m not able to debug the initial unit test. Essentially nothing happens at all. Is there a way I can debug to get more info?

I have all the requirements met and you can see my configs here: https://github.com/wonbyte/.dotfiles/tree/main/.config/nvim

I’m also running ‘terminator’ as my terminal

How to execute hover actions

I can see the hover actions available on hover. However, I couldn't figure out how to execute them. Are there any default keybindings? What commands to run?

Standalone file support

I wonder if standalone file support 1 could be supported with this plugin or if that's the work of another plugin like lsp-config.

Example on how to use this with Spacevim and terminal

Hi, I am trying to set this up on my wsl2 with neovim.appimage and spacevim but I can't get any of the features apart from the got to definition .

After years of working with vim I'm still a noob, so any help would be very appreciated :)

Custom runnable options?

I'm here to ask is there a way to set custom runnable with options for those programs that need options to be given to them?

Or you can do that already and I'm just stupid for not knowing.

generate default code when converting #[derive(Debug)] to a manual implementation doesn't work

RA since release 2021-08-09 (https://rust-analyzer.github.io/thisweek/2021/08/09/changelog-89.html) generates default code when converting #[derive(Debug)] to manual impl. Since version 2021-08-16 (https://rust-analyzer.github.io/thisweek/2021/08/16/changelog-90.html) this functionality was extended to other derive macros (namely Default, Hash, Clone or PartialEq). This works fine in vscode but doesn't work in nvim with rust-tools.nvim. Codeaction 'Convert to manual impl std::fmt::Debug for ... generates only empty impl without fmt method itself.

Tested with latest RA installed via homebrew on macOS>

% rust-analyzer --version
rust-analyzer 996300f4a 2021-08-23 dev

How do I install this on Arch?

I tried to install this plugin for nvim 0.5, but it doesn't work. I was able to install the plugins and I installed the rust-analyzer, but where should I put the initial setup?

require('rust-tools').setup({}) clobbers on_attach

i have a custom on_attach function configured for rust-analyzer which does not fire when rust-tools is installed. i think this is a bad user experience, i want to be able to do things like set keybindings in buffers where a language server has started

Animated Cursor in README

Sorry for adding an issue for this, but i'm curious what you are using for the animated cursor in the README screen capture videos.

The folder 'images' have 54.46 MB

When I use vim-plug, it download that folder, which I think is unnecessary. Maybe you could host this images in some other site, like imgur?

Errors for MoveItem

I'm getting an error for the MoveItem commands:

Error executing vim.schedule lua callback: ...unwrapped-master/share/nvim/runtime/lua/vim/lsp/util.lua:461: attempt to index local 'text_document' (a nil value)

Neovim master from 3 days ago.

Shouldn't changes in Cargo.toml trigger the check?

Pretty much the title.

If I change the Cargo.toml file and add a dependency it is not rechecking to add this dependency into rust-analyzer's context and the lsp never sees these crates until I reload the whole project.

Is there a way to accomplish this?

LSP[rust_analyzer] rust-analyzer failed to load workspace: Failed to parse edition 2021

I installed rust-tools and added the default setup to my lua files. I commented out all other lspconfig related setups to avoid intereference.

I upgraded everything using rustup.

   stable-x86_64-apple-darwin unchanged - rustc 1.55.0 (c8dfcfe04 2021-09-06)
  nightly-x86_64-apple-darwin unchanged - rustc 1.57.0-nightly (05044c2e6 2021-09-26)

I ran cargo new playground && cd playground

I opened neovim.

I get the error:

LSP[rust_analyzer] rust-analyzer failed to load workspace:
Failed to read Cargo metadata from Cargo.toml file xxx/playground/Cargo.toml, cargo 1.57.0-nightly (0121d66aa 2021-09-22): 
Failed to parse edition 2021: invalid edition: "2021"

Why?

Improve debugging configuration (displaying local variables, etc)

Rust is known to be,... difficult with dap. rust-lldb apparently promises to aid the formatting and displaying of variables, although documentation on that is sparse.

For reference, currently values like strings or enums are diplayed like this:
image
which is obviously suboptimal.
Firstly, the string content is displayed,... badly.
secondly, the value of an enum variable is completely invisible.

Looking through several repos and projects where this has been discussed, it always sounds as though there was some solution that some people manage to get to work, although I've not yet found any concrete "this is what you need to do" solution that I could provide and propose here.

Rust-tools uses lldb-vscode for their debugging.
Looking at the rust langauge support section of the CodeLLDB repo, proper displaying of these values is promised. Surely enough, in VSCode, values do actually get shown correctly.

I'm not quite sure if this means that there is some magic that the VSCode plugin does on top of lldb-vscode to manipulate how the data is shown / sourced, or if this is achieved by some magical configuration that can be passed to lldb-vscode directly.
Given that setting this up for nvim-dap seems to be an unsolved problem currently, the rust-tools.nvim project might be the chance to figure out a reference solution for this, and then potentially upstream that to the nvim-dap repo itself.

This is not a concrete proposal, but just me throwing out some thoughts and hoping that someone more knowledgeable about the debug adapter situation will read this ^^' I played around with the mentioned "sourceLanguages": ["rust"] option, but that alone did not change anything for me at least.

Incorrect syntax in inlay_hints.lua

When I try to use this pluggin and run
"require('rust-tools').setup(opts)" as specficied in the readme file I get error:

inlay_hints.lua:102: '=' expected near 'continue'

I am using neovim 0.5.0 and lua version is 5.1

customise float window borders?

Hi there! This plugin is super cool, especially those inlay hints and hover action.
I have an issue though. I noticed that the border for the hover window is hardcoded, which isn't what I want.
I'd like to be able to change it. Here's what it currently has compared to how I want it to look.

  • Default
    image

  • Mine
    image

Thanks in advance!

How to change inlayhints color.

Actual

colorscheme is base16-gruvbox-dark-hard.
Should I just change comment color because color of inlayhints has the same color as comments.
2021-07-12_1920x1080

Expected

blue color hints

Environment

NVIM v0.5.0
Build type: Release
LuaJIT 2.0.5
os arhclinux

My config

-- rust-tools
local opts = {
  tools = { -- rust-tools options
    -- automatically set inlay hints (type hints)
    -- There is an issue due to which the hints are not applied on the first
    -- opened file. For now, write to the file to trigger a reapplication of
    -- the hints or just run :RustSetInlayHints.
    -- default: true
    autoSetHints = true,
    -- whether to show hover actions inside the hover window
    -- this overrides the default hover handler so something like lspsaga.nvim's hover would be overriden by this
    -- default: true
    hover_with_actions = true,
    -- These apply to the default RustRunnables command
    runnables = {
      -- whether to use telescope for selection menu or not
      -- default: true
      use_telescope = true
      -- rest of the opts are forwarded to telescope
    },
    -- These apply to the default RustSetInlayHints command
    inlay_hints = {
      -- wheter 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 lenght 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
    },
    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,
    },
  },
-- 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/CONFIG.md#rust_analyzer
  server = {
    on_attach = on_attach,
    capabilities = capabilities,
    flags = {
      allow_incremental_sync = true,
      debounce_text_changes = 500,
    },
    settings = {
      ["rust-analyzer"] = {
        assist = {
          importGranularity = "module",
          importEnforceGranularity = true,
        },
        cargo = {
          loadOutDirsFromCheck = true,
          allFeatures = true,
        },
        procMacro = {
          enable = true,
        },
        checkOnSave = {
          command = "clippy",
        },
        experimental = {
          procAttrMacros = true,
        },
        hoverActions = {
          references = true,
        },
        inlayHints = {
          chainingHints = true,
          maxLength = 40,
          parameterHints = true,
          typeHints = true,
        },
        lens = {
          methodReferences = true,
          references = true,
        },
      },
    },
  }, -- rust-analyer options
}
require('rust-tools').setup(opts)

run_command bug

run_command calls in handler and get_telescope_handler functions were not updated to reflect change from run_command to M.run_command in runnables.lua

#34

Warning when using hover action: fancy_floating_markdown is deprecated

Description

When I try to view the documentation for a symbol I get the following error in :messages:

fancy_floating_markdown is deprecated. Please use open_floating_preview and pass focus_id = [unique_name] instead

Here's an example of what I'm seeing:

(Appologies for the colorscheme and slowness. Default nvim 🤷)

Steps to reproduce:

Using this config:

init.vim
set completeopt=menuone,noselect
set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')

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

call plug#end()

autocmd VimEnter * PlugClean! | PlugUpdate --sync | close

lua << EOF

require('rust-tools').setup { }

EOF

nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
  1. Create a test rust repo: cargo new my_repo
  2. Open nvim nvim -nu test.vim my_repo/src/main.rs
  3. Navigate to the println! symbol
  4. Type K to bring up the documentation popup

Expected:

Shows the window, with no warning messages

Actual

Shows the warning message

Additional Details

Nvim version: v0.5.0-dev+1362-g3cd688ff7
Plugin commit hash: 6f92ba636c06069592c64f85888b452da7e81cfd
OS: Mac OS

Docs: Show how this plugin can be used with other LSPs

I want to set up not only rust support in nvim but also other LSPs for bash, go, clangd, etc.

Considering that this plugin will interact with lsp-config: How do I configure those LSP servers without breaking the rust support?

Some documentation on how to configure such a setup would be appreciated.

Passing "on_attach" does not work as expected

I have configured other language servers to automatically attach to buffers using a line like so:

require'lspconfig'.pylsp.setup({ on_attach=on_attach })

However, using a similar configuration for rust-tools does not result in the language server automatically attaching to Rust buffers. Here is the relevant configuration:

local on_attach = function(client)
  require'completion'.on_attach(client)
end

require('rust-tools').setup({
  server = { on_attach = on_attach }
})

Workspace project starting multiple LSP servers

I have a project with the following structure:

root
|_ Cargo.toml
|_ src
|____ source code...
|_ Sub-Project
|____ Cargo.toml
|____ src
|_______ source code...

Whenever I open a file from the sub project, it is starting a new lsp server and even pointing the root directory to the wrong folder:

image

Is there a way to fix this?

I'm also seeing a lot of this warnings in the logs:

[ WARN ] 2021-09-16T11:28:58+0200 ] ...l/Cellar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp.lua:87 ]	"method rust-analyzer/inlayHints is not supported by any of the servers registered for the current buffer"

Is this normal?

Options to customize inlay hints

The prefix seems to be hard coded to =>. I normally prefer no prefix, would it be possible to make this configurable?

Also, is there a way to disable inlay hints by default? I thought autoSetHints = false would do this but it still seems to be added on save

Support for LSP Diagonostics

Does rust-tools have support for Lsp diagnostic? When I have an error I am receiving inline hints about the error. But if I wanted to view the error in a hover I need to call.

vim.lsp.diagnostic.show_line_diagnostics()

I wonder if there a way to integrate this with the hover system from rust-tools?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.