diff --git a/README.md b/README.md index 058ece0..e563137 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..c81c83a --- /dev/null +++ b/config.lua @@ -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", "", "RustOpenExternalDocs", { noremap = true, silent = true }) + +lvim.builtin.which_key.mappings["L"] = { + name = "Rust", + r = { "RustRunnables", "Runnables" }, + t = { "lua _CARGO_TEST()", "Cargo Test" }, + m = { "RustExpandMacro", "Expand Macro" }, + c = { "RustOpenCargo", "Open Cargo" }, + p = { "RustParentModule", "Parent Module" }, + d = { "RustDebuggables", "Debuggables" }, + v = { "RustViewCrateGraph", "View Crate Graph" }, + R = { + "lua require('rust-tools/workspace_refresh')._reload_workspace_from_cargo_toml()", + "Reload Workspace", + }, + o = { "RustOpenExternalDocs", "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, + }, +}