diff --git a/lvim/config.lua b/lvim/config.lua index 2caed10..a386a61 100644 --- a/lvim/config.lua +++ b/lvim/config.lua @@ -1,14 +1,10 @@ ---[[ -lvim is the global options object - -Linters should be -filled in as strings with either -a global executable or a path to -an executable -]] --- THESE ARE EXAMPLE CONFIGS FEEL FREE TO CHANGE TO WHATEVER YOU WANT - --- general +-- Read the docs: https://www.lunarvim.org/docs/configuration +-- Example configs: https://github.com/LunarVim/starter.lvim +-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6 +-- Forum: https://www.reddit.com/r/lunarvim/ +-- Discord: https://discord.com/invite/Xb9B4Ny +-- +-- General lvim.log.level = "warn" lvim.format_on_save = false lvim.colorscheme = "onedark" @@ -20,13 +16,14 @@ vim.api.nvim_create_autocmd("FileType", { pattern = "cpp", command = "setlocal shiftwidth=2 tabstop=2" }) --- keymappings [view all the defaults by pressing Lk] -lvim.leader = "space" --- add your own keymapping -lvim.keys.normal_mode[""] = ":w" -lvim.builtin.terminal.open_mapping = "" +lvim.builtin.treesitter.ensure_installed = { + "lua", + "rust", + "toml", +} +lvim.builtin.nvimtree.setup.renderer.icons.show.git = false --- Use which-key to add extra bindings with the leader-key prefix +-- Keybind lvim.builtin.which_key.mappings["g"].g = { "ToggleTermTermExec cmd='gitui&&exit'", "Gitui" } lvim.builtin.which_key.mappings["s"].B = { "Telescope git_branches", "Checkout branch" } lvim.builtin.which_key.mappings["s"].b = { "Telescope buffers", "Buffer" } @@ -37,45 +34,36 @@ lvim.builtin.which_key.mappings["t"] = { t = { "ToggleTerm size=15 direction=horizontal", "Split horizontal" }, } --- lvim.builtin.which_key.mappings["t"] = { --- name = "+Trouble", --- r = { "Trouble lsp_references", "References" }, --- f = { "Trouble lsp_definitions", "Definitions" }, --- d = { "Trouble document_diagnostics", "Diagnostics" }, --- q = { "Trouble quickfix", "QuickFix" }, --- l = { "Trouble loclist", "LocationList" }, --- w = { "Trouble workspace_diagnostics", "Workspace Diagnostics" }, --- } - -lvim.builtin.alpha.active = true -lvim.builtin.alpha.mode = "dashboard" -lvim.builtin.terminal.active = true -lvim.builtin.nvimtree.setup.view.side = "left" -lvim.builtin.nvimtree.setup.renderer.icons.show.git = false - --- if you don't want all the parsers change this to a table of the ones you want -lvim.builtin.treesitter.ensure_installed = { - "bash", - "json", - "lua", - "python", - "typescript", - "rust", - "java", - "toml", -} - -lvim.builtin.treesitter.highlight.enabled = true - - --- Additional Plugins +-- Plugins lvim.plugins = { + --RUST + "simrat39/rust-tools.nvim", + { + "saecki/crates.nvim", + version = "v0.3.0", + dependencies = { "nvim-lua/plenary.nvim" }, + config = function() + require("crates").setup { + null_ls = { + enabled = true, + name = "crates.nvim", + }, + popup = { + border = "rounded", + }, + } + end, + }, + { "slint-ui/vim-slint" }, + -- General + { + "j-hui/fidget.nvim", + config = function() + require("fidget").setup() + end, + }, { "navarasu/onedark.nvim" }, { "folke/tokyonight.nvim" }, - { - "folke/trouble.nvim", - cmd = "TroubleToggle", - }, { "Pocco81/auto-save.nvim", config = function() @@ -89,86 +77,23 @@ lvim.plugins = { "iamcco/markdown-preview.nvim", build = function() vim.fn["mkdp#util#install"]() end, }, - -- :Rust - { - 'saecki/crates.nvim', - -- ft = {"toml"}, - config = function(_, opts) - local crates = require('crates') - crates.setup({ - null_ls = { - enabled = true, - name = "crates.nvim", - }, - }) - require('cmp').setup.buffer({ - sources = { { name = "crates" } } - }) - crates.show() - end, - }, - { - "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 = { - settings = { - ["rust-analyzer"] = { - checkOnSave = { - command = "clippy", - } - } - }, - 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, - }, - { "slint-ui/vim-slint" }, - -- Java - { 'hdiniz/vim-gradle' }, - { "mfussenegger/nvim-jdtls", }, - -- Deno - { 'sigmasd/deno-nvim' } } + +-- Themes +require('onedark').setup { + style = 'darker', -- Default theme style. Choose between 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer' and 'light' + toggle_style_key = "ss", + transparent = false, -- Show/hide background + + code_style = { + comments = 'italic', + keywords = 'italic,', + functions = 'bold', + strings = 'none', + variables = 'none' + }, +} + -- folding vim.o.foldcolumn = '2' -- '0' is not bad vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value @@ -213,66 +138,118 @@ for _, ls in ipairs(language_servers) do }) end require('ufo').setup() +-- RUST CONFIG +vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "rust_analyzer" }) --- Java -vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "jdtls" }) -local lspconfig = require('lspconfig') -local lombok = vim.fn.stdpath('data') .. '/mason/packages/jdtls/lombok.jar' -lspconfig.jdtls.setup { cmd = { "jdtls", "--jvm-arg=-javaagent:" .. lombok } } +local mason_path = vim.fn.glob(vim.fn.stdpath "data" .. "/mason/") --- Deno -local nvim_lsp = require("lspconfig") -nvim_lsp.denols.setup { - on_attach = on_attach, - root_dir = nvim_lsp.util.root_pattern("deno.jsonc", "deno.json"), - init_options = { - lint = true, - }, -} -nvim_lsp.tsserver.setup { - on_attach = on_attach, - root_dir = nvim_lsp.util.root_pattern("package.json"), - single_file_support = false -} +local codelldb_path = mason_path .. "bin/codelldb" +local liblldb_path = mason_path .. "packages/codelldb/extension/lldb/lib/liblldb" +local this_os = vim.loop.os_uname().sysname -require("deno-nvim").setup({ - server = { - on_attach = ..., - capabilites = ... - }, - -- if you're using dap to debug (see the README for more info) - dap = { - adapter = ... +-- The path in windows is different +if this_os:find "Windows" then + codelldb_path = mason_path .. "packages\\codelldb\\extension\\adapter\\codelldb.exe" + liblldb_path = mason_path .. "packages\\codelldb\\extension\\lldb\\bin\\liblldb.dll" +else + -- The liblldb extension is .so for linux and .dylib for macOS + liblldb_path = liblldb_path .. (this_os == "Linux" and ".so" or ".dylib") +end + +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, + adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path), + }, + 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) --- Themes -require('onedark').setup { - style = 'darker', -- Default theme style. Choose between 'dark', 'darker', 'cool', 'deep', 'warm', 'warmer' and 'light' - toggle_style_key = "ss", - transparent = false, -- Show/hide background +lvim.builtin.dap.on_config_done = function(dap) + dap.adapters.codelldb = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path) + 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 - code_style = { - comments = 'italic', - keywords = 'italic,', - functions = 'bold', - strings = 'none', - variables = 'none' +vim.api.nvim_set_keymap("n", "", "RustOpenExternalDocs", { noremap = true, silent = true }) + +lvim.builtin.which_key.mappings["C"] = { + 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" }, + y = { "lua require'crates'.open_repository()", "[crates] open repository" }, + P = { "lua require'crates'.show_popup()", "[crates] show popup" }, + i = { "lua require'crates'.show_crate_popup()", "[crates] show info" }, + f = { "lua require'crates'.show_features_popup()", "[crates] show features" }, + D = { "lua require'crates'.show_dependencies_popup()", "[crates] show dependencies" }, } --- - - --- Autocommands (https://neovim.io/doc/user/autocmd.html) --- vim.api.nvim_create_autocmd("BufEnter", { --- pattern = { "*.json", "*.jsonc" }, --- -- enable wrap mode for json files only --- command = "setlocal wrap", --- }) --- vim.api.nvim_create_autocmd("FileType", { --- pattern = "zsh", --- callback = function() --- -- let treesitter use bash highlight for zsh files as well --- require("nvim-treesitter.highlight").attach(0, "bash") --- end, --- })