From c489d393695e90d424f9ae51e35c4d42358e6a71 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 9 Aug 2024 02:45:31 -0400 Subject: yes there's a bit of java in my nvim config why do you ask? --- lua/conf/plugins/biscuit.lua | 1 + lua/conf/plugins/cmp.lua | 170 +++++++++++++++ lua/conf/plugins/comment.lua | 7 + lua/conf/plugins/dressing.lua | 21 ++ lua/conf/plugins/fidget.lua | 34 +++ lua/conf/plugins/gitsigns.lua | 78 +++++++ lua/conf/plugins/glance.lua | 44 ++++ lua/conf/plugins/harpoon.lua | 31 +++ lua/conf/plugins/headlines.lua | 28 +++ lua/conf/plugins/incline.lua | 12 ++ lua/conf/plugins/jdtls.lua | 3 + lua/conf/plugins/lsp_lines.lua | 14 ++ lua/conf/plugins/lspconfig.lua | 18 ++ lua/conf/plugins/luasnip.lua | 52 +++++ lua/conf/plugins/mason-lspconfig.lua | 369 ++++++++++++++++++++++++++++++++ lua/conf/plugins/mason.lua | 31 +++ lua/conf/plugins/mellow.lua | 35 +++ lua/conf/plugins/neogen.lua | 19 ++ lua/conf/plugins/neorg.lua | 135 ++++++++++++ lua/conf/plugins/nvim-colorizer.lua | 11 + lua/conf/plugins/project.lua | 18 ++ lua/conf/plugins/telescope.lua | 78 +++++++ lua/conf/plugins/todo-comments.lua | 42 ++++ lua/conf/plugins/treesitter-context.lua | 40 ++++ lua/conf/plugins/treesitter.lua | 59 +++++ lua/conf/plugins/treesj.lua | 14 ++ lua/conf/plugins/undotree.lua | 12 ++ 27 files changed, 1376 insertions(+) create mode 100644 lua/conf/plugins/biscuit.lua create mode 100644 lua/conf/plugins/cmp.lua create mode 100644 lua/conf/plugins/comment.lua create mode 100644 lua/conf/plugins/dressing.lua create mode 100644 lua/conf/plugins/fidget.lua create mode 100644 lua/conf/plugins/gitsigns.lua create mode 100644 lua/conf/plugins/glance.lua create mode 100644 lua/conf/plugins/harpoon.lua create mode 100644 lua/conf/plugins/headlines.lua create mode 100644 lua/conf/plugins/incline.lua create mode 100644 lua/conf/plugins/jdtls.lua create mode 100644 lua/conf/plugins/lsp_lines.lua create mode 100644 lua/conf/plugins/lspconfig.lua create mode 100644 lua/conf/plugins/luasnip.lua create mode 100644 lua/conf/plugins/mason-lspconfig.lua create mode 100644 lua/conf/plugins/mason.lua create mode 100644 lua/conf/plugins/mellow.lua create mode 100644 lua/conf/plugins/neogen.lua create mode 100644 lua/conf/plugins/neorg.lua create mode 100644 lua/conf/plugins/nvim-colorizer.lua create mode 100644 lua/conf/plugins/project.lua create mode 100644 lua/conf/plugins/telescope.lua create mode 100644 lua/conf/plugins/todo-comments.lua create mode 100644 lua/conf/plugins/treesitter-context.lua create mode 100644 lua/conf/plugins/treesitter.lua create mode 100644 lua/conf/plugins/treesj.lua create mode 100644 lua/conf/plugins/undotree.lua (limited to 'lua/conf/plugins') diff --git a/lua/conf/plugins/biscuit.lua b/lua/conf/plugins/biscuit.lua new file mode 100644 index 0000000..d5a1067 --- /dev/null +++ b/lua/conf/plugins/biscuit.lua @@ -0,0 +1 @@ +return { 'Biscuit-Theme/nvim' } diff --git a/lua/conf/plugins/cmp.lua b/lua/conf/plugins/cmp.lua new file mode 100644 index 0000000..5dbb6ed --- /dev/null +++ b/lua/conf/plugins/cmp.lua @@ -0,0 +1,170 @@ +local function has_words_before() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true) + [1]:sub(col, col):match("%s") == nil +end + +return { 'hrsh7th/nvim-cmp', + requires = { + 'danymat/neogen', + 'nvim-treesitter/nvim-treesitter', + 'lukas-reineke/cmp-under-comparator' -- better results + }, + + -- suppliers for completions (they require nvim-cmp to be loaded before they are) + deps = { + 'hrsh7th/cmp-buffer', -- buffers + 'FelipeLema/cmp-async-path', -- path + 'hrsh7th/cmp-nvim-lsp', -- lsp + 'hrsh7th/cmp-nvim-lsp-signature-help', -- completion information + { 'L3MON4D3/cmp-luasnip-choice', -- luasnip + requires = 'L3MON4D3/LuaSnip' + } + }, + + function() + local cmp = require('cmp') + local luasnip = require('luasnip') + local neogen = require('neogen') + + cmp.setup { + -- disable when in comments + enabled = function() + local context = require('cmp.config.context') + if vim.api.nvim_get_mode().mode == 'c' then + return true + else + return not context.in_treesitter_capture("comment") + and not context.in_syntax_group("Comment") + end + end, + + -- completion sources + sources = cmp.config.sources { + { name = 'nvim_lsp', priority = 999 }, + { name = 'luasnip_choice', priority = 750 }, + { name = 'buffer', max_item_count = 3 }, + { name = 'async_path', max_item_count = 5 }, + { name = 'neorg' }, + { name = 'nvim_lsp_signature_help' } + }, + + -- how to sort results + sorting = { + comparators = { + cmp.config.compare.offset, + cmp.config.compare.exact, + cmp.config.compare.score, + require('cmp-under-comparator').under, + cmp.config.compare.kind, + cmp.config.compare.sort_text, + cmp.config.compare.length, + cmp.config.compare.order, + } + }, + + -- appearance of window + window = { + completion = { + scrollbar = false, + border = 'solid', + winhighlight = "Normal:WinBarNC,FloatBorder:WinBarNC,Search:WinBarNC", + }, + documentation = { + border = 'solid', + winhighlight = "Normal:WinBarNC,FloatBorder:WinBarNC,Search:WinBarNC", + } + }, + + -- position of window + view = { + entries = { + name = 'custom', + selection_order = 'near_cursor' + } + }, + + -- formatting of content + formatting = { + fields = { 'menu', 'abbr', 'kind' }, + format = function(entry, item) + local menu_icon = { + nvim_lsp = 'λ', + nvim_lua = 'v', + calc = '+', + luasnip = '%', + buffer = '@', + path = '#' + } + + item.menu = menu_icon[entry.source.name] + return item + end + }, + + experimental = { + ghost_text = true + }, + + -- snippet integration + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + + -- mappings + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping(function(fallback) + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true }) + elseif cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + if #cmp.get_entries() == 1 then + cmp.confirm({ select = true }) + end + elseif neogen.jumpable() then + neogen.jump_next() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + elseif neogen.jumpable(-1) then + neogen.jump_prev() + else + fallback() + end + end, { "i", "s" }), + + [''] = cmp.mapping { + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, + select = true }), + }, + + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.close(), + [""] = cmp.mapping.abort() + } + } + end +} diff --git a/lua/conf/plugins/comment.lua b/lua/conf/plugins/comment.lua new file mode 100644 index 0000000..9a6373d --- /dev/null +++ b/lua/conf/plugins/comment.lua @@ -0,0 +1,7 @@ +return { 'numToStr/Comment.nvim', + function() + require('Comment').setup { + ignore = '^$' + } + end +} diff --git a/lua/conf/plugins/dressing.lua b/lua/conf/plugins/dressing.lua new file mode 100644 index 0000000..64f9723 --- /dev/null +++ b/lua/conf/plugins/dressing.lua @@ -0,0 +1,21 @@ +local branch = nil +if vim.version().minor == 7 then + branch = 'nvim-0.7' +elseif vim.version().minor == 5 then + branch = 'nvim-0.5' +end + +return { 'stevearc/dressing.nvim', + disable = vim.version().minor < 5, + branch = branch, + requires = 'nvim-telescope/telescope.nvim', + function() + require('dressing').setup { + input = { + title_pos = "center", + border = 'solid', + relative = "win" + } + } + end +} diff --git a/lua/conf/plugins/fidget.lua b/lua/conf/plugins/fidget.lua new file mode 100644 index 0000000..e36488e --- /dev/null +++ b/lua/conf/plugins/fidget.lua @@ -0,0 +1,34 @@ +return { 'j-hui/fidget.nvim', + disable = vim.version().minor < 9, + function() + local notification_defaults = require("fidget.notification").default_config + notification_defaults["icon"] = "" + + require('fidget').setup { + progress = { + display = { + progress_icon = { + pattern = "line", + period = 1 + }, + done_icon = ":)", + } + }, + notification = { + override_vim_notify = true, + configs = { + default = notification_defaults, + }, + view = { + icon_separator = " ", + group_separator = "---", + group_separator_hl = "Comment", + }, + window = { + zindex = 44, + relative = "win" + } + } + } + end +} diff --git a/lua/conf/plugins/gitsigns.lua b/lua/conf/plugins/gitsigns.lua new file mode 100644 index 0000000..f168b93 --- /dev/null +++ b/lua/conf/plugins/gitsigns.lua @@ -0,0 +1,78 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'lewis6991/gitsigns.nvim', + disable = vim.version().minor < 9, + function() + local gs = require("gitsigns") + + gs.setup { + signs = { + add = { text = '│' }, + change = { text = '│' }, + delete = { text = '-' }, + topdelete = { text = '‾' }, + changedelete = { text = '~' }, + untracked = { text = '┆' } + }, + + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + + watch_gitdir = { + interval = 1000, + follow_files = true + }, + + attach_to_untracked = true, + current_line_blame_formatter = ', - ', + + preview_config = { border = 'solid' }, + + on_attach = function(bufnr) + local opts = { buffer = bufnr } + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + return ']c' + end + vim.schedule(function() gs.next_hunk() end) + return '' + end, { expr = true, buffer = bufnr }) + + map('n', '[c', function() + if vim.wo.diff then + return '[c' + end + vim.schedule(function() gs.prev_hunk() end) + return '' + end, { expr = true, buffer = bufnr }) + + -- Actions + map('n', 'hs', gs.stage_hunk, opts) + map('n', 'hr', gs.reset_hunk, opts) + map('v', 'hs', function() + gs.stage_hunk { vim.fn.line('.'), vim.fn.line('v') } + end, opts) + map('v', 'hr', function() + gs.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } + end, opts) + map('n', 'hS', gs.stage_buffer, opts) + map('n', 'hu', gs.undo_stage_hunk, opts) + map('n', 'hR', gs.reset_buffer, opts) + map('n', 'hp', gs.preview_hunk, opts) + map('n', 'hb', function() gs.blame_line { full=true } end, opts) + map('n', 'tb', gs.toggle_current_line_blame, opts) + map('n', 'hd', gs.diffthis, opts) + map('n', 'hD', function() gs.diffthis('~') end, opts) + map('n', 'td', gs.toggle_deleted, opts) + + -- Text object + map({ 'o', 'x' }, 'ih', ':Gitsigns select_hunk', opts) + end + } + end +} diff --git a/lua/conf/plugins/glance.lua b/lua/conf/plugins/glance.lua new file mode 100644 index 0000000..c5a4d41 --- /dev/null +++ b/lua/conf/plugins/glance.lua @@ -0,0 +1,44 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'dnlhc/glance.nvim', + disable = vim.version().minor < 7, + function() + require('glance').setup { + border = { + enable = true, + top_char = '', + bottom_char = '─', + }, + folds = { + fold_closed = '+', + fold_open = '-', + folded = true + }, + theme = { + enable = false + }, + hooks = { + before_open = function(results, open, jump, method) + local uri = vim.uri_from_bufnr(0) + if #results == 1 then + local target_uri = results[1].uri or results[1].targetUri + + if target_uri == uri then + jump() + misc.timeout_highlight() + return + end + end + + open() + end + } + } + + map('n', 'gd', 'Glance definitions') + map('n', 'gr', 'Glance references') + map('n', 'gy', 'Glance type_definitions') + map('n', 'gi', 'Glance implementations') + end +} diff --git a/lua/conf/plugins/harpoon.lua b/lua/conf/plugins/harpoon.lua new file mode 100644 index 0000000..cb2edca --- /dev/null +++ b/lua/conf/plugins/harpoon.lua @@ -0,0 +1,31 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'ThePrimeagen/harpoon', + disable = vim.version().minor < 8, + branch = 'harpoon2', + requires = 'nvim-lua/plenary.nvim', + function() + local harpoon = require("harpoon") + + harpoon:setup() + + map("n", "a", function() + harpoon:list():add() + vim.notify("added "..vim.fn.expand("%:t").." to quickmarks", vim.log.levels.INFO, { + title = misc.appid, + }) + end, { desc = "add current file to quickmarks" }) + + map("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) + + map("n", "", function() harpoon:list():select(1) end) + map("n", "", function() harpoon:list():select(2) end) + map("n", "", function() harpoon:list():select(3) end) + map("n", "", function() harpoon:list():select(4) end) + + -- Toggle previous & next buffers stored within Harpoon list + map("n", "", function() harpoon:list():prev() end) + map("n", "", function() harpoon:list():next() end) + end +} diff --git a/lua/conf/plugins/headlines.lua b/lua/conf/plugins/headlines.lua new file mode 100644 index 0000000..c932d72 --- /dev/null +++ b/lua/conf/plugins/headlines.lua @@ -0,0 +1,28 @@ +return { 'lukas-reineke/headlines.nvim', + requires = 'nvim-treesitter/nvim-treesitter', + function() + require('headlines').setup { + norg = { + headline_highlights = { + "@neorg.headings.1.title", + "@neorg.headings.2.title", + "@neorg.headings.3.title", + "@neorg.headings.4.title", + "@neorg.headings.5.title", + "@neorg.headings.6.title" + }, + bullets = { "", "", "", "" }, + }, + markdown = { + headline_highlights = { + "@neorg.headings.1.title", + "@neorg.headings.2.title", + "@neorg.headings.3.title", + "@neorg.headings.4.title", + "@neorg.headings.5.title", + "@neorg.headings.6.title" + } + } + } + end +} diff --git a/lua/conf/plugins/incline.lua b/lua/conf/plugins/incline.lua new file mode 100644 index 0000000..03b4284 --- /dev/null +++ b/lua/conf/plugins/incline.lua @@ -0,0 +1,12 @@ +return { 'b0o/incline.nvim', + function() + vim.cmd('set laststatus=3') + + require('incline').setup { + hide = { + focused_win = true, + cursorline = true + } + } + end +} diff --git a/lua/conf/plugins/jdtls.lua b/lua/conf/plugins/jdtls.lua new file mode 100644 index 0000000..e9808d6 --- /dev/null +++ b/lua/conf/plugins/jdtls.lua @@ -0,0 +1,3 @@ +return { 'mfussenegger/nvim-jdtls', + disable = vim.version().minor < 6 +} diff --git a/lua/conf/plugins/lsp_lines.lua b/lua/conf/plugins/lsp_lines.lua new file mode 100644 index 0000000..b257de5 --- /dev/null +++ b/lua/conf/plugins/lsp_lines.lua @@ -0,0 +1,14 @@ +return { 'whynothugo/lsp_lines.nvim', + url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim', + requires = 'neovim/nvim-lspconfig', + function() + require('lsp_lines').setup() + + vim.diagnostic.config { + virtual_lines = { + highlight_whole_line = false, + only_current_line = true + } + } + end +} diff --git a/lua/conf/plugins/lspconfig.lua b/lua/conf/plugins/lspconfig.lua new file mode 100644 index 0000000..3dce638 --- /dev/null +++ b/lua/conf/plugins/lspconfig.lua @@ -0,0 +1,18 @@ +return { 'neovim/nvim-lspconfig', + disable = vim.version().minor < 8, + function() + vim.diagnostic.config { + virtual_text = false, + signs = true, + update_in_insert = false, + underline = true, + severity_sort = true + } + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, { border = 'solid' }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, { border = 'solid' }) + end +} diff --git a/lua/conf/plugins/luasnip.lua b/lua/conf/plugins/luasnip.lua new file mode 100644 index 0000000..26b293b --- /dev/null +++ b/lua/conf/plugins/luasnip.lua @@ -0,0 +1,52 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'L3MON4D3/LuaSnip', + branch = 'v2.3.0', + disable = vim.version().minor < 7, + config = function() + vim.cmd('make install_jsregexp') + end, + function() + local luasnip = require('luasnip') + local types = require("luasnip.util.types") + + luasnip.config.set_config { + history = true, -- return back into snippet + updateevents = { "TextChanged", "TextChangedI" }, -- update on text insert + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = {{ "●", "@boolean" }} + } + }, + [types.insertNode] = { + active = { + virt_text = {{ "●", "@constant" }} + } + }, + }, + } + + map({"i", "s"}, { "", "" }, function() + if luasnip.choice_active() then + luasnip.change_choice(1) + end + end) + + map({"i", "s"}, "", function() + if luasnip.expandable(-1) then + luasnip.expand(-1) + end + end) + + -- load all snippets from snippet directory + for _, file in ipairs(vim.api.nvim_get_runtime_file("lua/snippets/*.lua", true)) do + local fn = file:gsub('^.*/', ''):gsub('%.lua$', '') + local ret = misc.include('snippets.'..fn) + if type(ret) ~= "boolean" then + luasnip.add_snippets(fn, ret, { key = fn }) + end + end + end +} diff --git a/lua/conf/plugins/mason-lspconfig.lua b/lua/conf/plugins/mason-lspconfig.lua new file mode 100644 index 0000000..edeaf93 --- /dev/null +++ b/lua/conf/plugins/mason-lspconfig.lua @@ -0,0 +1,369 @@ +local misc = require('core.misc') +local map, auto, augroup = misc.map, misc.auto, misc.augroup + +return { 'williamboman/mason-lspconfig.nvim', + requires = { + 'williamboman/mason.nvim', + 'mfussenegger/nvim-jdtls', + 'neovim/nvim-lspconfig' + }, + function() + local util = require('lspconfig.util') + + -- configure lsp when attached + local function lsp_attach(client, bufnr) + -- helper function(s) + local function set_lsp_sign(name, text) + vim.fn.sign_define(name, { text = text, texthl = name }) + end + + set_lsp_sign("DiagnosticSignError", "x") + set_lsp_sign("DiagnosticSignWarn" , "!") + set_lsp_sign("DiagnosticSignInfo" , "i") + set_lsp_sign("DiagnosticSignHint" , "h") + + local opts = { buffer = bufnr } + -- LSP actions + map('n', 'K', vim.lsp.buf.hover, opts) + map('n', 'gD', vim.lsp.buf.definition, opts) + -- map('n', 'gD', 'lua vim.lsp.buf.declaration()') + map('n', 'gI', vim.lsp.buf.implementation, opts) + map('n', 'gY', vim.lsp.buf.type_definition, opts) + map('n', 'gR', vim.lsp.buf.references, opts) + map('n', '', vim.lsp.buf.signature_help, opts) + map('n', 'lr', vim.lsp.buf.rename, opts) + map('n', '', vim.lsp.buf.rename, opts) + map('n', 'gA', vim.lsp.buf.code_action, { + buffer = bufnr, + desc = 'check code actions', + }) + map('n', '', vim.lsp.buf.code_action, { + buffer = bufnr, + desc = 'check code actions' + }) + + -- Diagnostics + map('n', '[d', vim.diagnostic.goto_prev) + map('n', ']d', vim.diagnostic.goto_next) + end + + -- setup lsp capabilities + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem = { + documentationFormat = { "markdown", "plaintext" }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { + valueSet = { 1 } + }, + resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits" + } + } + } + + -- setup language servers + require('mason-lspconfig').setup { + ensure_installed = { + "lua_ls", + "clangd", + "jdtls", + "tsserver", + "phpactor", + "html", + "cssls", + "bashls", + "zls" + -- "asm-lsp", -- seems to be broken + } + } + require('mason-lspconfig').setup_handlers { + function(server_name) + require('lspconfig')[server_name].setup { + on_attach = lsp_attach, + capabilities = capabilities + } + end, + + -- setup luals + ["lua_ls"] = function(server_name) + local root_files = { '.luarc.json', '.luarc.jsonc', '.luacheckrc', + '.stylua.toml', 'stylua.toml', 'selene.toml', 'selene.yml', + 'README.md' + } + + -- FIXME: for some reason luals randomly resets the indentation of code + -- when pressing o or O. Right now this is a minor annoyance I will deal + -- with in exchange for really good lua lsp support. + -- + -- FIXME: luals also seems to start up twice and sends back twice the + -- completions (one configured with the below settings and one without) + require('lspconfig')[server_name].setup { + on_attach = lsp_attach, + settings = { + Lua = { + diagnostics = { + globals = { "vim", 'mp' } + }, + runtime = { + version = 'LuaJIT' + }, + format = { + enable = false + }, + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME + } + } + } + }, + + root_dir = function(fname) + local root = util.root_pattern(unpack(root_files))(fname) + if root and root ~= vim.env.HOME then + return root + end + + root = util.root_pattern('lua/')(fname) + if root then + return root + end + return util.find_git_ancestor(fname) + end + } + end, + + -- setup clangd + ["clangd"] = function(server_name) + require('lspconfig')[server_name].setup { + on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + + -- add some clangd specific mappings + local opts = { buffer = bufnr } + map("n", "o", "ClangdSwitchSourceHeader", opts) + end, + capabilities = capabilities, + + cmd = { + "clangd", + "--background-index", + "--clang-tidy", + "--header-insertion=iwyu", + "--completion-style=detailed", + "--function-arg-placeholders", + "--fallback-style=llvm" + }, + init_options = { + usePlaceholders = true, + clangdFileStatus = true, + fallback_flags = { + "-xc" -- makes clangd think we're using c instead of c++ + } + } + } + end, + + -- setup jdtls + ["jdtls"] = function(server_name) + auto("Filetype", { + pattern = "java", + callback = function() + -- must be a java interpreter of version 17 or greater + local java = "java" + + local buffer = {} + ---@type function + local startlsp + + -- check if version of java in use is high enough + vim.fn.jobstart({ java, vim.fn.stdpath('config').."/extras/JavaVersion.java" }, { + stdin = nil, + on_stdout = function(_, data, _) + table.insert(buffer, table.concat(data)) + end, + on_exit = function(_, exit_code, _) + local v = vim.version.parse(table.concat(buffer)) + + -- if there's an error, no version info, or the java version is + -- less than 17 stop the lsp from starting + if exit_code ~= 0 then + vim.notify(string.format( + "java version check failed: exit code %s", exit_code), + vim.log.levels.ERROR, { title = misc.appid }) + return + elseif not v then + vim.notify("no java version info found", vim.log.levels.ERROR, + { title = misc.appid }) + return + elseif v.major < 17 then + vim.notify(string.format( + "java version %s < 17.0.0 Cannot run jdtls, bailing out", + v[1].."."..v[2].."."..v[3]), + vim.log.levels.ERROR, { title = misc.appid }) + return + end + + startlsp() + end + }) + + function startlsp() + local ok, jdtls = pcall(require, "jdtls") + if not ok then + vim.notify("jdtls not found, can't start java lsp", + vim.log.levels.ERROR, {}) + return + end + + local config = {} + + config.on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + + -- add some jdtls specific mappings + local opts = { buffer = bufnr } + map('n', 'cri', jdtls.organize_imports, opts) + map('n', 'crv', jdtls.extract_variable, opts) + map('n', 'crc', jdtls.extract_constant, opts) + map('x', 'crv', "lua require('jdtls').extract_variable(true)", opts) + map('x', 'crc', "lua require('jdtls').extract_constant(true)", opts) + map('x', 'crm', "lua require('jdtls').extract_method(true)", opts) + + -- refresh the codelens every time after writing the file + local jdtls_cmds = augroup("jdtls_cmds") + + pcall(vim.lsp.codelens.refresh) + auto('BufWritePost', { + buffer = bufnr, + group = jdtls_cmds, + desc = 'refresh codelens', + callback = function() + pcall(vim.lsp.codelens.refresh) + end + }) + end + + -- setup path stuff + local path = {} + local jdtls_install = require('mason-registry').get_package('jdtls'):get_install_path() + path.data_dir = vim.fn.stdpath('cache')..'/nvim-jdtls' + path.java_agent = jdtls_install..'/lombok.jar' + path.launcher_jar = vim.fn.glob(jdtls_install..'/plugins/org.eclipse.equinox.launcher_*.jar') + path.platform_config = jdtls_install..'/config_linux' + path.bundles = {} + + -- data dir + local data_dir = path.data_dir..'/'..vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') + + -- enable basic capabilities + config.capabilities = capabilities + + -- enable some extended client capabilities + local extendedClientCapabilities = jdtls.extendedClientCapabilities + extendedClientCapabilities.resolveAdditionalTextEditsSupport = true + + -- command to start the lsp server + config.cmd = { + java, -- this has to be java17 or newer + '-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', + '-Xmx1G', + '--add-modules=ALL-SYSTEM', + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + '-jar', path.launcher_jar, + '-configuration', path.platform_config, + '-data', data_dir + } + + -- settings + config.settings = { + java = { + eclipse = { downloadSources = true }, + gradle = { enabled = true }, + maven = { downloadSources = true }, + implementationsCodeLens = { enabled = true }, + referencesCodeLens = { enabled = true }, + references = { includeDecompiledSources = true }, + symbols = { includeSourceMethodDeclarations = true }, + inlayHints = { + parameterNames = { + enabled = "all" + } + }, + completion = { + favoriteStaticMembers = { + "org.hamcrest.MatcherAssert.assertThat", + "org.hamcrest.Matchers.*", + "org.hamcrest.CoreMatchers.*", + "org.junit.jupiter.api.Assertions.*", + "java.util.Objects.requireNonNull", + "java.util.Objects.requireNonNullElse", + "org.mockito.Mockito.*" + }, + filteredTypes = { + "com.sun.*", + "io.micrometer.shaded.*", + "java.awt.*", + "jdk.*", + "sun.*" + }, + importOrder = { + "java", + "javax", + "com", + "org" + } + }, + sources = { + organizeImports = { + starThreshold = 9999, + staticStarThreshold = 9999 + } + }, + codeGeneration = { + toString = { + template = '${object.className}{${member.name()}=${member.value}, ${otherMembers}}' + }, + hashCodeEquals = { useJava7Objects = true }, + useBlocks = true, + } + } + } + config.signatureHelp = { enabled = true } + config.flags = { allow_incremental_sync = true } + + -- disable all messages from printing + config.handlers = { + ['language/status'] = function() end + } + + config.init_options = { + extendedClientCapabilities = extendedClientCapabilities, + } + + config.root_dir = vim.fs.root(0, { ".git", "mvnw", ".gradle", + "gradlew" }) + + -- start it up + jdtls.start_or_attach(config) + end + end + }) + end + } + end +} diff --git a/lua/conf/plugins/mason.lua b/lua/conf/plugins/mason.lua new file mode 100644 index 0000000..b3eeacf --- /dev/null +++ b/lua/conf/plugins/mason.lua @@ -0,0 +1,31 @@ +return { 'williamboman/mason.nvim', + disable = vim.version().minor < 7, + function() + local mason = require('mason') + + mason.setup { + ui = { + border = "solid", + width = 0.8, + height = 0.9, + + icons = { + package_installed = "+", + package_pending = "?", + package_uninstalled = "x" + } + }, + keymaps = { + toggle_package_expand = "", + install_package = "i", + update_package = "u", + check_package_version = "c", + update_all_packages = "U", + check_outdated_packages = "C", + uninstall_package = "r", + cancel_installation = "", + apply_language_filter = "" + } + } + end +} diff --git a/lua/conf/plugins/mellow.lua b/lua/conf/plugins/mellow.lua new file mode 100644 index 0000000..af805ed --- /dev/null +++ b/lua/conf/plugins/mellow.lua @@ -0,0 +1,35 @@ +return { 'mellow-theme/mellow.nvim', + requires = 'nvim-treesitter/nvim-treesitter', + function() + vim.g.mellow_variant = "dark" + local c = require("mellow.colors")[vim.g.mellow_variant] + + vim.g.mellow_highlight_overrides = { + -- stop inactive windows from having a darker bg + ["NormalNC"] = { link = "Normal" }, + + -- make floats darker + ["NormalFloat"] = { fg = c.fg, bg = c.bg_dark }, + ["FloatBorder"] = { link = "NormalFloat" }, + + -- neorg headings, looks extra good with lukas-reineke/headlines.nvim + ["@neorg.headings.1.title"] = { fg = c.yellow, bg = "#2a211c" }, + ["@neorg.headings.1.icon"] = { link = "@neorg.headings.1.title" }, + + ["@neorg.headings.2.title"] = { fg = c.blue, bg = '#201e25' }, + ["@neorg.headings.2.icon"] = { link = "@neorg.headings.2.title" }, + + ["@neorg.headings.3.title"] = { fg = c.cyan, bg = '#2b1b20' }, + ["@neorg.headings.3.icon"] = { link = "@neorg.headings.3.title" }, + + ["@neorg.headings.4.title"] = { fg = c.green, bg = '#1d201e' }, + ["@neorg.headings.4.icon"] = { link = "@neorg.headings.4.title" }, + + ["@neorg.headings.5.title"] = { fg = c.magenta, bg = '#251a21' }, + ["@neorg.headings.5.icon"] = { link = "@neorg.headings.5.title" }, + + ["@neorg.headings.6.title"] = { fg = c.white, bg = '#212126' }, + ["@neorg.headings.6.icon"] = { link = "@neorg.headings.6.title" } + } + end +} diff --git a/lua/conf/plugins/neogen.lua b/lua/conf/plugins/neogen.lua new file mode 100644 index 0000000..19c3422 --- /dev/null +++ b/lua/conf/plugins/neogen.lua @@ -0,0 +1,19 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'danymat/neogen', + requires = { + 'nvim-treesitter/nvim-treesitter', + 'L3MON4D3/LuaSnip' + }, + function() + local neogen = require('neogen') + neogen.setup { + enabled = true, + input_after_comment = true, + snippet_engine = "luasnip", + } + + map('n', 'd', neogen.generate) + end +} diff --git a/lua/conf/plugins/neorg.lua b/lua/conf/plugins/neorg.lua new file mode 100644 index 0000000..b67cb78 --- /dev/null +++ b/lua/conf/plugins/neorg.lua @@ -0,0 +1,135 @@ +-- WARNING: neorg does some pretty stupid stuff when it comes to the plugins it +-- wants (using luarocks), in order to get around all that bullshit I've +-- manually added it's dependencies. Because I don't want this to randomly break +-- I've also pinned neorg to the latest working version that I've messed around +-- with. +-- +-- NOTE: for my future self to update this thingy while not breaking +-- dependencies take a look at the build.lua for versioning info. Also make sure +-- to check the release notes on github for info on breaking changes. + +local workspace_cache = vim.fs.joinpath(vim.fn.stdpath("data"), "neorg-workspace-cache.lua") + +--- populate neorg workspaces from path or cache +---@param path string path to populate workspaces from +---@param cache boolean? if true will re populate the cache from the fs +---@return table workspaces +local function populate_workspaces(path, cache) + local workspaces = {} + cache = cache or false + + if vim.fn.filereadable(workspace_cache) == 1 and not cache then + local ok, ret = pcall(dofile, workspace_cache) + if ok and type(ret) == "table" then + return ret + end + end + + -- loop through all files in path if path is not empty + if vim.fn.empty(vim.fn.glob(path)) == 0 then + for n, t in vim.fs.dir(path) do + if string.sub(n, 1, 1) == "." or (t ~= "directory" and t ~= "link") then + goto continue + end + -- make sure this still works if the last charachter in the path isn't a '/' + workspaces[n] = (string.sub(path, #path, #path) == "/") and path..n or path.."/"..n + ::continue:: + end + end + + -- write data to cachefile + local f = io.open(workspace_cache, "w+") + if not f then + return workspaces + end + + f:write("return") + local ret = vim.inspect(workspaces) + if type(ret) == "string" then + f:write(ret) + else + f:write("false") + end + + f:close() + + return workspaces +end + +return { 'nvim-neorg/neorg', + disable = vim.version.lt(vim.version(), { 0, 10, 0 }), + branch = 'v9.1.1', + requires = { + 'nvim-lua/plenary.nvim', + 'nvim-treesitter/nvim-treesitter', + 'folke/zen-mode.nvim', + 'hrsh7th/nvim-cmp', + { 'nvim-neorg/neorg-telescope', + requires = 'nvim-telescope/telescope.nvim' + }, + + -- NOTE: these are usually installed by neorg via luarocks, the versions + -- were picked based on the build.lua found in the root of the neorg repo + { 'nvim-neotest/nvim-nio', + branch = 'v1.7.0' + }, + { 'nvim-neorg/lua-utils.nvim', + branch = 'v1.0.2' + }, + { 'MunifTanjim/nui.nvim', + branch = '0.3.0' + }, + { 'pysan3/pathlib.nvim', + branch = 'v2.2.2' + } + }, + + function() + local wsphome = (os.getenv("XDG_DOCUMENTS_DIR") or + (os.getenv("HOME").."/Documents")).."/notes/" + + require('neorg').setup { + load = { + -- not sure how to sort the modules so ima just put the empty ones first + ["core.defaults"] = {}, + ["core.export"] = {}, + ["core.export.markdown"] = {}, + ["core.integrations.telescope"] = {}, + ["core.summary"] = {}, + ["core.ui.calendar"] = {}, + + ["core.completion"] = { + config = { + engine = "nvim-cmp" + } + }, + ["core.concealer"] = { + config = { + folds = false + } + }, + ["core.dirman"] = { + config = { + -- a list of available workspaces are generated at runtime >:) + workspaces = populate_workspaces(wsphome) + } + }, + ["core.esupports.metagen"] = { + config = { + type = "auto" + } + }, + ["core.presenter"] = { + config = { + zen_mode = "zen-mode" + } + }, + ["core.qol.toc"] = { + config = { + close_after_use = true + } + } + } + } + end +} diff --git a/lua/conf/plugins/nvim-colorizer.lua b/lua/conf/plugins/nvim-colorizer.lua new file mode 100644 index 0000000..c37dfb1 --- /dev/null +++ b/lua/conf/plugins/nvim-colorizer.lua @@ -0,0 +1,11 @@ +return { 'NvChad/nvim-colorizer.lua', + disable = vim.version().minor < 7 and not vim.fn.has("termguicolors"), + function() + require('colorizer').setup { + user_default_options = { + names = false, + css = true + } + } + end +} diff --git a/lua/conf/plugins/project.lua b/lua/conf/plugins/project.lua new file mode 100644 index 0000000..afc5ecf --- /dev/null +++ b/lua/conf/plugins/project.lua @@ -0,0 +1,18 @@ +return { 'ahmedkhalf/project.nvim', + disable = vim.version().minor < 5, + function() + require('project_nvim').setup { + patterns = { + ".git", + "Makefile", + "_darcs", + ".hg", + ".bzr", + ".svn", + "package.json", + "index.norg", + "README.md" + } + } + end +} diff --git a/lua/conf/plugins/telescope.lua b/lua/conf/plugins/telescope.lua new file mode 100644 index 0000000..20f516d --- /dev/null +++ b/lua/conf/plugins/telescope.lua @@ -0,0 +1,78 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'nvim-telescope/telescope.nvim', + disable = vim.version().minor < 9, + requires = { + 'nvim-lua/plenary.nvim', + { 'nvim-telescope/telescope-fzf-native.nvim', + config = function() + vim.cmd('make') + end + } + }, + function() + local telescope = require("telescope") + local actions = require('telescope.actions') + local action_layout = require("telescope.actions.layout") + + local function telescopew() + if vim.o.columns <= 80 then + return vim.o.columns + else + return 0.8 + end + end + + telescope.setup { + defaults = { + borderchars = { + prompt = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, + results = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, + preview = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' }, + }, + winblend = 0, + layout_strategy = 'horizontal', + sorting_strategy = 'descending', + scroll_strategy = 'limit', + layout_config = { + horizontal = { + width = telescopew(), + height = 20, + prompt_position = 'bottom', + anchor = 'N', + } + }, + mappings = { + i = { + [""] = actions.close, + [''] = actions.move_selection_next, + [''] = actions.move_selection_previous, + [''] = actions.select_default, + [''] = actions.preview_scrolling_up, + [''] = actions.preview_scrolling_down, + [""] = action_layout.toggle_preview + }, + n = { + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + } + } + } + } + + local telebuilt = require('telescope.builtin') + map('n', 'f', function() + telebuilt.fd { follow = true } + end, { desc = 'Find files.' }) + map('n', 's', telebuilt.live_grep, { desc = 'Find string in project.' }) + map('n', 'b', telebuilt.current_buffer_fuzzy_find, { + desc = 'Find string in current buffer.', + }) + + -- enable previewing in the default colorscheme switcher + telebuilt.colorscheme = function() + require("telescope.builtin.__internal").colorscheme { enable_preview = true } + end + end +} diff --git a/lua/conf/plugins/todo-comments.lua b/lua/conf/plugins/todo-comments.lua new file mode 100644 index 0000000..55ebd32 --- /dev/null +++ b/lua/conf/plugins/todo-comments.lua @@ -0,0 +1,42 @@ +local branch = nil +if vim.version().minor < 8 then + branch = 'neovim-pre-0.8.0' +end + +return { 'folke/todo-comments.nvim', + requires = 'nvim-lua/plenary.nvim', + branch = branch, + function() + require('todo-comments').setup { + keywords = { + FIX = { + icon = "# ", + alt = { "FIXME", "BUG" }, + }, + HACK = { + icon = "* ", + color = "warning", + }, + WARN = { + icon = "! ", + color = "warning", + alt = { "WARNING", "XXX" }, + }, + NOTE = { + icon = "i ", + color = "hint", + alt = { "INFO", "TODO" }, + }, + PERF = { + icon = "@ ", + alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" }, + }, + TEST = { + icon = "@ ", + color = "test", + alt = { "TESTING", "PASSED", "FAILED" }, + }, + }, + } + end +} diff --git a/lua/conf/plugins/treesitter-context.lua b/lua/conf/plugins/treesitter-context.lua new file mode 100644 index 0000000..3306e6b --- /dev/null +++ b/lua/conf/plugins/treesitter-context.lua @@ -0,0 +1,40 @@ +local misc = require("core.misc") +local map = misc.map + +local branch = nil +if vim.version().minor == 7 then + branch = 'compat/0.7' +end + +return { 'nvim-treesitter/nvim-treesitter-context', + disable = vim.version().minor < 7, + branch = branch, + requires = 'nvim-treesitter/nvim-treesitter', + function() + local treesitter_context = require("treesitter-context") + + treesitter_context.setup { + enable = true, + line_numbers = true, + separator = '─', + } + + -- mapping to jump to the first closest line of context in buffer + map("n", "[j", function() + local lline = vim.api.nvim_win_get_cursor(0)[1]; + local line + + -- go to the first closest line of context and center it + treesitter_context.go_to_context() + vim.api.nvim_input('zz') + + -- make sure we actually moved + line = vim.api.nvim_win_get_cursor(0)[1]; + if line == lline then + return + end + + misc.timeout_highlight() + end) + end +} diff --git a/lua/conf/plugins/treesitter.lua b/lua/conf/plugins/treesitter.lua new file mode 100644 index 0000000..c24d454 --- /dev/null +++ b/lua/conf/plugins/treesitter.lua @@ -0,0 +1,59 @@ +table.contains = function(self, string) + for _, v in pairs(self) do + if v == string then + return true + end + end + return false +end + +return { 'nvim-treesitter/nvim-treesitter', + disable = vim.version.lt(vim.version(), { 0, 9, 2 }), + config = function() + vim.cmd("TSUpdate") + end, + function() + require('nvim-treesitter.configs').setup { + -- good default parsers + ensure_installed = { "c", "lua", "vim", "vimdoc", "markdown", + "markdown_inline", "java", "bash", "css", "html", "luadoc" + }, + + -- install missing parsers + auto_install = true, + + -- indentation + indent = { + enable = true, + + disable = function(lang, buf) + -- disable indenting in php (it's more broken with than without) + return table.contains({ + "php" + }, lang) + end + }, + + -- enable highlighting + highlight = { + enable = true, + -- use vim highlighting in addition to treesitter + additional_vim_regex_highlighting = true, + + disable = function(lang, buf) + -- disable in diff files + local langs = { "diff" } + if table.contains(langs, lang) then + return true + end + + -- disable in big files + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > (1024 * 100 * 10) --[[1MB]] then + return true + end + end + } + } + end +} diff --git a/lua/conf/plugins/treesj.lua b/lua/conf/plugins/treesj.lua new file mode 100644 index 0000000..8ec65d4 --- /dev/null +++ b/lua/conf/plugins/treesj.lua @@ -0,0 +1,14 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'Wansmer/treesj', + disable = vim.version().minor < 9, + requires = 'nvim-treesitter/nvim-treesitter', + function() + require('treesj').setup { + use_default_keymaps = false, + } + + map('n', 'j', require('treesj').toggle, { desc = 'fold code' }) + end +} diff --git a/lua/conf/plugins/undotree.lua b/lua/conf/plugins/undotree.lua new file mode 100644 index 0000000..e649d57 --- /dev/null +++ b/lua/conf/plugins/undotree.lua @@ -0,0 +1,12 @@ +local misc = require('core.misc') +local map = misc.map + +return { 'mbbill/undotree', + function() + if (vim.g.loaded_undotree) then + vim.g.undotree_DiffAutoOpen = 0 + end + + map("n", "u", "UndotreeToggle") + end +} -- cgit v1.2.1