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

Rust IDE #16

Merged
merged 3 commits into from
Oct 8, 2022
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
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# starter.lvim

A great starting point for your LunarVim journey!
A great starting point for your LunarVim Rust journey!

## Submission Guidelines

- Ideally one file!
- IDE config must be added to its own branch named `lang-ide`
- try to keep it focused on the language and not your biased keybindings/options
![screenshot](https://user-images.githubusercontent.com/15178513/193708078-ba8ca1d2-8e30-405d-8b54-e4c2717071a0.png)
144 changes: 144 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
-- if you don't want all the parsers change this to a table of the ones you want
lvim.builtin.treesitter.ensure_installed = {
"lua",
"rust",
"toml",
}

lvim.builtin.dap.active = true
lvim.builtin.treesitter.highlight.enable = true

vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" })

local formatters = require "lvim.lsp.null-ls.formatters"
formatters.setup {
{ command = "stylua", filetypes = { "lua" } },
}

local mason_path = vim.fn.glob(vim.fn.stdpath "data" .. "/mason/")
local codelldb_adapter = {
type = "server",
port = "${port}",
executable = {
command = mason_path .. "bin/codelldb",
args = { "--port", "${port}" },
-- On windows you may have to uncomment this:
-- detached = false,
},
}

pcall(function()
require("rust-tools").setup {
tools = {
executor = require("rust-tools/executors").termopen, -- can be quickfix or termopen
reload_workspace_from_cargo_toml = true,
runnables = {
use_telescope = true,
},
inlay_hints = {
auto = true,
only_current_line = false,
show_parameter_hints = false,
parameter_hints_prefix = "<-",
other_hints_prefix = "=>",
max_len_align = false,
max_len_align_padding = 1,
right_align = false,
right_align_padding = 7,
highlight = "Comment",
},
hover_actions = {
border = "rounded",
},
on_initialized = function()
vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter", "CursorHold", "InsertLeave" }, {
pattern = { "*.rs" },
callback = function()
local _, _ = pcall(vim.lsp.codelens.refresh)
end,
})
end,
},
dap = {
adapter = codelldb_adapter,
},
server = {
on_attach = function(client, bufnr)
require("lvim.lsp").common_on_attach(client, bufnr)
local rt = require "rust-tools"
vim.keymap.set("n", "K", rt.hover_actions.hover_actions, { buffer = bufnr })
end,

capabilities = require("lvim.lsp").common_capabilities(),
settings = {
["rust-analyzer"] = {
lens = {
enable = true,
},
checkOnSave = {
enable = true,
command = "clippy",
},
},
},
},
}
end)

-- CHANGED --
lvim.builtin.dap.on_config_done = function(dap)
dap.adapters.codelldb = codelldb_adapter
dap.configurations.rust = {
{
name = "Launch file",
type = "codelldb",
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
},
}
end

vim.api.nvim_set_keymap("n", "<m-d>", "<cmd>RustOpenExternalDocs<Cr>", { noremap = true, silent = true })

lvim.builtin.which_key.mappings["L"] = {
name = "Rust",
r = { "<cmd>RustRunnables<Cr>", "Runnables" },
t = { "<cmd>lua _CARGO_TEST()<cr>", "Cargo Test" },
m = { "<cmd>RustExpandMacro<Cr>", "Expand Macro" },
c = { "<cmd>RustOpenCargo<Cr>", "Open Cargo" },
p = { "<cmd>RustParentModule<Cr>", "Parent Module" },
d = { "<cmd>RustDebuggables<Cr>", "Debuggables" },
v = { "<cmd>RustViewCrateGraph<Cr>", "View Crate Graph" },
R = {
"<cmd>lua require('rust-tools/workspace_refresh')._reload_workspace_from_cargo_toml()<Cr>",
"Reload Workspace",
},
o = { "<cmd>RustOpenExternalDocs<Cr>", "Open External Docs" },
}

lvim.plugins = {
"simrat39/rust-tools.nvim",
{
"saecki/crates.nvim",
tag = "v0.3.0",
requires = { "nvim-lua/plenary.nvim" },
config = function()
require("crates").setup {
null_ls = {
enabled = true,
name = "crates.nvim",
},
}
end,
},
{
"j-hui/fidget.nvim",
config = function()
require("fidget").setup()
end,
},
}