diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-09-09 20:48:47 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-09-09 20:48:47 +0200 |
commit | 81b5ea969f26c520c4da9248d5e6d9b6a32b709c (patch) | |
tree | 3a86af02c5dc80cb82c296aa72614131f04905b0 /.config/nvim | |
parent | 6a1732982287ef5aff2a6de171192b9e2bb90758 (diff) |
Change compe to cmp package
Diffstat (limited to '.config/nvim')
-rw-r--r-- | .config/nvim/config.lua | 1 | ||||
-rw-r--r-- | .config/nvim/lua/config/defaults.lua | 50 | ||||
-rw-r--r-- | .config/nvim/lua/core/autopairs.lua | 52 | ||||
-rw-r--r-- | .config/nvim/lua/core/builtins/init.lua | 2 | ||||
-rw-r--r-- | .config/nvim/lua/core/cmp.lua | 123 | ||||
-rw-r--r-- | .config/nvim/lua/core/compe.lua | 145 | ||||
-rw-r--r-- | .config/nvim/lua/core/lualine/components.lua | 3 | ||||
-rw-r--r-- | .config/nvim/lua/impatient.lua | 348 | ||||
-rw-r--r-- | .config/nvim/lua/impatient/cachepack.lua | 0 | ||||
-rw-r--r-- | .config/nvim/lua/impatient/profile.lua | 156 | ||||
-rw-r--r-- | .config/nvim/lua/lsp/handlers.lua | 77 | ||||
-rw-r--r-- | .config/nvim/lua/plugins.lua | 28 |
12 files changed, 746 insertions, 239 deletions
diff --git a/.config/nvim/config.lua b/.config/nvim/config.lua index b0582f0..e5186e3 100644 --- a/.config/nvim/config.lua +++ b/.config/nvim/config.lua @@ -13,7 +13,6 @@ options.lsp.diagnostics.virtual_text = false -- require("extra.json_schemas").setup() -- After changing plugin config it is recommended to run :PackerCompile -options.builtin.compe.active = true options.builtin.autopairs.active = true options.builtin.dashboard.active = true options.builtin.terminal.active = true diff --git a/.config/nvim/lua/config/defaults.lua b/.config/nvim/lua/config/defaults.lua index f62fd87..bcadef3 100644 --- a/.config/nvim/lua/config/defaults.lua +++ b/.config/nvim/lua/config/defaults.lua @@ -38,31 +38,31 @@ options = { lsp = { completion = { item_kind = { - " (text) ", - " (method)", - " (function)", - " (constructor)", - " ﴲ (field)", - "[] (variable)", - " (class)", - " ﰮ (interface)", - " (module)", - " 襁 (property)", - " (unit)", - " (value)", - " 練 (enum)", - " (keyword)", - " (snippet)", - " (color)", - " (file)", - " (reference)", - " (folder)", - " (enummember)", - " ﲀ (constant)", - " ﳤ (struct)", - " (event)", - " (operator)", - " (typeparameter)", + " (Text) ", + " (Method)", + " (Function)", + " (Constructor)", + " (Field)", + " (Variable)", + " (Class)", + " ﰮ (Interface)", + " (Module)", + " (Property)", + " 塞 (Unit)", + " (Value)", + " 練 (Enum)", + " (Keyword)", + " (Snippet)", + " (Color)", + " (File)", + " (Reference)", + " (Folder)", + " (EnumMember)", + " ﲀ (Constant)", + " (Struct)", + " (Event)", + " (Operator)", + " (TypeParameter)", }, }, diagnostics = { diff --git a/.config/nvim/lua/core/autopairs.lua b/.config/nvim/lua/core/autopairs.lua index f8bdfd1..8ea3094 100644 --- a/.config/nvim/lua/core/autopairs.lua +++ b/.config/nvim/lua/core/autopairs.lua @@ -20,36 +20,44 @@ function M.config() end M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} local autopairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" - - vim.g.completion_confirm_key = "" - MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](autopairs.esc "<cr>") - else - return autopairs.esc "<cr>" - end - else - return autopairs.autopairs_cr() - end - end - - if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = options.builtin.autopairs.map_cr, - map_complete = options.builtin.autopairs.map_complete, - } - end + local cond = require "nvim-autopairs.conds" autopairs.setup { check_ts = options.builtin.autopairs.check_ts, ts_config = options.builtin.autopairs.ts_config, } + -- vim.g.completion_confirm_key = "" + + autopairs.add_rule(Rule("$$", "$$", "tex")) + autopairs.add_rules { + Rule("$", "$", { "tex", "latex" }) -- don't add a pair if the next character is % + :with_pair(cond.not_after_regex_check "%%") -- don't add a pair if the previous character is xxx + :with_pair(cond.not_before_regex_check("xxx", 3)) -- don't move right when repeat character + :with_move(cond.none()) -- don't delete if the next character is xx + :with_del(cond.not_after_regex_check "xx") -- disable add newline when press <cr> + :with_cr(cond.none()), + } + autopairs.add_rules { + Rule("$$", "$$", "tex"):with_pair(function(opts) + print(vim.inspect(opts)) + if opts.line == "aa $$" then + -- don't add pair on that line + return false + end + end), + } + + if package.loaded["cmp"] then + require("nvim-autopairs.completion.cmp").setup { + map_cr = true, -- map <CR> on insert mode + map_complete = true, -- it will auto insert `(` after select function or method item + auto_select = true, -- automatically select the first item + } + end + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } local ts_conds = require "nvim-autopairs.ts-conds" diff --git a/.config/nvim/lua/core/builtins/init.lua b/.config/nvim/lua/core/builtins/init.lua index 32f96af..dc9b5ff 100644 --- a/.config/nvim/lua/core/builtins/init.lua +++ b/.config/nvim/lua/core/builtins/init.lua @@ -4,7 +4,7 @@ local builtins = { "keymappings", "core.which-key", "core.gitsigns", - "core.compe", + "core.cmp", "core.dashboard", "core.dap", "core.terminal", diff --git a/.config/nvim/lua/core/cmp.lua b/.config/nvim/lua/core/cmp.lua new file mode 100644 index 0000000..50f7058 --- /dev/null +++ b/.config/nvim/lua/core/cmp.lua @@ -0,0 +1,123 @@ +local M = {} + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +local function T(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false +end + +M.config = function() + local status_cmp_ok, cmp = pcall(require, "cmp") + if not status_cmp_ok then + return + end + local status_luasnip_ok, luasnip = pcall(require, "luasnip") + if not status_luasnip_ok then + return + end + options.builtin.cmp = { + formatting = { + format = function(entry, vim_item) + local icons = require("lsp.kind").icons + vim_item.kind = icons[vim_item.kind] + vim_item.menu = ({ + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + })[entry.source.name] + vim_item.dup = ({ + buffer = 1, + path = 1, + nvim_lsp = 0, + })[entry.source.name] or 0 + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "crates" }, + }, + mapping = { + ["<C-d>"] = cmp.mapping.scroll_docs(-4), + ["<C-f>"] = cmp.mapping.scroll_docs(4), + -- TODO: potentially fix emmet nonsense + ["<Tab>"] = cmp.mapping(function() + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "<C-n>", "n") + elseif luasnip.expand_or_jumpable() then + vim.fn.feedkeys(T "<Plug>luasnip-expand-or-jump", "") + elseif check_backspace() then + vim.fn.feedkeys(T "<Tab>", "n") + elseif is_emmet_active() then + return vim.fn["cmp#complete"]() + else + vim.fn.feedkeys(T "<Tab>", "n") + end + end, { + "i", + "s", + }), + ["<S-Tab>"] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "<C-p>", "n") + elseif luasnip.jumpable(-1) then + vim.fn.feedkeys(T "<Plug>luasnip-jump-prev", "") + else + fallback() + end + end, { + "i", + "s", + }), + + ["<C-Space>"] = cmp.mapping.complete(), + ["<C-e>"] = cmp.mapping.close(), + ["<CR>"] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + } +end + +M.setup = function() + require("luasnip/loaders/from_vscode").lazy_load() + require("cmp").setup(options.builtin.cmp) +end + +return M diff --git a/.config/nvim/lua/core/compe.lua b/.config/nvim/lua/core/compe.lua deleted file mode 100644 index 19e49e0..0000000 --- a/.config/nvim/lua/core/compe.lua +++ /dev/null @@ -1,145 +0,0 @@ -local M = {} - -M.config = function() - options.builtin.compe = { - active = true, - on_config_done = nil, - autocomplete = true, - debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - documentation = { - border = "single", - winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", - max_width = 120, - min_width = 60, - max_height = math.floor(vim.o.lines * 0.3), - min_height = 1, - }, - -- documentation = true, - - source = { - path = { kind = " (Path)" }, - buffer = { kind = " (Buffer)" }, - calc = { kind = " (Calc)" }, - vsnip = { kind = " (Snippet)" }, - nvim_lsp = { kind = " (LSP)" }, - nvim_lua = false, - spell = { kind = " (Spell)" }, - tags = false, - vim_dadbod_completion = false, - snippets_nvim = false, - ultisnips = false, - treesitter = false, - emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, - -- for emoji press : (idk if that in compe tho) - }, - - keymap = { - values = { - insert_mode = { - -- ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true } }, - -- ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true } }, - ["<C-Space>"] = { - "compe#complete()", - { silent = true, noremap = true, expr = true }, - }, - ["<C-e>"] = { - "compe#close('<C-e>')", - { silent = true, noremap = true, expr = true }, - }, - ["<C-f>"] = { - "compe#scroll({ 'delta': +4 })", - { silent = true, noremap = true, expr = true }, - }, - ["<C-d>"] = { - "compe#scroll({ 'delta': -4 })", - { silent = true, noremap = true, expr = true }, - }, - }, - }, - opts = { - insert_mode = { noremap = true, silent = true, expr = true }, - }, - }, - } -end - -M.setup = function() - vim.g.vsnip_snippet_dir = options.vsnip_dir - - local compe = require "compe" - - compe.setup(options.builtin.compe) - - local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) - end - - local check_back_space = function() - local col = vim.fn.col "." - 1 - if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then - return true - else - return false - end - end - - local is_emmet_active = function() - local clients = vim.lsp.buf_get_clients() - - for _, client in pairs(clients) do - if client.name == "emmet_ls" then - return true - end - end - return false - end - - -- Use (s-)tab to: - --- move to prev/next item in completion menuone - --- jump to prev/next snippet's placeholder - _G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-n>" - elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then - return t "<Plug>(vsnip-jump-next)" - elseif check_back_space() then - return t "<Tab>" - elseif is_emmet_active() then - return vim.fn["compe#complete"]() - else - return t "<Tab>" - end - end - - _G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "<C-p>" - elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then - return t "<Plug>(vsnip-jump-prev)" - else - return t "<S-Tab>" - end - end - - local keymap = require "keymappings" - keymap.load(options.builtin.compe.keymap.values, options.builtin.compe.keymap.opts) - - vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) - - if options.builtin.compe.on_config_done then - options.builtin.compe.on_config_done(compe) - end -end - -return M diff --git a/.config/nvim/lua/core/lualine/components.lua b/.config/nvim/lua/core/lualine/components.lua index adae368..6af34fa 100644 --- a/.config/nvim/lua/core/lualine/components.lua +++ b/.config/nvim/lua/core/lualine/components.lua @@ -85,7 +85,8 @@ return { }, treesitter = { function() - if next(vim.treesitter.highlighter.active) then + local b = vim.api.nvim_get_current_buf() + if next(vim.treesitter.highlighter.active[b]) then return " " end return "" diff --git a/.config/nvim/lua/impatient.lua b/.config/nvim/lua/impatient.lua new file mode 100644 index 0000000..7d924d1 --- /dev/null +++ b/.config/nvim/lua/impatient.lua @@ -0,0 +1,348 @@ +-- modified version from https://github.com/lewis6991/impatient.nvim + +local vim = vim +local uv = vim.loop +local impatient_start = uv.hrtime() +local api = vim.api +local ffi = require "ffi" + +local get_option, set_option = api.nvim_get_option, api.nvim_set_option +local get_runtime_file = api.nvim_get_runtime_file +local home_dir = uv.os_homedir() + +local impatient_dur + +local M = { + cache = {}, + profile = nil, + dirty = false, + path = home_dir .. "/.local/share/nvim/cache", + log = {}, +} + +_G.__luacache = M + +--{{{ +local cachepack = {} + +-- using double for packing/unpacking numbers has no conversion overhead +local c_double = ffi.typeof "double[1]" +local sizeof_c_double = ffi.sizeof "double" + +local out_buf = {} + +function out_buf.write_number(buf, num) + buf[#buf + 1] = ffi.string(c_double(num), sizeof_c_double) +end + +function out_buf.write_string(buf, str) + out_buf.write_number(buf, #str) + buf[#buf + 1] = str +end + +function out_buf.to_string(buf) + return table.concat(buf) +end + +local in_buf = {} + +function in_buf.read_number(buf) + if buf.size < buf.pos then + error "buffer access violation" + end + local res = ffi.cast("double*", buf.ptr + buf.pos)[0] + buf.pos = buf.pos + sizeof_c_double + return res +end + +function in_buf.read_string(buf) + local len = in_buf.read_number(buf) + local res = ffi.string(buf.ptr + buf.pos, len) + buf.pos = buf.pos + len + + return res +end + +function cachepack.pack(cache) + local total_keys = vim.tbl_count(cache) + local buf = {} + + out_buf.write_number(buf, total_keys) + for k, v in pairs(cache) do + out_buf.write_string(buf, k) + out_buf.write_string(buf, v[1] or "") + out_buf.write_number(buf, v[2] or 0) + out_buf.write_string(buf, v[3] or "") + end + + return out_buf.to_string(buf) +end + +function cachepack.unpack(str, raw_buf_size) + if raw_buf_size == 0 or str == nil or (raw_buf_size == nil and #str == 0) then + return {} + end + + local buf = { + ptr = raw_buf_size and str or ffi.new("const char[?]", #str, str), + pos = 0, + size = raw_buf_size or #str, + } + local cache = {} + + local total_keys = in_buf.read_number(buf) + for _ = 1, total_keys do + local k = in_buf.read_string(buf) + local v = { + in_buf.read_string(buf), + in_buf.read_number(buf), + in_buf.read_string(buf), + } + cache[k] = v + end + + return cache +end +--}}} + +local function log(...) + M.log[#M.log + 1] = table.concat({ string.format(...) }, " ") +end + +function M.print_log() + for _, l in ipairs(M.log) do + print(l) + end +end + +function M.enable_profile() + M.profile = {} + M.print_profile = function() + M.profile["impatient"] = { + resolve = 0, + load = impatient_dur, + loader = "standard", + } + require("impatient.profile").print_profile(M.profile) + end + vim.cmd [[command! LuaCacheProfile lua _G.__luacache.print_profile()]] +end + +local function is_cacheable(path) + -- Don't cache files in /tmp since they are not likely to persist. + -- Note: Appimage versions of Neovim mount $VIMRUNTIME in /tmp in a unique + -- directory on each launch. + return not vim.startswith(path, "/tmp/") +end + +local function hash(modpath) + local stat = uv.fs_stat(modpath) + if stat then + return stat.mtime.sec + end +end + +local function hrtime() + if M.profile then + return uv.hrtime() + end +end + +local function load_package_with_cache(name, loader) + local resolve_start = hrtime() + + local basename = name:gsub("%.", "/") + local paths = { "lua/" .. basename .. ".lua", "lua/" .. basename .. "/init.lua" } + + for _, path in ipairs(paths) do + local modpath = get_runtime_file(path, false)[1] + if modpath then + local load_start = hrtime() + local chunk, err = loadfile(modpath) + + if M.profile then + M.profile[name] = { + resolve = load_start - resolve_start, + load = hrtime() - load_start, + loader = loader or "standard", + } + end + + if chunk == nil then + return err + end + + if is_cacheable(modpath) then + log("Creating cache for module %s", name) + M.cache[name] = { modpath, hash(modpath), string.dump(chunk) } + M.dirty = true + else + log("Unable to cache module %s", name) + end + + return chunk + end + end + return nil +end + +local reduced_rtp + +-- Speed up non-cached loads by reducing the rtp path during requires +function M.update_reduced_rtp() + local luadirs = get_runtime_file("lua/", true) + + for i = 1, #luadirs do + luadirs[i] = luadirs[i]:sub(1, -6) + end + + reduced_rtp = table.concat(luadirs, ",") +end + +local function load_package_with_cache_reduced_rtp(name) + local orig_rtp = get_option "runtimepath" + local orig_ei = get_option "eventignore" + + if not reduced_rtp then + M.update_reduced_rtp() + end + + set_option("eventignore", "all") + set_option("rtp", reduced_rtp) + + local found = load_package_with_cache(name, "reduced") + + set_option("rtp", orig_rtp) + set_option("eventignore", orig_ei) + + return found +end + +local function load_from_cache(name) + local resolve_start = hrtime() + if M.cache[name] == nil then + log("No cache for module %s", name) + return "No cache entry" + end + + local modpath, mhash, codes = unpack(M.cache[name]) + + if mhash ~= hash(modpath) then + log("Stale cache for module %s", name) + M.cache[name] = nil + M.dirty = true + return "Stale cache" + end + + local load_start = hrtime() + local chunk = loadstring(codes) + + if M.profile then + M.profile[name] = { + resolve = load_start - resolve_start, + load = hrtime() - load_start, + loader = "cache", + } + end + + if not chunk then + M.cache[name] = nil + M.dirty = true + log("Error loading cache for module. Invalidating", name) + return "Cache error" + end + + return chunk +end + +function M.save_cache() + if M.dirty then + log("Updating cache file: %s", M.path) + local f = io.open(M.path, "w+b") + f:write(cachepack.pack(M.cache)) + f:flush() + M.dirty = false + end +end + +function M.clear_cache() + M.cache = {} + os.remove(M.path) +end + +local function setup() + local stat = uv.fs_stat(M.path) + if stat then + log("Loading cache file %s", M.path) + local ok + -- Linux/macOS lets us easily mmap the cache file for faster reads without passing to Lua + if jit.os == "Linux" or jit.os == "OSX" then + local size = stat.size + + local C = ffi.C + local O_RDONLY = 0x00 + local PROT_READ = 0x01 + local MAP_PRIVATE = 0x02 + + ffi.cdef [[ + int open(const char *pathname, int flags); + int close(int fd); + void *mmap(void *addr, size_t length, int prot, int flags, int fd, long int offset); + int munmap(void *addr, size_t length); + ]] + local f = C.open(M.path, O_RDONLY) + + local addr = C.mmap(nil, size, PROT_READ, MAP_PRIVATE, f, 0) + ok = ffi.cast("intptr_t", addr) ~= -1 + + if ok then + M.cache = cachepack.unpack(ffi.cast("char *", addr), size) + C.munmap(addr, size) + end + + C.close(f) + else + local f = io.open(M.path, "rb") + ok, M.cache = pcall(function() + return cachepack.unpack(f:read "*a") + end) + end + + if not ok then + log("Corrupted cache file, %s. Invalidating...", M.path) + os.remove(M.path) + M.cache = {} + end + M.dirty = not ok + end + + local insert = table.insert + local package = package + + -- Fix the position of the preloader. This also makes loading modules like 'ffi' + -- and 'bit' quicker + if package.loaders[1] == vim._load_package then + -- Move vim._load_package to the second position + local vim_load = table.remove(package.loaders, 1) + insert(package.loaders, 2, vim_load) + end + + insert(package.loaders, 2, load_from_cache) + insert(package.loaders, 3, load_package_with_cache_reduced_rtp) + insert(package.loaders, 4, load_package_with_cache) + + vim.cmd [[ + augroup impatient + autocmd VimEnter,VimLeave * lua _G.__luacache.save_cache() + autocmd OptionSet runtimepath lua _G.__luacache.update_reduced_rtp(true) + augroup END + command! LuaCacheClear lua _G.__luacache.clear_cache() + command! LuaCacheLog lua _G.__luacache.print_log() + ]] +end + +setup() + +impatient_dur = uv.hrtime() - impatient_start + +return M diff --git a/.config/nvim/lua/impatient/cachepack.lua b/.config/nvim/lua/impatient/cachepack.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/.config/nvim/lua/impatient/cachepack.lua diff --git a/.config/nvim/lua/impatient/profile.lua b/.config/nvim/lua/impatient/profile.lua new file mode 100644 index 0000000..d057386 --- /dev/null +++ b/.config/nvim/lua/impatient/profile.lua @@ -0,0 +1,156 @@ +local M = {} + +local api = vim.api + +function M.print_profile(profile) + if not profile then + print "Error: profiling was not enabled" + return + end + + local total_resolve = 0 + local total_load = 0 + local name_pad = 0 + local modules = {} + local plugins = {} + + for module, p in pairs(profile) do + p.resolve = p.resolve / 1000000 + p.load = p.load / 1000000 + p.total = p.resolve + p.load + p.module = module:gsub("/", ".") + + local plugin = p.module:match "([^.]+)" + if plugin then + if not plugins[plugin] then + plugins[plugin] = { + module = plugin, + resolve = 0, + load = 0, + total = 0, + } + end + local r = plugins[plugin] + + r.resolve = r.resolve + p.resolve + r.load = r.load + p.load + r.total = r.total + p.total + + if not r.loader then + r.loader = p.loader + elseif r.loader ~= p.loader then + r.loader = "mixed" + end + end + + total_resolve = total_resolve + p.resolve + total_load = total_load + p.load + + if #module > name_pad then + name_pad = #module + end + + modules[#modules + 1] = p + end + + table.sort(modules, function(a, b) + return a.module > b.module + end) + + do + local plugins_a = {} + for _, v in pairs(plugins) do + plugins_a[#plugins_a + 1] = v + end + plugins = plugins_a + end + + table.sort(plugins, function(a, b) + return a.total > b.total + end) + + local lines = {} + local function add(...) + lines[#lines + 1] = string.format(...) + end + + local l = string.rep("─", name_pad + 1) + + add( + "%s┬───────────┬────────────┬────────────┬────────────┐", + l + ) + add( + "%-" + .. name_pad + .. "s │ Loader │ Resolve │ Load │ Total │", + "" + ) + add( + "%s┼───────────┼────────────┼────────────┼────────────┤", + l + ) + add( + "%-" .. name_pad .. "s │ │ %8.4fms │ %8.4fms │ %8.4fms │", + "Total", + total_resolve, + total_load, + total_resolve + total_load + ) + add( + "%s┴───────────┴────────────┴────────────┴────────────┤", + l + ) + add( + "%-" .. name_pad .. "s │", + "By Plugin" + ) + add( + "%s┬───────────┬────────────┬────────────┬────────────┤", + l + ) + for _, p in ipairs(plugins) do + add( + "%-" .. name_pad .. "s │ %9s │ %8.4fms │ %8.4fms │ %8.4fms │", + p.module, + p.loader, + p.resolve, + p.load, + p.total + ) + end + add( + "%s┴───────────┴────────────┴────────────┴────────────┤", + l + ) + add( + "%-" .. name_pad .. "s │", + "By Module" + ) + add( + "%s┬───────────┬────────────┬────────────┬────────────┤", + l + ) + for _, p in pairs(modules) do + add( + "%-" .. name_pad .. "s │ %9s │ %8.4fms │ %8.4fms │ %8.4fms │", + p.module, + p.loader, + p.resolve, + p.load, + p.total + ) + end + add( + "%s┴───────────┴────────────┴────────────┴────────────┘", + l + ) + + local bufnr = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(bufnr, 0, 0, false, lines) + api.nvim_buf_set_option(bufnr, "buftype", "nofile") + api.nvim_buf_set_name(bufnr, "Impatient Profile Report") + api.nvim_set_current_buf(bufnr) +end + +return M diff --git a/.config/nvim/lua/lsp/handlers.lua b/.config/nvim/lua/lsp/handlers.lua index d19cb33..04b8477 100644 --- a/.config/nvim/lua/lsp/handlers.lua +++ b/.config/nvim/lua/lsp/handlers.lua @@ -3,44 +3,56 @@ local M = {} function M.setup() - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + local config = { -- your config virtual_text = options.lsp.diagnostics.virtual_text, - signs = options.lsp.diagnostics.signs.active, - underline = options.lsp.document_highlight, - }) - - vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _) - local config = { -- your config - virtual_text = options.lsp.diagnostics.virtual_text, - signs = options.lsp.diagnostics.signs, - underline = options.lsp.diagnostics.underline, - update_in_insert = options.lsp.diagnostics.update_in_insert, - severity_sort = options.lsp.diagnostics.severity_sort, - } - local uri = params.uri - local bufnr = vim.uri_to_bufnr(uri) + signs = options.lsp.diagnostics.signs, + underline = options.lsp.diagnostics.underline, + update_in_insert = options.lsp.diagnostics.update_in_insert, + severity_sort = options.lsp.diagnostics.severity_sort, + } + if vim.fn.has "nvim-0.5.1" > 0 then + vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, result, ctx, _) + local uri = result.uri + local bufnr = vim.uri_to_bufnr(uri) + if not bufnr then + return + end - if not bufnr then - return + local diagnostics = result.diagnostics + vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config) end + else + vim.lsp.handlers["textDocument/publishDiagnostics"] = + function(_, _, params, client_id, _) + local uri = params.uri + local bufnr = vim.uri_to_bufnr(uri) + if not bufnr then + return + end - local diagnostics = params.diagnostics - - vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) - - if not vim.api.nvim_buf_is_loaded(bufnr) then - return - end - vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) + local diagnostics = params.diagnostics + vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) + end end vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = options.lsp.popup_border, }) - vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = options.lsp.popup_border, - }) + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, + { + border = options.lsp.popup_border, + } + ) end function M.show_line_diagnostics() @@ -65,7 +77,10 @@ function M.show_line_diagnostics() local source = diagnostic.source if source then if string.find(source, "/") then - source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$")) + source = string.sub( + diagnostic.source, + string.find(diagnostic.source, "([%w-_]+)$") + ) end diags[i].message = string.format("%s: %s", source, diagnostic.message) else @@ -102,7 +117,9 @@ function M.show_line_diagnostics() end vim.api.nvim_command( - "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)" + "autocmd QuitPre <buffer> ++nested ++once lua pcall(vim.api.nvim_win_close, " + .. winnr + .. ", true)" ) vim.lsp.util.close_preview_autocmd(close_events, winnr) end diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 5b342f0..20bcb4c 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -27,34 +27,34 @@ return { }, -- Completion & Snippets { - "hrsh7th/nvim-compe", - event = "InsertEnter", + "hrsh7th/nvim-cmp", config = function() - require("core.compe").setup() + require("core.cmp").setup() end, - disable = not options.builtin.compe.active, - }, - { - "hrsh7th/vim-vsnip", - -- wants = "friendly-snippets", - event = "InsertEnter", - disable = not options.builtin.compe.active, + requires = { + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lua", + }, }, { "rafamadriz/friendly-snippets", - event = "InsertCharPre", - disable = not options.builtin.compe.active, + -- event = "InsertCharPre", + -- disable = not options.builtin.compe.active, }, -- Autopairs { "windwp/nvim-autopairs", -- event = "InsertEnter", - after = "nvim-compe", + after = "nvim-cmp", config = function() require("core.autopairs").setup() end, - disable = not options.builtin.autopairs.active or not options.builtin.compe.active, + disable = not options.builtin.autopairs.active, }, -- Treesitter |