From b6785e29d22e0ba5146dc851c8fa0cd9ddea4560 Mon Sep 17 00:00:00 2001 From: yavko Date: Mon, 3 Oct 2022 17:11:10 -0700 Subject: [PATCH 1/3] Initial Rust IDE --- config.lua | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 config.lua diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..4ee62b8 --- /dev/null +++ b/config.lua @@ -0,0 +1,103 @@ +lvim.log.level = "warn" +lvim.format_on_save = true +lvim.colorscheme = "tokyonight" + +-- to disable icons and use a minimalist setup, uncomment the following +-- lvim.use_icons = false + +-- keymappings [view all the defaults by pressing Lk] +lvim.leader = "space" + +-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile +lvim.builtin.alpha.active = true +lvim.builtin.alpha.mode = "dashboard" +lvim.builtin.notify.active = true +lvim.builtin.terminal.active = true +lvim.builtin.nvimtree.setup.view.side = "left" +lvim.builtin.nvimtree.setup.renderer.icons.show.git = false +lvim.builtin.breadcrumbs.active = true +lvim.builtin.treesitter.highlight.enabled = true +lvim.builtin.dap.active = true +-- lvim.builtin.terminal.shell = "pwsh.exe -NoLogo" + +-- if you don't want all the parsers change this to a table of the ones you want +lvim.builtin.treesitter.ensure_installed = { + "rust", + "toml" +} +lvim.builtin.treesitter.highlight.enable = true + +-- set a formatter, this will override the language server formatting capabilities (if it exists) +local formatters = require "lvim.lsp.null-ls.formatters" +formatters.setup { + { command = "rustfmt", filetypes = { "rust" } }, +} + +local lsp_manager = require "lvim.lsp.manager" +lsp_manager.setup("rust_analyzer") + + +lvim.plugins = { + { + "simrat39/rust-tools.nvim", + -- ft = { "rust", "rs" }, -- IMPORTANT: re-enabling this seems to break inlay-hints + config = function() + require("rust-tools").setup { + tools = { + executor = require("rust-tools/executors").termopen, -- can be quickfix or termopen + reload_workspace_from_cargo_toml = true, + inlay_hints = { + auto = true, + only_current_line = false, + show_parameter_hints = true, + 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 = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, + }, + auto_focus = true, + }, + }, + server = { + on_init = require("lvim.lsp").common_on_init, + on_attach = function(client, bufnr) + require("lvim.lsp").common_on_attach(client, bufnr) + local rt = require "rust-tools" + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "lA", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, + } + end, + }, + { + "saecki/crates.nvim", + tag = "v0.3.0", + requires = { "nvim-lua/plenary.nvim" }, + config = function() + require("crates").setup() + end, + }, + { + "j-hui/fidget.nvim", + config = function() + require("fidget").setup() + end + } +} From 22cb4f599aead6e8da0011fee0296ccdbfcd58f7 Mon Sep 17 00:00:00 2001 From: yavko Date: Mon, 3 Oct 2022 17:20:33 -0700 Subject: [PATCH 2/3] Edit readme --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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) From e5a46a49844ac09d00db13b383990554d3ef8be9 Mon Sep 17 00:00:00 2001 From: yavko Date: Fri, 7 Oct 2022 20:41:10 -0700 Subject: [PATCH 3/3] Add everyones changes --- config.lua | 191 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 116 insertions(+), 75 deletions(-) diff --git a/config.lua b/config.lua index 4ee62b8..c81c83a 100644 --- a/config.lua +++ b/config.lua @@ -1,103 +1,144 @@ -lvim.log.level = "warn" -lvim.format_on_save = true -lvim.colorscheme = "tokyonight" - --- to disable icons and use a minimalist setup, uncomment the following --- lvim.use_icons = false - --- keymappings [view all the defaults by pressing Lk] -lvim.leader = "space" - --- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile -lvim.builtin.alpha.active = true -lvim.builtin.alpha.mode = "dashboard" -lvim.builtin.notify.active = true -lvim.builtin.terminal.active = true -lvim.builtin.nvimtree.setup.view.side = "left" -lvim.builtin.nvimtree.setup.renderer.icons.show.git = false -lvim.builtin.breadcrumbs.active = true -lvim.builtin.treesitter.highlight.enabled = true -lvim.builtin.dap.active = true --- lvim.builtin.terminal.shell = "pwsh.exe -NoLogo" - -- 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" + "toml", } + +lvim.builtin.dap.active = true lvim.builtin.treesitter.highlight.enable = true --- set a formatter, this will override the language server formatting capabilities (if it exists) +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" }) + local formatters = require "lvim.lsp.null-ls.formatters" formatters.setup { - { command = "rustfmt", filetypes = { "rust" } }, + { command = "stylua", filetypes = { "lua" } }, } -local lsp_manager = require "lvim.lsp.manager" -lsp_manager.setup("rust_analyzer") +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, -lvim.plugins = { - { - "simrat39/rust-tools.nvim", - -- ft = { "rust", "rs" }, -- IMPORTANT: re-enabling this seems to break inlay-hints - config = function() - require("rust-tools").setup { - tools = { - executor = require("rust-tools/executors").termopen, -- can be quickfix or termopen - reload_workspace_from_cargo_toml = true, - inlay_hints = { - auto = true, - only_current_line = false, - show_parameter_hints = true, - parameter_hints_prefix = "<-", - other_hints_prefix = "=>", - max_len_align = false, - max_len_align_padding = 1, - right_align = false, - right_align_padding = 7, - highlight = "Comment", + capabilities = require("lvim.lsp").common_capabilities(), + settings = { + ["rust-analyzer"] = { + lens = { + enable = true, }, - hover_actions = { - border = { - { "╭", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╮", "FloatBorder" }, - { "│", "FloatBorder" }, - { "╯", "FloatBorder" }, - { "─", "FloatBorder" }, - { "╰", "FloatBorder" }, - { "│", "FloatBorder" }, - }, - auto_focus = true, + checkOnSave = { + enable = true, + command = "clippy", }, }, - server = { - on_init = require("lvim.lsp").common_on_init, - on_attach = function(client, bufnr) - require("lvim.lsp").common_on_attach(client, bufnr) - local rt = require "rust-tools" - -- Hover actions - vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) - -- Code action groups - vim.keymap.set("n", "lA", rt.code_action_group.code_action_group, { buffer = bufnr }) - end, - }, - } - end, + }, + }, + } +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() + require("crates").setup { + null_ls = { + enabled = true, + name = "crates.nvim", + }, + } end, }, { "j-hui/fidget.nvim", config = function() require("fidget").setup() - end - } + end, + }, }