From 057b357f0533cf92d2fb502cad1cd6941b925325 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 3 Feb 2023 16:08:09 +0100 Subject: [PATCH] update nvim --- lazy.lua | 9 +++++++ lsp/config/denols.lua | 6 +++++ lsp/config/eslint.lua | 6 +++++ lsp/config/jdtls.lua | 53 +++++++++++++++++++++++++++++++++++++ lsp/config/tsserver.lua | 6 +++++ lsp/setup_handlers.lua | 17 ++++++++++++ mappings.lua | 3 +++ plugins/crates-nvim.lua | 4 +++ plugins/mason-lspconfig.lua | 4 +-- plugins/mason-null-ls.lua | 33 ++++++++++++++++++++++- plugins/mason-nvim-dap.lua | 31 ++++++++++++++++++++++ plugins/nvim-cmp.lua | 24 +++++++++++++++++ plugins/nvim-jdtls.lua | 3 +++ plugins/nvim-metals.lua | 4 +++ plugins/octo.lua | 1 + plugins/ranger-nvim.lua | 1 + plugins/rust-tools.lua | 3 +++ plugins/which-key.lua | 13 +++++++++ which-key/register.lua | 13 --------- 19 files changed, 218 insertions(+), 16 deletions(-) create mode 100644 lazy.lua create mode 100644 lsp/config/denols.lua create mode 100644 lsp/config/eslint.lua create mode 100644 lsp/config/jdtls.lua create mode 100644 lsp/config/tsserver.lua create mode 100644 lsp/setup_handlers.lua create mode 100644 plugins/crates-nvim.lua create mode 100644 plugins/mason-nvim-dap.lua create mode 100644 plugins/nvim-cmp.lua create mode 100644 plugins/nvim-jdtls.lua create mode 100644 plugins/nvim-metals.lua create mode 100644 plugins/rust-tools.lua create mode 100644 plugins/which-key.lua delete mode 100644 which-key/register.lua diff --git a/lazy.lua b/lazy.lua new file mode 100644 index 0000000..1db01f1 --- /dev/null +++ b/lazy.lua @@ -0,0 +1,9 @@ +return { + defaults = { lazy = true }, + performance = { + rtp = { + -- customize default disabled vim plugins + disabled_plugins = { "tohtml", "gzip", "matchit", "zipPlugin", "netrwPlugin", "tarPlugin", "matchparen" }, + }, + }, +} diff --git a/lsp/config/denols.lua b/lsp/config/denols.lua new file mode 100644 index 0000000..e1d25fc --- /dev/null +++ b/lsp/config/denols.lua @@ -0,0 +1,6 @@ +return { + denols = function(opts) + opts.root_dir = require("lspconfig.util").root_pattern("deno.json", "deno.jsonc") + return opts + end, +} diff --git a/lsp/config/eslint.lua b/lsp/config/eslint.lua new file mode 100644 index 0000000..da3ad71 --- /dev/null +++ b/lsp/config/eslint.lua @@ -0,0 +1,6 @@ +return { + eslint = function(opts) + opts.root_dir = require("lspconfig.util").root_pattern("package.json", ".eslintrc.json", ".eslintrc.js") + return opts + end, +} diff --git a/lsp/config/jdtls.lua b/lsp/config/jdtls.lua new file mode 100644 index 0000000..9c46b81 --- /dev/null +++ b/lsp/config/jdtls.lua @@ -0,0 +1,53 @@ +return { + jdtls = function(opts) + -- use this function notation to build some variables + local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } + local root_dir = require("jdtls.setup").find_root(root_markers) + + -- calculate workspace dir + local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") + local workspace_dir = vim.fn.stdpath "data" .. "/site/java/workspace-root/" .. project_name + os.execute("mkdir " .. workspace_dir) + + -- get the mason install path + local install_path = require("mason-registry").get_package("jdtls"):get_install_path() + + -- get the current OS + local os + print(os) + if vim.fn.has "macunix" then + os = "mac" + elseif vim.fn.has "win32" then + os = "win" + else + os = "linux" + end + + -- return the server config + return { + cmd = { + "java", + "-Declipse.application=org.eclipse.jdt.ls.core.id1", + "-Dosgi.bundles.defaultStartLevel=4", + "-Declipse.product=org.eclipse.jdt.ls.core.product", + "-Dlog.protocol=true", + "-Dlog.level=ALL", + "-javaagent:" .. install_path .. "/lombok.jar", + "-Xms1g", + "--add-modules=ALL-SYSTEM", + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + "-jar", + vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"), + "-configuration", + install_path .. "/config_" .. os, + "-data", + workspace_dir, + }, + + root_dir = root_dir, + } + end, +} diff --git a/lsp/config/tsserver.lua b/lsp/config/tsserver.lua new file mode 100644 index 0000000..82aaf0a --- /dev/null +++ b/lsp/config/tsserver.lua @@ -0,0 +1,6 @@ +return { + tsserver = function(opts) + opts.root_dir = require("lspconfig.util").root_pattern "package.json" + return opts + end, +} diff --git a/lsp/setup_handlers.lua b/lsp/setup_handlers.lua new file mode 100644 index 0000000..5a1f712 --- /dev/null +++ b/lsp/setup_handlers.lua @@ -0,0 +1,17 @@ +return { + -- keys for a specific server name will be used for that LSP + --jdtls = function(server, opts) + -- -- custom sumneko_lua setup handler + -- require("lspconfig")["sumneko_lua"].setup(opts) + --end, + rust_analyzer = function(_, opts) require("rust-tools").setup { server = opts } end, + + jdtls = function(_, opts) + vim.api.nvim_create_autocmd("Filetype", { + pattern = "java", -- autocmd to start jdtls + callback = function() + if opts.root_dir and opts.root_dir ~= "" then require("jdtls").start_or_attach(opts) end + end, + }) + end, +} diff --git a/mappings.lua b/mappings.lua index 9228d93..a6ba42d 100644 --- a/mappings.lua +++ b/mappings.lua @@ -9,6 +9,9 @@ return { ["bt"] = { "BufferLineSortByTabs", desc = "Sort by tabs" }, -- quick save -- [""] = { ":w!", desc = "Save File" }, -- change description but the same command + ["b"] = { name = "Buffer" }, + ["P"] = { "Telescope projects", desc = "projects" }, + ["."] = { "Ranger", desc = "ranger" }, }, t = { -- setting a mapping to false will disable it diff --git a/plugins/crates-nvim.lua b/plugins/crates-nvim.lua new file mode 100644 index 0000000..c781977 --- /dev/null +++ b/plugins/crates-nvim.lua @@ -0,0 +1,4 @@ +return { + "Saecki/crates.nvim", + config = function() require("crates").setup() end, +} diff --git a/plugins/mason-lspconfig.lua b/plugins/mason-lspconfig.lua index f5ac5cc..c7259c7 100644 --- a/plugins/mason-lspconfig.lua +++ b/plugins/mason-lspconfig.lua @@ -1,7 +1,7 @@ return { "williamboman/mason-lspconfig.nvim", opts = { - ensure_installed = { "sumneko_lua", "rust_analyzer", "gopls", "yamlls", "tsserver", "terraformls" }, - automatic_installation = true, + ensure_installed = { "sumneko_lua", "gopls", "yamlls", "tsserver", "terraformls", "jsonls", "jdtls" }, + automatic_installation = { exclude = { "rust_analyzer" } }, }, } diff --git a/plugins/mason-null-ls.lua b/plugins/mason-null-ls.lua index c5434d8..4397817 100644 --- a/plugins/mason-null-ls.lua +++ b/plugins/mason-null-ls.lua @@ -1,4 +1,35 @@ return { -- overrides `require("mason-null-ls").setup(...)` "jay-babu/mason-null-ls.nvim", - opts = { ensure_installed = { "prettier", "stylua" } }, + config = function(plugin, opts) + plugin.default_config(opts) -- use the default configuration function + local null_ls = require "null-ls" + require("mason-null-ls").setup_handlers { -- setup custom handlers + prettier = function() + require("null-ls").register(null_ls.builtins.formatting.prettier.with { + condition = function(utils) + return utils.root_has_file "package.json" + or utils.root_has_file ".prettierrc" + or utils.root_has_file ".prettierrc.json" + or utils.root_has_file ".prettierrc.js" + end, + }) + end, + -- For prettierd: + -- prettierd = function() + -- require("null-ls").register(require("null-ls").builtins.formatting.prettierd.with({ + -- condition = function(utils) + -- return utils.root_has_file("package.json") or utils.root_has_file(".prettierrc") or utils.root_has_file(".prettierrc.json") or utils.root_has_file(".prettierrc.js") + -- end + -- })) + -- end, + -- For eslint_d: + -- eslint_d = function() + -- require("null-ls").register(require("null-ls").builtins.diagnostics.eslint_d.with({ + -- condition = function(utils) + -- return utils.root_has_file("package.json") or utils.root_has_file(".eslintrc.json") or utils.root_has_file(".eslintrc.js") + -- end + -- })) + -- end, + } + end, } diff --git a/plugins/mason-nvim-dap.lua b/plugins/mason-nvim-dap.lua new file mode 100644 index 0000000..9ec4594 --- /dev/null +++ b/plugins/mason-nvim-dap.lua @@ -0,0 +1,31 @@ +return { + "jay-babu/mason-nvim-dap.nvim", + config = function(self, opts) + self.default_config(opts) -- run default AstroNvim mason-nvim-dap config function + + -- do more configuration as needed + local mason_nvim_dap = require "mason-nvim-dap" + mason_nvim_dap.setup_handlers { + python = function(source_name) + local dap = require "dap" + dap.adapters.python = { + type = "executable", + command = "/usr/bin/python3", + args = { + "-m", + "debugpy.adapter", + }, + } + + dap.configurations.python = { + { + type = "python", + request = "launch", + name = "Launch file", + program = "${file}", -- This configuration will launch the current file if used. + }, + } + end, + } + end, +} diff --git a/plugins/nvim-cmp.lua b/plugins/nvim-cmp.lua new file mode 100644 index 0000000..5fa3c3f --- /dev/null +++ b/plugins/nvim-cmp.lua @@ -0,0 +1,24 @@ +return { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-emoji", -- add cmp source as dependency of cmp + }, + -- override the options table that is used in the `require("cmp").setup()` call + opts = function(_, opts) + -- opts parameter is the default options table + -- the function is lazy loaded so cmp is able to be required + local cmp = require "cmp" + -- modify the sources part of the options table + opts.sources = cmp.config.sources { + { name = "nvim_lsp", priority = 1000 }, + { name = "luasnip", priority = 750 }, + { name = "buffer", priority = 500 }, + { name = "path", priority = 250 }, + { name = "emoji", priority = 700 }, -- add new source + { name = "crates", priority = 1000 }, + } + + -- return the new table to be used + return opts + end, +} diff --git a/plugins/nvim-jdtls.lua b/plugins/nvim-jdtls.lua new file mode 100644 index 0000000..ec55509 --- /dev/null +++ b/plugins/nvim-jdtls.lua @@ -0,0 +1,3 @@ +return { + "mfussenegger/nvim-jdtls", -- load jdtls on module +} diff --git a/plugins/nvim-metals.lua b/plugins/nvim-metals.lua new file mode 100644 index 0000000..ab08fa7 --- /dev/null +++ b/plugins/nvim-metals.lua @@ -0,0 +1,4 @@ +return { + "scalameta/nvim-metals", + dependencies = { "nvim-lua/plenary.nvim" }, +} diff --git a/plugins/octo.lua b/plugins/octo.lua index 4d55c01..e762ea2 100644 --- a/plugins/octo.lua +++ b/plugins/octo.lua @@ -1,5 +1,6 @@ return { after = "telescope.nvim", "pwntester/octo.nvim", + event = "UIEnter", config = function() require("octo").setup() end, } diff --git a/plugins/ranger-nvim.lua b/plugins/ranger-nvim.lua index c8e917b..041af67 100644 --- a/plugins/ranger-nvim.lua +++ b/plugins/ranger-nvim.lua @@ -1,4 +1,5 @@ return { "kjuulh/ranger.nvim", + event = "UIEnter", config = function() require("ranger").setup {} end, } diff --git a/plugins/rust-tools.lua b/plugins/rust-tools.lua new file mode 100644 index 0000000..89b718b --- /dev/null +++ b/plugins/rust-tools.lua @@ -0,0 +1,3 @@ +return { + "simrat39/rust-tools.nvim", +} diff --git a/plugins/which-key.lua b/plugins/which-key.lua new file mode 100644 index 0000000..5727c77 --- /dev/null +++ b/plugins/which-key.lua @@ -0,0 +1,13 @@ +return { + "folke/which-key.nvim", + config = function(plugin, opts) + plugin.default_config(opts) + local wk = require "which-key" + wk.register({ + b = { name = "Buffer" }, + }, { + mode = "n", + prefix = "", + }) + end, +} diff --git a/which-key/register.lua b/which-key/register.lua deleted file mode 100644 index b5f78e2..0000000 --- a/which-key/register.lua +++ /dev/null @@ -1,13 +0,0 @@ -return { - -- first key is the mode, n == normal mode - n = { - -- second key is the prefix, prefixes - [""] = { - -- third key is the key to bring up next level and its displayed - -- group name in which-key top level menu - ["b"] = { name = "Buffer" }, - ["P"] = { "Telescope projects", "projects" }, - ["."] = { "Ranger", "ranger" }, - }, - }, -}