diff options
37 files changed, 888 insertions, 278 deletions
diff --git a/after/ftplugin/java.lua b/after/ftplugin/java.lua new file mode 100644 index 0000000..26e7e2e --- /dev/null +++ b/after/ftplugin/java.lua @@ -0,0 +1,136 @@ +local misc = require('core.misc') +local lsp = require('core.lsp.functions') +local map, auto = misc.map, misc.auto + +local jdtls = require('jdtls') +local jdtls_install = require('mason-registry').get_package('jdtls'):get_install_path() + +-- make sure to check if things with 💀 need updating +local config = { + cmd = { + 'java', -- 💀 + '-jar', vim.fn.glob(jdtls_install..'/plugins/org.eclipse.equinox.launcher_*.jar'), -- 💀 + '-configuration', jdtls_install..'/config_linux', + '-data', vim.fn.stdpath('cache')..'/nvim-jdtls', + + '--add-modules=ALL-SYSTEM', + '--add-opens', 'java.base/java.lang=ALL-UNNAMED', + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + '-Declipse.application=org.eclipse.jdt.ls.core.id1', + '-Declipse.product=org.eclipse.jdt.ls.core.product', + '-Dlog.level=ALL', + '-Dlog.protocol=true', + '-Dosgi.bundles.defaultStartLevel=4', + '-Xmx1G', + }, + root_dir = vim.fs.dirname(vim.fs.find({ + 'gradlew', + '.git', + 'mvnw', + 'settings.gradle', -- Gradle (multi-project) + 'settings.gradle.kts', -- Gradle (multi-project) + 'build.xml', -- Ant + 'pom.xml', -- Maven + }, { upward = true })[1]), + + -- don't print out status messages + handlers = { + ['language/status'] = function() end + }, + + on_attach = function(_, 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', function() jdtls.extract_variable(true) end, opts) + map('x', 'crc', function() jdtls.extract_constant(true) end, opts) + map('x', 'crm', function() jdtls.extract_method(true) end, opts) + + pcall(vim.lsp.codelens.refresh) + auto('BufWritePost', { + buffer = bufnr, + desc = 'refresh codelens', + callback = function() + pcall(vim.lsp.codelens.refresh) + end + }) + end, + capabilities = lsp.capabilities +} + +-- generate the path to the java file(s) +---@type string|nil +local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"), "/JavaVersion.class") +---@type string|nil +local src_path = vim.fs.joinpath(vim.fn.stdpath("config"), "/extras/JavaVersion.java") + +-- if either path is invalid +if not cache_path or not src_path then + return +end + +--- build a cache of the JavaVersion code +local function build_cache() + -- check if we have javac + vim.system({ "javac" }, {}, function(out) + if out.code == 127 then + cache_path = nil + return + end + + -- compile our code + vim.system({ 'javac', src_path, '-d', vim.fn.stdpath("cache") }, {}, function(out) + if out.code ~= 0 then + cache_path = nil + end + end) + end) +end + +-- check if we have a compiled version of JavaVersion +local f, _ = io.open(cache_path, "r") +if not f then -- if we don't have a cache + build_cache() +else + io.close(f) +end + +-- check the java version +local buffer = {} +vim.fn.jobstart({ + config.cmd[1], + (cache_path and "JavaVersion") or src_path +}, { + cwd = vim.fn.stdpath("cache"), + 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 + + -- start lsp + jdtls.start_or_attach(config) + end + }) diff --git a/after/ftplugin/norg.lua b/after/ftplugin/norg.lua index c09a36e..fc69be9 100644 --- a/after/ftplugin/norg.lua +++ b/after/ftplugin/norg.lua @@ -17,7 +17,7 @@ end, "so") -- if the parsers don't exist download them if found[0] < 2 and (not found["norg.so"] or not found["norg_meta.so"]) then - vim.cmd.Neorg("sync-parsers") + vim.cmd("Neorg sync-parsers") end -- set colorcolumn in norg buffers @@ -1,12 +1,14 @@ -- enable performance stuff -vim.loader.enable() +if vim.fn.has("nvim-0.9") == true then + vim.loader.enable() +end -- bootstrap plugin manager local path = vim.fn.stdpath("data").."/site/pack/deps/opt/dep" if vim.fn.empty(vim.fn.glob(path)) > 0 then vim.fn.system({ "git", "clone", "--depth=1", "https://git.squi.bid/dep", path }) end -vim.cmd.packadd("dep") +vim.cmd("packadd dep") -- load miscellaneous utilities local misc = require('core.misc') diff --git a/lua/conf/autos.lua b/lua/conf/autos.lua index f5b232e..b23d26e 100644 --- a/lua/conf/autos.lua +++ b/lua/conf/autos.lua @@ -24,7 +24,8 @@ auto('BufRead', { group = bufcheck, desc = 'Return to the last place the buffer was closed in.', callback = function() - vim.cmd.call([[setpos(".", getpos("'\""))]]) + vim.fn.setpos('.', vim.fn.getpos("'\"")) + vim.cmd("norm! zz") end }) diff --git a/lua/conf/binds.lua b/lua/conf/binds.lua index 1426ac3..8f3c05e 100644 --- a/lua/conf/binds.lua +++ b/lua/conf/binds.lua @@ -52,9 +52,9 @@ vim.keymap.set('n', 'z=', function() end, { desc = 'Shows spelling suggestions' }) -- quickfix -map('n', '<M-j>', '<cmd>cnext<CR>zz') -map('n', '<M-k>', '<cmd>cprev<CR>zz') +map('n', '<M-j>', '<cmd>cnext<CR>') +map('n', '<M-k>', '<cmd>cprev<CR>') map('n', '<M-c>', '<cmd>cclose<CR>') --- open up Ex -map('n', '<leader>c', '<cmd>Ex<CR>') +-- man pages +map('n', '<C-k>', '<cmd>Man<CR>') diff --git a/lua/conf/opts.lua b/lua/conf/opts.lua index db75358..5d8a24f 100644 --- a/lua/conf/opts.lua +++ b/lua/conf/opts.lua @@ -1,3 +1,6 @@ +local misc = require('core.misc') +local auto = misc.auto + -- color stuff if vim.fn.has("termguicolors") then vim.opt.termguicolors = true @@ -5,6 +8,10 @@ end vim.opt.laststatus = 3 +-- numbers +vim.opt.number = true +vim.opt.relativenumber = true + -- buffer vim.opt.scrolloff = 5 vim.opt.wrap = true -- wraping lines @@ -21,7 +28,12 @@ vim.opt.tabstop = tabwidth vim.opt.shiftwidth = tabwidth vim.opt.softtabstop = tabwidth -vim.opt.clipboard = 'unnamedplus' -- system clipboard +-- Schedule the setting after `UiEnter` because it can increase startup-time. +-- (yoinked from kickstart.nvim) +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' -- system clipboard +end) + vim.opt.updatetime = 200 -- file saving @@ -50,3 +62,71 @@ vim.g.netrw_winsize = 30 vim.g.netrw_liststyle = 1 vim.g.netrw_sizestyle = "H" vim.g.netrw_hide = 1 + +-- folding +auto("FileType", { + callback = function() + -- support lsp folding + if vim.fn.has("nvim-0.11") then + auto('LspAttach', { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client then + return + end + + if client:supports_method('textDocument/foldingRange') then + local win = vim.api.nvim_get_current_win() + vim.wo[win][0].foldmethod = "expr" + vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()' + end + end, + }) + end + + -- or just rely on treesitter + if require("nvim-treesitter.parsers").has_parser() then + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + else + vim.opt.foldmethod = "syntax" + end + end +}) + +-- lsp folding: vim.o.foldexpr = "v:lua.vim.lsp.foldexpr()" +-- waiting on https://github.com/neovim/neovim/pull/31311 to hit a release +require('core.lsp.functions').add_capabilities({ + textDocument = { + foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true + } + } +}) + +vim.opt.foldlevelstart = 99 +vim.opt.foldlevel = 99 +vim.opt.foldenable = true +vim.o.fillchars = 'fold: ' + +_G.Fold_text = require('core.folding') +vim.opt.foldtext = 'v:lua.Fold_text()' + +-- statusline +function _G.Status() + return table.concat { + "%t", -- file name + " %h", -- help buffer tag + "%m", -- modify tag + "%r", -- readonly flag + "%=", -- seperate left and right side + + -- print out the number of lsp clients attached + "λ"..#vim.lsp.get_clients({ bufnr = 0 }).." ", + + "%l,%c%V", -- line, column-virtual column + " %P" -- percentage through display window + } +end +vim.o.statusline="%!v:lua.Status()" diff --git a/lua/conf/plugins/cmp.lua b/lua/conf/plugins/cmp.lua index ebca929..d6d7766 100644 --- a/lua/conf/plugins/cmp.lua +++ b/lua/conf/plugins/cmp.lua @@ -1,14 +1,22 @@ +local lsp = require('core.lsp.functions') + return { 'hrsh7th/nvim-cmp', requires = { 'nvim-treesitter/nvim-treesitter', - 'lukas-reineke/cmp-under-comparator' -- better results + 'lukas-reineke/cmp-under-comparator', -- better results + 'xzbdmw/colorful-menu.nvim' -- fancy colors }, -- 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', + function() + -- add lsp capabilities + lsp.add_capabilities(require('cmp_nvim_lsp').default_capabilities()) + end + }, -- lsp 'hrsh7th/cmp-nvim-lsp-signature-help', -- completion information { 'L3MON4D3/cmp-luasnip-choice', -- luasnip requires = 'L3MON4D3/LuaSnip' @@ -19,6 +27,7 @@ return { 'hrsh7th/nvim-cmp', local cmp = require('cmp') local luasnip = require('luasnip') + -- setup cmp cmp.setup { -- disable when in comments enabled = function() @@ -44,8 +53,8 @@ return { 'hrsh7th/nvim-cmp', -- how to sort results sorting = { comparators = { - cmp.config.compare.offset, cmp.config.compare.exact, + cmp.config.compare.offset, cmp.config.compare.score, require('cmp-under-comparator').under, cmp.config.compare.kind, @@ -80,16 +89,24 @@ return { 'hrsh7th/nvim-cmp', formatting = { fields = { 'menu', 'abbr', 'kind' }, format = function(entry, item) + local hl_info = require("colorful-menu").cmp_highlights(entry) local menu_icon = { nvim_lsp = 'λ', - nvim_lua = 'v', luasnip = '%', buffer = '@', path = '#', async_path = '#' } + -- add a little icon item.menu = menu_icon[entry.source.name] + + -- add highlights + if hl_info ~= nil then + item.abbr_hl_group = hl_info.highlights + item.abbr = hl_info.text + end + return item end }, @@ -107,25 +124,14 @@ return { 'hrsh7th/nvim-cmp', -- mappings mapping = cmp.mapping.preset.insert { - ["<C-y>"] = cmp.mapping(function() - cmp.confirm({ select = true }) - end, { "i", "c" }), - - ["<C-n>"] = cmp.mapping(function() - if cmp.visible() then - cmp.select_next_item() - end - end), - - ["<C-p>"] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item() - end - end), - + ["<C-y>"] = cmp.mapping.confirm { + select = true + }, + ["<C-n>"] = cmp.mapping.select_next_item(), + ["<C-p>"] = cmp.mapping.select_prev_item(), ["<C-u>"] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(4), - ['<ESC>'] = cmp.mapping.close() + ["<ESC>"] = cmp.mapping.close() } } end diff --git a/lua/conf/plugins/dap-virtual-text.lua b/lua/conf/plugins/dap-virtual-text.lua deleted file mode 100644 index 9225272..0000000 --- a/lua/conf/plugins/dap-virtual-text.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { 'theHamsta/nvim-dap-virtual-text', - requires = { - 'mfussenegger/nvim-dap', - 'nvim-treesitter/nvim-treesitter' - }, - function() - require("nvim-dap-virtual-text").setup {} - end -} diff --git a/lua/conf/plugins/dap.lua b/lua/conf/plugins/dap.lua index fdcd152..5fafd92 100644 --- a/lua/conf/plugins/dap.lua +++ b/lua/conf/plugins/dap.lua @@ -4,9 +4,9 @@ local map = misc.map return { 'mfussenegger/nvim-dap', requires = { 'williamboman/mason.nvim', - 'nvim-telescope/telescope.nvim' + 'nvim-telescope/telescope.nvim', }, - disable = vim.version().minor < 8, + disable = not vim.fn.has("nvim-0.8.0"), branch = '0.8.0', function() @@ -38,10 +38,13 @@ return { 'mfussenegger/nvim-dap', } } - map('n', '<Leader>ec', dap.continue) - map('n', '<Leader>eb', require("dap.breakpoints").toggle) - map('n', '<Leader>e]', dap.step_over) - map('n', '<Leader>e[', dap.step_back) - map('n', '<Leader>eR', dap.restart) + map('n', '<Leader>ec', dap.continue, { desc = "dap continue " }) + map('n', '<Leader>el', dap.run_last, { desc = "dap run last" }) + map('n', '<Leader>et', dap.terminate, { desc = "dap terminate " }) + map('n', '<Leader>eb', require("dap.breakpoints").toggle, { desc = "dap toggle breakpoint" }) + map('n', '<Leader>e]', dap.step_over, { desc = "dap step over" }) + map('n', '<Leader>e[', dap.step_back, { desc = "dap step back" }) + map('n', '<Leader>er', dap.repl.toggle, { desc = "dap repl toggle" }) + map('n', '<Leader>eR', dap.restart, { desc = "dap restart" }) end } diff --git a/lua/conf/plugins/dressing.lua b/lua/conf/plugins/dressing.lua index 36622a6..75e4a44 100644 --- a/lua/conf/plugins/dressing.lua +++ b/lua/conf/plugins/dressing.lua @@ -1,12 +1,12 @@ local branch = nil -if vim.version().minor == 7 then +if vim.fn.has("nvim-0.7.0") then branch = 'nvim-0.7' -elseif vim.version().minor == 5 then +elseif vim.fn.has("nvim-0.5.0") then branch = 'nvim-0.5' end return { 'stevearc/dressing.nvim', - disable = vim.version().minor < 5, + disable = true or not vim.fn.has("nvim-0.5.0"), branch = branch, requires = 'nvim-telescope/telescope.nvim', function() diff --git a/lua/conf/plugins/fidget.lua b/lua/conf/plugins/fidget.lua index 667c905..b4bfbac 100644 --- a/lua/conf/plugins/fidget.lua +++ b/lua/conf/plugins/fidget.lua @@ -1,5 +1,5 @@ return { 'j-hui/fidget.nvim', - disable = vim.version().minor < 9, + disable = not vim.fn.has("nvim-0.9.0"), branch = "v1.5.0", function() local notification_defaults = require("fidget.notification").default_config @@ -16,6 +16,7 @@ return { 'j-hui/fidget.nvim', } }, notification = { + filter = vim.log.levels.DEBUG, override_vim_notify = true, configs = { default = notification_defaults diff --git a/lua/conf/plugins/gitsigns.lua b/lua/conf/plugins/gitsigns.lua index f168b93..a92264e 100644 --- a/lua/conf/plugins/gitsigns.lua +++ b/lua/conf/plugins/gitsigns.lua @@ -2,7 +2,7 @@ local misc = require('core.misc') local map = misc.map return { 'lewis6991/gitsigns.nvim', - disable = vim.version().minor < 9, + disable = not vim.fn.has("nvim-0.9.0"), function() local gs = require("gitsigns") diff --git a/lua/conf/plugins/harpoon.lua b/lua/conf/plugins/harpoon.lua index 9cca238..c26964a 100644 --- a/lua/conf/plugins/harpoon.lua +++ b/lua/conf/plugins/harpoon.lua @@ -2,7 +2,7 @@ local misc = require('core.misc') local map = misc.map return { 'ThePrimeagen/harpoon', - disable = vim.version().minor < 8, + disable = not vim.fn.has("nvim-0.8.0"), commit = 'e76cb03', branch = 'harpoon2', requires = 'nvim-lua/plenary.nvim', diff --git a/lua/conf/plugins/headlines.lua b/lua/conf/plugins/headlines.lua index c932d72..e2dedd6 100644 --- a/lua/conf/plugins/headlines.lua +++ b/lua/conf/plugins/headlines.lua @@ -14,14 +14,7 @@ return { 'lukas-reineke/headlines.nvim', 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" - } + headline_highlights = false } } end diff --git a/lua/conf/plugins/instant.lua b/lua/conf/plugins/instant.lua new file mode 100644 index 0000000..6866e71 --- /dev/null +++ b/lua/conf/plugins/instant.lua @@ -0,0 +1,5 @@ +return { 'jbyuki/instant.nvim', + function() + vim.g.instant_username = "squibid" + end +} diff --git a/lua/conf/plugins/jdtls.lua b/lua/conf/plugins/jdtls.lua index c847e5a..b6dbd72 100644 --- a/lua/conf/plugins/jdtls.lua +++ b/lua/conf/plugins/jdtls.lua @@ -3,7 +3,7 @@ local lsp = require('core.lsp.functions') local map, auto = misc.map, misc.auto return { 'mfussenegger/nvim-jdtls', - disable = vim.version().minor < 6, + disable = not vim.fn.has("nvim-0.6.0"), requires = 'mfussenegger/nvim-dap', function() auto("FileType", { @@ -34,7 +34,10 @@ return { 'mfussenegger/nvim-jdtls', 'gradlew', '.git', 'mvnw', - 'build.xml' + 'settings.gradle', -- Gradle (multi-project) + 'settings.gradle.kts', -- Gradle (multi-project) + 'build.xml', -- Ant + 'pom.xml', -- Maven }, { upward = true })[1]), -- don't print out status messages @@ -42,10 +45,7 @@ return { 'mfussenegger/nvim-jdtls', ['language/status'] = function() end }, - capabilities = lsp.capabilities(), - on_attach = function(client, bufnr) - lsp.attach(client, bufnr) - + on_attach = function(_, bufnr) -- add some jdtls specific mappings local opts = { buffer = bufnr } map('n', 'cri', jdtls.organize_imports, opts) @@ -64,8 +64,10 @@ return { 'mfussenegger/nvim-jdtls', end }) end, + capabilities = lsp.capabilities } + -- generate the path to the java file(s) ---@type string|nil local cache_path = vim.fs.joinpath(vim.fn.stdpath("cache"), "/JavaVersion.class") ---@type string|nil diff --git a/lua/conf/plugins/leetcode.lua b/lua/conf/plugins/leetcode.lua index bda7c08..7619c84 100644 --- a/lua/conf/plugins/leetcode.lua +++ b/lua/conf/plugins/leetcode.lua @@ -7,7 +7,7 @@ return { 'kawre/leetcode.nvim', }, config = function() -- because we're using treesitter make sure to install the html parser - vim.cmd.TSUpdate("html") + vim.cmd("TSUpdate html") end, function() require('leetcode').setup { diff --git a/lua/conf/plugins/lsp_lines.lua b/lua/conf/plugins/lsp_lines.lua index e28aec8..9ccaa73 100644 --- a/lua/conf/plugins/lsp_lines.lua +++ b/lua/conf/plugins/lsp_lines.lua @@ -1,3 +1,4 @@ return { 'whynothugo/lsp_lines', - url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim' + url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim', + disable = not vim.fn.has("nvim-0.8.0") } diff --git a/lua/conf/plugins/luasnip.lua b/lua/conf/plugins/luasnip.lua index d881a57..169ec5d 100644 --- a/lua/conf/plugins/luasnip.lua +++ b/lua/conf/plugins/luasnip.lua @@ -3,9 +3,9 @@ local map = misc.map return { 'L3MON4D3/LuaSnip', branch = 'v2.3.0', - disable = vim.version().minor < 7, + disable = not vim.fn.has("nvim-0.7.0"), config = function() - vim.cmd.make('install_jsregexp') + vim.cmd('make install_jsregexp') end, function() local luasnip = require('luasnip') diff --git a/lua/conf/plugins/mason-lspconfig.lua b/lua/conf/plugins/mason-lspconfig.lua index 65c5693..ceedb6c 100644 --- a/lua/conf/plugins/mason-lspconfig.lua +++ b/lua/conf/plugins/mason-lspconfig.lua @@ -1,18 +1,23 @@ local misc = require('core.misc') local lsp = require('core.lsp.functions') -local map, auto, augroup = misc.map, misc.auto, misc.augroup +local map = misc.map return { 'williamboman/mason-lspconfig.nvim', requires = { 'williamboman/mason.nvim', { 'neovim/nvim-lspconfig', - disable = vim.version().minor < 8, + disable = not vim.fn.has("nvim-0.8.0"), function() lsp.setup() end - } + }, + + -- these two update some lsp capabilities and therefore must be run first + -- 'hrsh7th/cmp-nvim-lsp', + -- 'kevinhwang91/nvim-ufo' }, function() + local lspconfig = require('lspconfig') local util = require('lspconfig.util') -- setup language servers @@ -27,97 +32,105 @@ return { 'williamboman/mason-lspconfig.nvim', "bashls", "zls" -- "asm-lsp", -- seems to be broken - } - } - require('mason-lspconfig').setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - on_attach = lsp.lsp_attach, - capabilities = lsp.capabilities() - } - end, + }, + + -- setup all handlers + handlers = { + function(server_name) + lspconfig[server_name].setup {} + 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' - } + -- 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: luals 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, - capabilities = lsp.capabilities(), - settings = { - Lua = { - diagnostics = { - globals = { "vim", 'mp' } - }, - runtime = { - version = 'LuaJIT' - }, - format = { - enable = false - }, - workspace = { - checkThirdParty = false, - library = { - vim.env.VIMRUNTIME + -- FIXME: luals seems to start up twice and sends back twice the + -- completions (one configured with the below settings and one without) + lspconfig[server_name].setup { + 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_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 + root = util.root_pattern('lua/')(fname) + if root then + return root + end + return util.find_git_ancestor(fname) 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) + } + end, - -- add some clangd specific mappings - local opts = { buffer = bufnr } - map("n", "<leader>o", "<cmd>ClangdSwitchSourceHeader<CR>", opts) - end, - capabilities = lsp.capabilities(), + -- setup clangd + ["clangd"] = function(server_name) + lspconfig[server_name].setup { + on_attach = function(client, bufnr) + -- add some clangd specific mappings + local opts = { buffer = bufnr } + map("n", "<leader>o", "<cmd>ClangdSwitchSourceHeader<CR>", opts) + end, - 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++ + 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, + end, - -- disable it, we start this using nvim-jdtls - ["jdtls"] = function(_) end - } + -- disable it, we start this using nvim-jdtls + ["jdtls"] = function(_) end, + -- setup basedpyright + ["basedpyright"] = function(server_name) + lspconfig[server_name].setup { + on_attach = function(client, bufnr) + -- add some basedpyright specific mappings + local opts = { buffer = bufnr } + map("n", "cri", "<cmd>PyrightOrganizeImports<CR>", opts) + end, + } + end + }, + + ["openscad_lsp"] = function(server_name) + lspconfig[server_name].setup {} + end + } end } diff --git a/lua/conf/plugins/mason.lua b/lua/conf/plugins/mason.lua index b3eeacf..87e66a9 100644 --- a/lua/conf/plugins/mason.lua +++ b/lua/conf/plugins/mason.lua @@ -1,5 +1,5 @@ return { 'williamboman/mason.nvim', - disable = vim.version().minor < 7, + disable = not vim.fn.has("nvim-0.7.0"), function() local mason = require('mason') diff --git a/lua/conf/plugins/mellow.lua b/lua/conf/plugins/mellow.lua index 11103ae..02bf7fd 100644 --- a/lua/conf/plugins/mellow.lua +++ b/lua/conf/plugins/mellow.lua @@ -1,5 +1,5 @@ return { 'mellow-theme/mellow.nvim', - disable = vim.version().minor < 8, + disable = not vim.fn.has("nvim-0.8.0"), requires = 'nvim-treesitter/nvim-treesitter', function() vim.g.mellow_variant = "dark" diff --git a/lua/conf/plugins/mini-clue.lua b/lua/conf/plugins/mini-clue.lua new file mode 100644 index 0000000..e2c3fa0 --- /dev/null +++ b/lua/conf/plugins/mini-clue.lua @@ -0,0 +1,52 @@ +return { 'echasnovski/mini.clue', + disable = true, + -- disable = not vim.fn.has("nvim-0.9.0"), + branch = "stable", + function() + local miniclue = require('mini.clue') + miniclue.setup({ + triggers = { + -- Leader triggers + { mode = 'n', keys = '<Leader>' }, + { mode = 'x', keys = '<Leader>' }, + + -- Built-in completion + { mode = 'i', keys = '<C-x>' }, + + -- `g` key + { mode = 'n', keys = 'g' }, + { mode = 'x', keys = 'g' }, + + -- Marks + { mode = 'n', keys = "'" }, + { mode = 'n', keys = '`' }, + { mode = 'x', keys = "'" }, + { mode = 'x', keys = '`' }, + + -- Registers + { mode = 'n', keys = '"' }, + { mode = 'x', keys = '"' }, + { mode = 'i', keys = '<C-r>' }, + { mode = 'c', keys = '<C-r>' }, + + -- Window commands + { mode = 'n', keys = '<C-w>' }, + + -- `z` key + { mode = 'n', keys = 'z' }, + { mode = 'x', keys = 'z' }, + }, + + clues = { + -- Enhance this by adding descriptions for <Leader> mapping groups + miniclue.gen_clues.builtin_completion(), + miniclue.gen_clues.g(), + miniclue.gen_clues.marks(), + miniclue.gen_clues.registers(), + miniclue.gen_clues.windows(), + miniclue.gen_clues.z(), + }, + }) + + end +} diff --git a/lua/conf/plugins/neorg.lua b/lua/conf/plugins/neorg.lua index f0fec2f..84a0b79 100644 --- a/lua/conf/plugins/neorg.lua +++ b/lua/conf/plugins/neorg.lua @@ -8,7 +8,12 @@ -- 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") +local workspace_cache +if not vim.fs then + workspace_cache = vim.fn.stdpath("data").."/neorg-workspace-cache.lua" +else + workspace_cache = vim.fs.joinpath(vim.fn.stdpath("data"), "neorg-workspace-cache.lua") +end --- populate neorg workspaces from path or cache ---@param path string path to populate workspaces from @@ -57,8 +62,8 @@ local function populate_workspaces(path, cache) end return { 'nvim-neorg/neorg', - disable = vim.version.lt(vim.version(), { 0, 10, 0 }), - branch = 'v9.1.1', + disable = not vim.fn.has("nvim-0.10.0"), + branch = 'v9.3.0', requires = { 'nvim-lua/plenary.nvim', 'nvim-treesitter/nvim-treesitter', @@ -69,7 +74,8 @@ return { 'nvim-neorg/neorg', }, -- 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 + -- were picked based on the neorg-scm-1.rockspec found in the root of the + -- neorg repo { 'nvim-neotest/nvim-nio', branch = 'v1.7.0' }, diff --git a/lua/conf/plugins/nvim-colorizer.lua b/lua/conf/plugins/nvim-colorizer.lua index 91cffd1..91fac13 100644 --- a/lua/conf/plugins/nvim-colorizer.lua +++ b/lua/conf/plugins/nvim-colorizer.lua @@ -1,5 +1,5 @@ return { 'norcalli/nvim-colorizer.lua', - disable = vim.version().minor < 4 and not vim.fn.has("termguicolors"), + disable = not vim.fn.has("nvim-0.4.0") and not vim.fn.has("termguicolors"), function() require('colorizer').setup(nil, { names = false, diff --git a/lua/conf/plugins/nyooom.lua b/lua/conf/plugins/nyooom.lua new file mode 100644 index 0000000..c6da17a --- /dev/null +++ b/lua/conf/plugins/nyooom.lua @@ -0,0 +1,7 @@ +return { 'squibid/nyooom', + url = 'https://git.squi.bid/nyooom', + pin = true, + function() + require('nyooom').setup {} + end +} diff --git a/lua/conf/plugins/oil.lua b/lua/conf/plugins/oil.lua new file mode 100644 index 0000000..5eeac4d --- /dev/null +++ b/lua/conf/plugins/oil.lua @@ -0,0 +1,160 @@ +local misc = require('core.misc') +local map = misc.map + +local permission_hlgroups = { + ['-'] = 'NonText', + ['r'] = 'DiagnosticSignWarn', + ['w'] = 'DiagnosticSignHint', + ['x'] = 'DiagnosticSignOk', +} + +return { 'stevearc/oil.nvim', + disable = not vim.fn.has("nvim-0.8.0"), + function() + require("oil").setup { + -- ID is automatically added at the beginning, and name at the end + -- See :help oil-columns + columns = { + { + "permissions", + highlight = function(permission_str) + local hls = {} + for i = 1, #permission_str do + local char = permission_str:sub(i, i) + table.insert(hls, { permission_hlgroups[char], i - 1, i }) + end + return hls + end, + }, + { "size", highlight = '@number' } + }, + + -- Window-local options to use for oil buffers + win_options = { + number = false, + relativenumber = false, + wrap = false, + signcolumn = "no", + cursorcolumn = false, + foldcolumn = "0", + spell = false, + list = false, + conceallevel = 3, + concealcursor = "nvic" + }, + + -- Send deleted files to the trash instead of permanently deleting them (:help oil-trash) + delete_to_trash = false, + + -- Skip the confirmation popup for simple operations (:help oil.skip_confirm_for_simple_edits) + skip_confirm_for_simple_edits = false, + + -- Selecting a new/moved/renamed file or directory will prompt you to save changes first + -- (:help prompt_save_on_select_new_entry) + prompt_save_on_select_new_entry = true, + + -- Oil will automatically delete hidden buffers after this delay + -- You can set the delay to false to disable cleanup entirely + -- Note that the cleanup process only starts when none of the oil buffers are currently displayed + cleanup_delay_ms = 2000, + lsp_file_methods = { + -- Enable or disable LSP file operations + enabled = true, + -- Time to wait for LSP file operations to complete before skipping + timeout_ms = 1000, + -- Set to true to autosave buffers that are updated with LSP willRenameFiles + -- Set to "unmodified" to only save unmodified buffers + autosave_changes = "unmodified" + }, + + -- Constrain the cursor to the editable parts of the oil buffer + -- Set to `false` to disable, or "name" to keep it on the file names + constrain_cursor = "editable", + + -- Set to true to watch the filesystem for changes and reload oil + watch_for_changes = false, + + -- Keymaps in oil buffer. Can be any value that `vim.keymap.set` accepts OR a table of keymap + -- options with a `callback` (e.g. { callback = function() ... end, desc = "", mode = "n" }) + -- Additionally, if it is a string that matches "actions.<name>", + -- it will use the mapping at require("oil.actions").<name> + -- Set to `false` to remove a keymap + -- See :help oil-actions for a list of all available actions + keymaps = { + ["g?"] = { "actions.show_help", mode = "n" }, + ["<C-l>"] = "actions.refresh", + ["<CR>"] = "actions.select", + ["-"] = { "actions.parent", mode = "n" }, + ["_"] = { "actions.open_cwd", mode = "n" }, + ["`"] = { "actions.cd", mode = "n" }, + ["~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" }, + ["gs"] = { "actions.change_sort", mode = "n" }, + ["gx"] = "actions.open_external", + ["g."] = { "actions.toggle_hidden", mode = "n" }, + ["g\\"] = { "actions.toggle_trash", mode = "n" } + }, + + view_options = { + -- Show files and directories that start with "." + show_hidden = false, + + -- This function defines what is considered a "hidden" file + is_hidden_file = function(name, bufnr) + if name == ".." then -- show previous directory + return false + end + local m = name:match("^%.") + return m ~= nil + end, + + -- This function defines what will never be shown, even when `show_hidden` is set + is_always_hidden = function(name, bufnr) + return false + end, + + -- Sort file names with numbers in a more intuitive order for humans. + -- Can be "fast", true, or false. "fast" will turn it off for large directories. + natural_order = "fast", + + -- Sort file and directory names case insensitive + case_insensitive = false, + + sort = { + -- sort order can be "asc" or "desc" + -- see :help oil-columns to see which columns are sortable + { "type", "asc" }, + { "name", "asc" }, + }, + + -- Customize the highlight group for the file name + highlight_filename = function(entry, is_hidden, is_link_target, is_link_orphan) + return nil + end, + }, + + -- Configuration for the floating window in oil.open_float + float = { + border = "solid" + }, + + -- Configuration for the floating action confirmation window + confirmation = { + border = "solid" + }, + -- Configuration for the floating progress window + progress = { + border = "solid" + }, + -- Configuration for the floating SSH window + ssh = { + border = "solid" + }, + -- Configuration for the floating keymaps help window + keymaps_help = { + border = "solid" + } + } + + map('n', '-', '<cmd>Oil<CR>') + end +} diff --git a/lua/conf/plugins/project.lua b/lua/conf/plugins/project.lua index 5ef820b..1075e4c 100644 --- a/lua/conf/plugins/project.lua +++ b/lua/conf/plugins/project.lua @@ -1,5 +1,6 @@ return { 'ahmedkhalf/project.nvim', - disable = vim.version().minor < 5, + disable = true, + -- disable = vim.fn.has("nvim-0.5.0"), function() require('project_nvim').setup { patterns = { diff --git a/lua/conf/plugins/smear.lua b/lua/conf/plugins/smear.lua deleted file mode 100644 index 4e0e051..0000000 --- a/lua/conf/plugins/smear.lua +++ /dev/null @@ -1,13 +0,0 @@ --- yea it's a bit flashy, but it's genuenly useful to be able to tell where my --- cursor has gone -return { 'sphamba/smear-cursor.nvim', - disable = vim.version.lt(vim.version(), { 0, 10, 2 }) or vim.g.neovide_version, - function() - require('smear_cursor').setup { - stiffness = 0.8, -- 0.6 [0, 1] - trailing_stiffness = 0.5, -- 0.3 [0, 1] - distance_stop_animating = 0.5, -- 0.1 > 0 - hide_target_hack = false -- true boolean - } - end -} diff --git a/lua/conf/plugins/telescope.lua b/lua/conf/plugins/telescope.lua index 597fbe3..b08d65d 100644 --- a/lua/conf/plugins/telescope.lua +++ b/lua/conf/plugins/telescope.lua @@ -2,12 +2,12 @@ local misc = require('core.misc') local map = misc.map return { 'nvim-telescope/telescope.nvim', - disable = vim.version().minor < 9, + disable = not vim.fn.has("nvim-0.9.0"), requires = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', config = function() - vim.cmd.make() + vim.cmd("make") end } }, @@ -48,14 +48,8 @@ return { 'nvim-telescope/telescope.nvim', ["<esc>"] = actions.close, ['<C-j>'] = actions.move_selection_next, ['<C-k>'] = actions.move_selection_previous, - ['<C-l>'] = actions.select_default, ['<C-u>'] = actions.preview_scrolling_up, ['<C-d>'] = actions.preview_scrolling_down, - ["<C-p>"] = action_layout.toggle_preview - }, - n = { - ["gg"] = actions.move_to_top, - ["G"] = actions.move_to_bottom, } } }, @@ -77,7 +71,7 @@ return { 'nvim-telescope/telescope.nvim', desc = 'Find string in current buffer.', }) map('n', '<leader>i', telebuilt.help_tags, { - desc = 'Fuzzy find over help tags.', + desc = 'find help tags.', }) -- find over specific directories @@ -85,12 +79,12 @@ return { 'nvim-telescope/telescope.nvim', require('telescope.builtin').find_files { cwd = vim.fn.stdpath("config") } - end, { desc = "Fuzzy find over files in my config" }) + end, { desc = "find config files" }) map('n', '<leader>tp', function() require('telescope.builtin').find_files { cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "site/pack/deps/opt") } - end, { desc = "Fuzzy find over files in my plugin directory" }) + end, { desc = "find files in plugin directory" }) -- enable previewing in the default colorscheme switcher telebuilt.colorscheme = function() diff --git a/lua/conf/plugins/todo-comments.lua b/lua/conf/plugins/todo-comments.lua index 55ebd32..ebf724d 100644 --- a/lua/conf/plugins/todo-comments.lua +++ b/lua/conf/plugins/todo-comments.lua @@ -1,11 +1,6 @@ -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, + disable = not vim.fn.has("nvim-0.8.0"), function() require('todo-comments').setup { keywords = { diff --git a/lua/conf/plugins/treesitter.lua b/lua/conf/plugins/treesitter.lua index 4f010d9..b18ae49 100644 --- a/lua/conf/plugins/treesitter.lua +++ b/lua/conf/plugins/treesitter.lua @@ -8,9 +8,9 @@ table.contains = function(self, string) end return { 'nvim-treesitter/nvim-treesitter', - disable = vim.version().minor < 10, + disable = not vim.fn.has("nvim-0.10.0"), config = function() - vim.cmd.TSUpdate() + vim.cmd("TSUpdate") end, function() require('nvim-treesitter.configs').setup { diff --git a/lua/conf/plugins/treesj.lua b/lua/conf/plugins/treesj.lua index 8ec65d4..4b3bae1 100644 --- a/lua/conf/plugins/treesj.lua +++ b/lua/conf/plugins/treesj.lua @@ -2,7 +2,7 @@ local misc = require('core.misc') local map = misc.map return { 'Wansmer/treesj', - disable = vim.version().minor < 9, + disable = not vim.fn.has("nvim-0.9.0"), requires = 'nvim-treesitter/nvim-treesitter', function() require('treesj').setup { diff --git a/lua/conf/plugins/ts-autotag.lua b/lua/conf/plugins/ts-autotag.lua index 001dd0a..915ddad 100644 --- a/lua/conf/plugins/ts-autotag.lua +++ b/lua/conf/plugins/ts-autotag.lua @@ -1,6 +1,9 @@ return { 'windwp/nvim-ts-autotag', - requires = 'nvim-telescope/telescope.nvim', - disable = vim.version.lt(vim.version(), { 0, 9, 5 }), + requires = { + 'nvim-telescope/telescope.nvim', + 'nvim-treesitter/nvim-treesitter' + }, + disable = not vim.fn.has("nvim-0.9.5"), function() require('nvim-ts-autotag').setup {} diff --git a/lua/core/folding.lua b/lua/core/folding.lua new file mode 100644 index 0000000..37b5d78 --- /dev/null +++ b/lua/core/folding.lua @@ -0,0 +1,120 @@ +--- Stolen from: https://github.com/Wansmer/nvim-config/blob/main/lua/modules/foldtext.lua +--- modified for my use +--- +---@module Foldtext +---Based on https://www.reddit.com/r/neovim/comments/16sqyjz/finally_we_can_have_highlighted_folds/ +---Updated with vim.treesitter._fold.foldtext() + + +local function parse_line(linenr) + local bufnr = vim.api.nvim_get_current_buf() + + local line = vim.api.nvim_buf_get_lines(bufnr, linenr - 1, linenr, false)[1] + if not line then + return nil + end + + local ok, parser = pcall(vim.treesitter.get_parser, bufnr) + if not ok then + return nil + end + + local query = vim.treesitter.query.get(parser:lang(), "highlights") + if not query then + return nil + end + + local tree = parser:parse({ linenr - 1, linenr })[1] + local result = {} + local line_pos = 0 + + for id, node, metadata in query:iter_captures(tree:root(), 0, linenr - 1, linenr) do + local name = query.captures[id] + local start_row, start_col, end_row, end_col = node:range() + + local priority = tonumber(metadata.priority or vim.highlight.priorities.treesitter) + + if start_row == linenr - 1 and end_row == linenr - 1 then + -- check for characters ignored by treesitter + if start_col > line_pos then + table.insert(result, { + line:sub(line_pos + 1, start_col), + { { "Folded", priority } }, + range = { line_pos, start_col }, + }) + end + line_pos = end_col + + local text = line:sub(start_col + 1, end_col) + table.insert(result, { text, { { "@" .. name, priority } }, range = { start_col, end_col } }) + end + end + + local i = 1 + while i <= #result do + -- find first capture that is not in current range and apply highlights on the way + local j = i + 1 + while j <= #result and result[j].range[1] >= result[i].range[1] and result[j].range[2] <= result[i].range[2] do + for k, v in ipairs(result[i][2]) do + if not vim.tbl_contains(result[j][2], v) then + table.insert(result[j][2], k, v) + end + end + j = j + 1 + end + + -- remove the parent capture if it is split into children + if j > i + 1 then + table.remove(result, i) + else + -- highlights need to be sorted by priority, on equal prio, the deeper nested capture (earlier + -- in list) should be considered higher prio + if #result[i][2] > 1 then + table.sort(result[i][2], function(a, b) + return a[2] < b[2] + end) + end + + result[i][2] = vim.tbl_map(function(tbl) + return tbl[1] + end, result[i][2]) + result[i] = { result[i][1], result[i][2] } + + i = i + 1 + end + end + + return result +end + +--- create a string of highlighted text for folds +---@return table|string +local function HighlightedFoldtext() + local result = parse_line(vim.v.foldstart) + if not result then + return vim.fn.foldtext() + end + + table.insert(result, { + " ... ", + "LspCodeLens", + }) + + local result2 = parse_line(vim.v.foldend) + if result2 then + local first = result2[1] + result2[1] = { vim.trim(first[1]), first[2] } + for _, item in ipairs(result2) do + table.insert(result, item) + end + end + + table.insert(result, { + " "..(vim.v.foldend - vim.v.foldstart + 1).." Lines Folded ", + "LspCodeLens", + }) + + return result +end + +return HighlightedFoldtext diff --git a/lua/core/lsp/functions.lua b/lua/core/lsp/functions.lua index ab47ccc..4c27bca 100644 --- a/lua/core/lsp/functions.lua +++ b/lua/core/lsp/functions.lua @@ -1,90 +1,115 @@ local misc = require('core.misc') -local map = misc.map +local map, include = misc.map, misc.include local M = {} -function M.setup() - vim.diagnostic.config { - virtual_text = false, - virtual_lines = { - only_current_line = true, - }, - 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' }) - - for _, v in pairs({ - { "DiagnosticSignError", "x" }, - { "DiagnosticSignWarn", "!" }, - { "DiagnosticSignInfo", "i" }, - { "DiagnosticSignHint", "h" } - }) do - vim.fn.sign_define(v[1], { text = v[2], texthl = v[1] }) +local function on_list(options) + vim.fn.setqflist({}, 'r', options) + if #options.items > 1 then + vim.cmd.copen() end + vim.cmd("cc! 1") end ---- generate client capabilities for lsp servers ----@return table capabilities -function M.capabilities() - local capabilities = vim.lsp.protocol.make_client_capabilities() - capabilities.textDocument.completion.completionItem = { - snippetSupport = true, - preselectSupport = true, - insertReplaceSupport = true, - labelDetailsSupport = true, - deprecatedSupport = true, - commitCharactersSupport = true, - tagSupport = { - valueSet = { 1 } - }, - resolveSupport = { - properties = { - "documentation", - "detail", - "additionalTextEdits" - } - } - } - - return capabilities +local function _w(func) + return function() + func({ + border = "solid", + max_width = math.floor(vim.o.columns * 0.7), + }, { on_list = on_list }) + end end --- setup basic options on lsp attach ----@param client number client number ---@param bufnr number buffer number -function M.attach(client, bufnr) - local opts = { buffer = bufnr } +local function attach(bufnr) + local opts = { buffer = bufnr, nowait = true } + -- LSP actions - map('n', 'K', vim.lsp.buf.hover, opts) - map('n', 'gd', vim.lsp.buf.definition, opts) - map('n', 'gD', 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', '<S-Tab>', vim.lsp.buf.signature_help, opts) - map('n', '<leader>r', vim.lsp.buf.rename, opts) - map('n', '<F2>', vim.lsp.buf.rename, opts) - map('n', 'gA', vim.lsp.buf.code_action, { + map('n', 'K', _w(vim.lsp.buf.hover), opts) + map('n', 'gd', _w(vim.lsp.buf.definition), opts) + map('n', 'gD', _w(vim.lsp.buf.declaration), opts) + map('n', 'gi', _w(vim.lsp.buf.implementation), opts) + map('n', 'gy', _w(vim.lsp.buf.type_definition), opts) + map('n', 'gr', _w(vim.lsp.buf.references), opts) + map('n', '<S-Tab>', _w(vim.lsp.buf.signature_help), opts) + map('n', { '<leader>r', '<F2>' }, _w(vim.lsp.buf.rename), opts) + map('n', 'gA', _w(vim.lsp.buf.code_action), { buffer = bufnr, desc = 'check code actions', }) - map('n', '<F4>', vim.lsp.buf.code_action, { + map('n', '<F4>', _w(vim.lsp.buf.code_action), { buffer = bufnr, desc = 'check code actions' }) -- Diagnostics - map('n', '[d', vim.diagnostic.goto_prev, opts) - map('n', ']d', vim.diagnostic.goto_next, opts) + map('n', '[d', function() + if not vim.fn.has("nvim-0.11") then + vim.diagnostic.goto_prev() + else + vim.diagnostic.jump({ count = -1 }) + end + end, opts) + map('n', ']d', function() + if not vim.fn.has("nvim-0.11") then + vim.diagnostic.goto_next() + else + vim.diagnostic.jump({ count = 1 }) + end + end, opts) -- map('n', 'qD', vim.diagnostic.setqflist, opts) end +function M.setup() + vim.diagnostic.config { + virtual_text = false, + virtual_lines = { + only_current_line = true, + }, + update_in_insert = false, + underline = true, + severity_sort = true, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "x", + [vim.diagnostic.severity.WARN] = "!", + [vim.diagnostic.severity.INFO] = "i", + [vim.diagnostic.severity.HINT] = "h", + } + } + } + + if not vim.fn.has("nvim-0.11") then + 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 + + -- set default capabilities + include('lspconfig.util').default_config.capabilities = M.capabilities + + -- run whenever a client attaches + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(event) + -- map keybinds + attach(event.buf) + end + }) +end + +--- capabilities that are to be used in lsp servers, for those setup through +--- lspconfig, this is already set as the default. Incase there is a server +--- not setup through lspconfig this function may be called to receive the +--- proper capabilities data. +M.capabilities = vim.lsp.protocol.make_client_capabilities() + +--- add capabilities to the default capabilities string +---@param new_capabilities lsp.ClientCapabilities +function M.add_capabilities(new_capabilities) + vim.tbl_deep_extend('force', M.capabilities, new_capabilities) +end + return M diff --git a/lua/core/misc.lua b/lua/core/misc.lua index 5200c8b..5d0c0cf 100644 --- a/lua/core/misc.lua +++ b/lua/core/misc.lua @@ -29,10 +29,19 @@ end --- set colorscheme ---@param name string name of colorscheme function M.colorscheme(name) - vim.cmd.colorscheme(name) + -- only set the colorscheme if it exists + for _, v in pairs(vim.fn.getcompletion('', 'color')) do + if v == name then + vim.cmd("colorscheme "..name) + break + end + end + + -- override with any addons for _, v in pairs(vim.fn.getcompletion('', 'color')) do if v == name..'.ext' then - vim.cmd.colorscheme(name..'.ext') + vim.cmd("colorscheme"..name..'.ext') + break end end end @@ -41,12 +50,24 @@ end ---@param mode string|table mode for the keymap ---@param bind string|table keymap ---@param cmd function|string command to run ----@param opts table? keymap options +---@param opts vim.keymap.set.Opts? keymap options function M.map(mode, bind, cmd, opts) opts = opts or {} opts['noremap'] = true opts['silent'] = true + -- attempt to autogenerate a basic description + if not opts['desc'] then + if type(cmd) == "string" then + opts['desc'] = cmd:gsub("<%a+>", "") + elseif type(cmd) == "function" then + -- TODO: find a way to generate a better name + local file_name = vim.fn.fnamemodify(debug.getinfo(cmd, "S").short_src, ":t") + opts['desc'] = "origin@"..file_name + end + end + + -- define the keybinds if type(bind) == 'table' then for i in pairs(bind) do vim.keymap.set(mode, bind[i], cmd, opts) @@ -69,7 +90,7 @@ end --- extend vim.api.nvim_create_autocmd ---@param event string|table event or events ----@param opts table options +---@param opts vim.api.keyset.create_autocmd options function M.auto(event, opts) vim.api.nvim_create_autocmd(event, opts) end @@ -161,24 +182,29 @@ function M.timeout_highlight(opts) -- timer code was happily stolen from neovim/runtime/lua/vim/highlight.lua :) local timer, timer_cancel - - if timer then - timer:close() - assert(timer_cancel) - timer_cancel() + if not vim.fn.has("nvim-0.11") then + if timer then + timer:close() + assert(timer_cancel) + timer_cancel() + end end -- set the highlight - vim.highlight.range(0, namespaceid, opts.hl, opts.range[1], opts.range[2], {}) + vim.highlight.range(0, namespaceid, opts.hl, opts.range[1], opts.range[2], { + opts.timeout, + }) - timer_cancel = function() - timer = nil - timer_cancel = nil - pcall(vim.api.nvim_buf_clear_namespace, 0, namespaceid, 0, -1) - pcall(vim.api.nvim_win_remove_ns, 0, namespaceid) - end + if not vim.fn.has("nvim-0.11") then + timer_cancel = function() + timer = nil + timer_cancel = nil + pcall(vim.api.nvim_buf_clear_namespace, 0, namespaceid, 0, -1) + pcall(vim.api.nvim_win_remove_ns, 0, namespaceid) + end - timer = vim.defer_fn(timer_cancel, opts.timeout) + timer = vim.defer_fn(timer_cancel, opts.timeout) + end end return M |