rust-tools.nvim icon indicating copy to clipboard operation
rust-tools.nvim copied to clipboard

Is it possible to load rust-tools with lazyvim?

Open tubzby opened this issue 2 years ago • 16 comments

I added a few lines in my init.lua . it doesn't work without any error messages:

{
	"simrat39/rust-tools.nvim",
	config = function()
		require('rust-tools').setup({})
	end
}

But if I paste the all the lines in the configuration sections of Readme, it will display some error message:

return {
	"simrat39/rust-tools.nvim",
	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" },
				},
				-- 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",
			},
		},
	},
}

Error detected while processing /Users/liuzhiping/.config/nvim/init.lua:
Failed to load `custom.plugins.rust-tools`
...xxxx/.config/nvim/lua/custom/plugins/rust-tools.lua:9: module 'rust-tools.executors' not found:
^Ino field package.preload['rust-tools.executors']
cache_loader: module rust-tools.executors not found
cache_loader_lib: module rust-tools.executors not found

tubzby avatar Mar 19 '23 03:03 tubzby

try

opts = function() 
    return {
        tools = {...}
    }
end

or

config = function() {
    require('rust-tools').setup({tools  = {...}})
}

songww avatar Mar 20 '23 08:03 songww

Thanks @songww , now I can see rust-tools is loaded in lazyvim.

But I when opened a RUST project, there's no inlay hints and the RustEnableInlayHints command shows "Not an editor command".

tubzby avatar Mar 20 '23 13:03 tubzby

I have no idea, It works fine for me.

songww avatar Mar 20 '23 15:03 songww

Thanks @songww , now I can see rust-tools is loaded in lazyvim.

But I when opened a RUST project, there's no inlay hints and the RustEnableInlayHints command shows "Not an editor command".

Another option: https://github.com/lvimuser/lsp-inlayhints.nvim#rust

polyzen avatar Mar 20 '23 19:03 polyzen

@polyzen thanks. Can anyone point a way out to debug or check the logs?

BTW, I'm using kickstart with some other plugins.

tubzby avatar Mar 21 '23 08:03 tubzby

Thanks @songww , now I can see rust-tools is loaded in lazyvim. But I when opened a RUST project, there's no inlay hints and the RustEnableInlayHints command shows "Not an editor command".

Another option: https://github.com/lvimuser/lsp-inlayhints.nvim#rust

lsp-inlayhints.nvim works for me!

tubzby avatar Mar 21 '23 13:03 tubzby

In case anybody else comes to this, I find out that rust-tools is in conflict with mason|mason_lsp rust-analyzer.

tubzby avatar Mar 24 '23 12:03 tubzby

In case anybody else comes to this, I find out that rust-tools is in conflict with mason|mason_lsp rust-analyzer.

It works fine for me.

songww avatar Mar 24 '23 13:03 songww

@tubzby FYI:

return {
  {
    "simrat39/rust-tools.nvim",
    dependencies = { "neovim/nvim-lspconfig", "nvim-lua/plenary.nvim", "mfussenegger/nvim-dap" },
    opts = function()
      local extension_path = vim.env.HOME .. "/.local/share/nvim/mason/packages/codelldb/extension/"
      local codelldb_path = extension_path .. "adapter/codelldb"
      local liblldb_path = extension_path .. "lldb/lib/liblldb.dylib"
      return {
        dap = { adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path) },
      }
    end,
  },
}

image

54corbin avatar Mar 24 '23 14:03 54corbin

@54corbin Thanks!

Tried your configuration with mason codelldb, seems codelldb is dependent on "bash-debug-adapter" and "bash-debug-adapter" failed while installing:

"bash-debug-adapter" was successfully installed.
...son-nvim-dap.nvim/lua/mason-nvim-dap/automatic_setup.lua:8: loop or previous error loading module 'mason-nvim-dap.mappings.configurations'
Press ENTER or type command to continue

tubzby avatar Mar 25 '23 03:03 tubzby

I added the following to a new file called rust-tools.lua in the plugins folder and it makes inlay hints work out of the box. I have rust-analyzer already installed in my system.

return {
  {
    "simrat39/rust-tools.nvim",
    opts = function(_, _)
      require("rust-tools").setup({})
    end,
  },
}

And don't forget to install the dependency after you add it to the config. I did at first. 🙃

Joxtacy avatar Mar 31 '23 18:03 Joxtacy

Thanks, tried everything. Only works if I remove rust-analyzer from mason and download a rust-analyzer to PATH.

I have pushed my vim config to https://github.com/tubzby/conf.nvim in case anyone else can do an in-depth digging.

tubzby avatar Apr 01 '23 01:04 tubzby

For those using AstroNvim (which now uses lazy), there is a specific recipe that works: https://astronvim.com/Recipes/advanced_lsp#rust-rust-toolsnvim

electricjones avatar Apr 01 '23 19:04 electricjones

Finally, it works out by adding these lines to mason_lspconfig setup_handlers:

mason_lspconfig.setup_handlers {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
    }
  end,
  ["rust_analyzer"] = function()
    require("rust-tools").setup {}
  end
}

tubzby avatar Apr 02 '23 00:04 tubzby

return { "simrat39/rust-tools.nvim", ft = "rust", opts = { ....

duanyuluo avatar May 04 '23 05:05 duanyuluo

return { "simrat39/rust-tools.nvim", ft = "rust", opts = { ....

load rust-tools.nvim when you load a .rs file

duanyuluo avatar May 04 '23 05:05 duanyuluo