From 540268d618627079c9b958a955b586e1888b46a8 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 10 Aug 2021 23:15:04 +0200 Subject: Major refactor of nvim --- .config/nvim/lua/core/autocmds.lua | 114 ++++++++++++++++++++ .config/nvim/lua/core/autopairs.lua | 2 + .config/nvim/lua/core/bufferline.lua | 46 ++++---- .config/nvim/lua/core/colorizer.lua | 17 --- .config/nvim/lua/core/commands.lua | 21 ++++ .config/nvim/lua/core/compe.lua | 50 ++++++--- .config/nvim/lua/core/dap.lua | 10 +- .config/nvim/lua/core/dashboard.lua | 24 ++--- .config/nvim/lua/core/formatter.lua | 60 ----------- .config/nvim/lua/core/galaxyline.lua | 50 ++++----- .config/nvim/lua/core/gitsigns.lua | 7 +- .config/nvim/lua/core/hop.lua | 20 ---- .config/nvim/lua/core/info.lua | 180 ++++++++++++++++++++++++++++++++ .config/nvim/lua/core/linter.lua | 33 ------ .config/nvim/lua/core/log.lua | 29 +++++ .config/nvim/lua/core/nvimtree.lua | 58 ++++++++-- .config/nvim/lua/core/status_colors.lua | 2 +- .config/nvim/lua/core/telescope.lua | 11 +- .config/nvim/lua/core/terminal.lua | 95 ++++++++++++++--- .config/nvim/lua/core/treesitter.lua | 122 +--------------------- .config/nvim/lua/core/which-key.lua | 79 +++++++++----- .config/nvim/lua/core/zen.lua | 34 ------ 22 files changed, 638 insertions(+), 426 deletions(-) create mode 100644 .config/nvim/lua/core/autocmds.lua delete mode 100644 .config/nvim/lua/core/colorizer.lua create mode 100644 .config/nvim/lua/core/commands.lua delete mode 100644 .config/nvim/lua/core/formatter.lua delete mode 100644 .config/nvim/lua/core/hop.lua create mode 100644 .config/nvim/lua/core/info.lua delete mode 100644 .config/nvim/lua/core/linter.lua create mode 100644 .config/nvim/lua/core/log.lua delete mode 100644 .config/nvim/lua/core/zen.lua (limited to '.config/nvim/lua/core') diff --git a/.config/nvim/lua/core/autocmds.lua b/.config/nvim/lua/core/autocmds.lua new file mode 100644 index 0000000..959ae15 --- /dev/null +++ b/.config/nvim/lua/core/autocmds.lua @@ -0,0 +1,114 @@ +local autocommands = {} + +options.autocommands = { + _general_settings = { + { + "Filetype", + "*", + "lua require('utils.ft').do_filetype(vim.fn.expand(\"\"))", + }, + { + "TextYankPost", + "*", + "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", + }, + { + "BufWinEnter", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufWinEnter", + "dashboard", + "setlocal cursorline signcolumn=yes cursorcolumn number", + }, + { + "BufRead", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { + "BufNewFile", + "*", + "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", + }, + { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_config()" }, + { + "FileType", + "qf", + "set nobuflisted", + }, + -- { "VimLeavePre", "*", "set title set titleold=" }, + }, + _filetypechanges = { + { "BufWinEnter", ".tf", "setlocal filetype=terraform" }, + { "BufRead", "*.tf", "setlocal filetype=terraform" }, + { "BufNewFile", "*.tf", "setlocal filetype=terraform" }, + { "BufWinEnter", ".zsh", "setlocal filetype=sh" }, + { "BufRead", "*.zsh", "setlocal filetype=sh" }, + { "BufNewFile", "*.zsh", "setlocal filetype=sh" }, + }, + -- _solidity = { + -- {'BufWinEnter', '.sol', 'setlocal filetype=solidity'}, {'BufRead', '*.sol', 'setlocal filetype=solidity'}, + -- {'BufNewFile', '*.sol', 'setlocal filetype=solidity'} + -- }, + -- _gemini = { + -- {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'}, + -- {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'} + -- }, + _markdown = { + { "FileType", "markdown", "setlocal wrap" }, + { "FileType", "markdown", "setlocal spell" }, + }, + _buffer_bindings = { + { "FileType", "floaterm", "nnoremap q :q" }, + }, + _auto_resize = { + -- will cause split windows to be resized evenly if main window is resized + { "VimResized", "*", "wincmd =" }, + }, + _packer_compile = { + -- will run PackerCompile after writing plugins.lua + { "BufWritePost", "plugins.lua", "PackerCompile" }, + }, + _general_lsp = { + { "FileType", "lspinfo", "nnoremap q :q" }, + }, + + -- _fterm_lazygit = { + -- -- will cause esc key to exit lazy git + -- {"TermEnter", "*", "call LazyGitNativation()"} + -- }, + -- _mode_switching = { + -- -- will switch between absolute and relative line numbers depending on mode + -- {'InsertEnter', '*', 'if &relativenumber | let g:ms_relativenumberoff = 1 | setlocal number norelativenumber | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_relativenumberoff") | setlocal relativenumber | endif'}, + -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'}, + -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'}, + -- }, + custom_groups = {}, +} + +function autocommands.define_augroups(definitions) -- {{{1 + -- Create autocommand groups based on the passed definitions + -- + -- The key will be the name of the group, and each definition + -- within the group should have: + -- 1. Trigger + -- 2. Pattern + -- 3. Text + -- just like how they would normally be defined from Vim itself + for group_name, definition in pairs(definitions) do + vim.cmd("augroup " .. group_name) + vim.cmd "autocmd!" + + for _, def in pairs(definition) do + local command = table.concat(vim.tbl_flatten { "autocmd", def }, " ") + vim.cmd(command) + end + + vim.cmd "augroup END" + end +end + +return autocommands diff --git a/.config/nvim/lua/core/autopairs.lua b/.config/nvim/lua/core/autopairs.lua index f0111db..afd6e28 100644 --- a/.config/nvim/lua/core/autopairs.lua +++ b/.config/nvim/lua/core/autopairs.lua @@ -1,8 +1,10 @@ -- if not package.loaded['nvim-autopairs'] then -- return -- end +local Log = require "core.log" local status_ok, _ = pcall(require, "nvim-autopairs") if not status_ok then + Log:get_default().error "Failed to load autopairs" return end local npairs = require "nvim-autopairs" diff --git a/.config/nvim/lua/core/bufferline.lua b/.config/nvim/lua/core/bufferline.lua index d4e4b4f..6306614 100644 --- a/.config/nvim/lua/core/bufferline.lua +++ b/.config/nvim/lua/core/bufferline.lua @@ -1,28 +1,20 @@ -vim.api.nvim_set_keymap("n", "", ":BufferClose", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "", ":BufferNext", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "", ":BufferPrevious", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "c", ":BufferClose", { noremap = true, silent = true }) +local M = {} -O.plugin.which_key.mappings["b"] = { - name = "Buffers", - j = { "BufferPick", "jump to buffer" }, - f = { "Telescope buffers", "Find buffer" }, - w = { "BufferWipeout", "wipeout buffer" }, - e = { - "BufferCloseAllButCurrent", - "close all but current buffer", - }, - h = { "BufferCloseBuffersLeft", "close all buffers to the left" }, - l = { - "BufferCloseBuffersRight", - "close all BufferLines to the right", - }, - D = { - "BufferOrderByDirectory", - "sort BufferLines automatically by directory", - }, - L = { - "BufferOrderByLanguage", - "sort BufferLines automatically by language", - }, -} +M.config = function() + options.builtin.bufferline = { + active = true, + keymap = { + normal_mode = { + [""] = ":BufferNext", + [""] = ":BufferPrevious", + }, + }, + } +end + +M.setup = function() + local keymap = require "keymappings" + keymap.append_to_defaults(options.builtin.bufferline.keymap) +end + +return M diff --git a/.config/nvim/lua/core/colorizer.lua b/.config/nvim/lua/core/colorizer.lua deleted file mode 100644 index c6a2a27..0000000 --- a/.config/nvim/lua/core/colorizer.lua +++ /dev/null @@ -1,17 +0,0 @@ -local M = {} - -M.config = function() - O.plugin.hop = { - active = false, - } -end - -M.setup = function() - local status_ok, colorizer = pcall(require, "colorizer") - if not status_ok then - return - end - colorizer.setup(O.plugin.hop) -end - -return M diff --git a/.config/nvim/lua/core/commands.lua b/.config/nvim/lua/core/commands.lua new file mode 100644 index 0000000..c42b385 --- /dev/null +++ b/.config/nvim/lua/core/commands.lua @@ -0,0 +1,21 @@ +local M = {} + +M.defaults = { + [[ + function! QuickFixToggle() + if empty(filter(getwininfo(), 'v:val.quickfix')) + copen + else + cclose + endif + endfunction + ]], +} + +M.load = function(commands) + for _, command in ipairs(commands) do + vim.cmd(command) + end +end + +return M diff --git a/.config/nvim/lua/core/compe.lua b/.config/nvim/lua/core/compe.lua index c8152ad..3291918 100644 --- a/.config/nvim/lua/core/compe.lua +++ b/.config/nvim/lua/core/compe.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.completion = { + options.builtin.compe = { enabled = true, autocomplete = true, debug = false, @@ -12,7 +13,15 @@ M.config = function() max_abbr_width = 100, max_kind_width = 100, max_menu_width = 100, - documentation = true, + 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)" }, @@ -30,18 +39,35 @@ M.config = function() emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, -- for emoji press : (idk if that in compe tho) }, + + keymap = { + values = { + insert_mode = { + -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, + -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, + [""] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, + [""] = { "compe#close('')", { silent = true, noremap = true, expr = true } }, + [""] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, + [""] = { "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 = O.vsnip_dir + vim.g.vsnip_snippet_dir = options.vsnip_dir local status_ok, compe = pcall(require, "compe") if not status_ok then + Log:get_default().error "Failed to load compe" return end - compe.setup(O.completion) + compe.setup(options.builtin.compe) local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -62,12 +88,13 @@ M.setup = function() _G.tab_complete = function() if vim.fn.pumvisible() == 1 then return t "" - elseif vim.fn.call("vsnip#available", { 1 }) == 1 then - return t "(vsnip-expand-or-jump)" + elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then + return t "(vsnip-jump-next)" elseif check_back_space() then return t "" else - return vim.fn["compe#complete"]() + -- return vim.fn["compe#complete"]() -- < use this if you want to always offer completion + return t "" end end @@ -81,16 +108,13 @@ M.setup = function() end end + local keymap = require "keymappings" + keymap.load(options.builtin.compe.keymap.values, options.builtin.compe.keymap.opts) + vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) - - vim.api.nvim_set_keymap("i", "", "compe#complete()", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#confirm('')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#close('')", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) - vim.api.nvim_set_keymap("i", "", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) end return M diff --git a/.config/nvim/lua/core/dap.lua b/.config/nvim/lua/core/dap.lua index bc76e22..a325c7c 100644 --- a/.config/nvim/lua/core/dap.lua +++ b/.config/nvim/lua/core/dap.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.dap = { + options.builtin.dap = { active = false, breakpoint = { text = "", @@ -14,13 +15,14 @@ end M.setup = function() local status_ok, dap = pcall(require, "dap") if not status_ok then + Log:get_default().error "Failed to load dap" return end - vim.fn.sign_define("DapBreakpoint", O.plugin.dap.breakpoint) + vim.fn.sign_define("DapBreakpoint", options.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" - O.user_which_key["d"] = { + options.builtin.which_key.mappings["d"] = { name = "Debug", t = { "lua require'dap'.toggle_breakpoint()", "Toggle Breakpoint" }, b = { "lua require'dap'.step_back()", "Step Back" }, @@ -34,7 +36,7 @@ M.setup = function() p = { "lua require'dap'.pause.toggle()", "Pause" }, r = { "lua require'dap'.repl.toggle()", "Toggle Repl" }, s = { "lua require'dap'.continue()", "Start" }, - q = { "lua require'dap'.stop()", "Quit" }, + q = { "lua require'dap'.close()", "Quit" }, } end diff --git a/.config/nvim/lua/core/dashboard.lua b/.config/nvim/lua/core/dashboard.lua index 4c7ecc3..c868540 100644 --- a/.config/nvim/lua/core/dashboard.lua +++ b/.config/nvim/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dashboard = { + options.builtin.dashboard = { active = false, search_handler = "telescope", custom_header = { @@ -49,26 +49,26 @@ end M.setup = function() vim.g.dashboard_disable_at_vimenter = 0 - vim.g.dashboard_custom_header = O.plugin.dashboard.custom_header + vim.g.dashboard_custom_header = options.builtin.dashboard.custom_header - vim.g.dashboard_default_executive = O.plugin.dashboard.search_handler + vim.g.dashboard_default_executive = options.builtin.dashboard.search_handler - vim.g.dashboard_custom_section = O.plugin.dashboard.custom_section + vim.g.dashboard_custom_section = options.builtin.dashboard.custom_section - O.plugin.which_key.mappings[";"] = { "Dashboard", "Dashboard" } + options.builtin.which_key.mappings[";"] = { "Dashboard", "Dashboard" } -- f = { -- description = { " Neovim Config Files" }, - -- command = "Telescope find_files cwd=" .. CONFIG_PATH, + -- command = "Telescope find_files cwd=" .. CoptionsFIG_PATH, -- }, -- e = {description = {' Marks '}, command = 'Telescope marks'} - vim.cmd "let g:dashboard_session_directory = $HOME..'/.config/nvim/.sessions'" + vim.cmd "let g:dashboard_session_directory = $HoptionsE..'/.config/nvim/.sessions'" vim.cmd "let packages = len(globpath('~/.local/share/nvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( [[ - let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' plugins'] + let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' builtins'] ]], false ) @@ -76,10 +76,10 @@ M.setup = function() -- file_browser = {description = {' File Browser'}, command = 'Telescope find_files'}, -- vim.g.dashboard_session_directory = CACHE_PATH..'/session' - -- vim.g.dashboard_custom_footer = O.dashboard.footer - require("utils").define_augroups { + -- vim.g.dashboard_custom_footer = optionsdashboard.footer + require("core.autocmds").define_augroups { _dashboard = { - -- seems to be nobuflisted that makes my stuff disapear will do more testing + -- seems to be nobuflisted that makes my stuff disappear will do more testing { "FileType", "dashboard", @@ -88,7 +88,7 @@ M.setup = function() { "FileType", "dashboard", - "set showtabline=0 | autocmd BufLeave set showtabline=" .. O.default_options.showtabline, + "set showtabline=0 | autocmd BufLeave set showtabline=" .. vim.opt.showtabline._value, }, { "FileType", "dashboard", "nnoremap q :q" }, }, diff --git a/.config/nvim/lua/core/formatter.lua b/.config/nvim/lua/core/formatter.lua deleted file mode 100644 index 04c078a..0000000 --- a/.config/nvim/lua/core/formatter.lua +++ /dev/null @@ -1,60 +0,0 @@ --- autoformat -if O.format_on_save then - require("utils").define_augroups { - autoformat = { - { - "BufWritePost", - "*", - ":silent FormatWrite", - }, - }, - } -end - --- -- check if formatter has been defined for the language or not --- local function formatter_exists(lang_formatter) --- if lang_formatter == nil then --- return false --- end --- if lang_formatter.exe == nil or lang_formatter.args == nil then --- return false --- end --- return true --- end - --- returns default formatter for given language --- local function formatter_return(lang_formatter) --- return { --- exe = lang_formatter.exe, --- args = lang_formatter.args, --- stdin = not (lang_formatter.stdin ~= nil), --- } --- end - --- fill a table like this -> {rust: {exe:"sth",args:{"a","b"},stdin=true},go: {}...} --- local formatter_filetypes = {} --- for k, v in pairs(O.lang) do --- if formatter_exists(v.formatter) then --- local keys = v.filetypes --- if keys == nil then --- keys = { k } --- end --- for _, l in pairs(keys) do --- formatter_filetypes[l] = { --- function() --- return formatter_return(v.formatter) --- end, --- } --- end --- end --- end -local status_ok, _ = pcall(require, "formatter") -if not status_ok then - return -end - -if not O.format_on_save then - vim.cmd [[if exists('#autoformat#BufWritePost') - :autocmd! autoformat - endif]] -end diff --git a/.config/nvim/lua/core/galaxyline.lua b/.config/nvim/lua/core/galaxyline.lua index 1f9f781..ff8c59a 100644 --- a/.config/nvim/lua/core/galaxyline.lua +++ b/.config/nvim/lua/core/galaxyline.lua @@ -1,15 +1,17 @@ -- if not package.loaded['galaxyline'] then -- return -- end +local Log = require "core.log" local status_ok, gl = pcall(require, "galaxyline") if not status_ok then + Log:get_default().error "Failed to load galaxyline" return end -- NOTE: if someone defines colors but doesn't have them then this will break -local palette_status_ok, colors = pcall(require, O.colorscheme .. ".palette") +local palette_status_ok, colors = pcall(require, options.colorscheme .. ".palette") if not palette_status_ok then - colors = O.plugin.galaxyline.colors + colors = options.builtin.galaxyline.colors end local condition = require "galaxyline.condition" @@ -189,39 +191,27 @@ table.insert(gls.right, { }, }) -local get_lsp_client = function(msg) +local function get_attached_provider_name(msg) msg = msg or "LSP Inactive" - local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") - local clients = vim.lsp.get_active_clients() - if next(clients) == nil then + local buf_clients = vim.lsp.buf_get_clients() + if next(buf_clients) == nil then return msg end - local lsps = "" - for _, client in ipairs(clients) do - local filetypes = client.config.filetypes - if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then - -- print(client.name) - if lsps == "" then - -- print("first", lsps) - lsps = client.name - else - if not string.find(lsps, client.name) then - lsps = lsps .. ", " .. client.name - end - -- print("more", lsps) - end + local buf_ft = vim.bo.filetype + local buf_client_names = {} + local null_ls_providers = require("lsp.null-ls").get_registered_providers_by_filetype(buf_ft) + for _, client in pairs(buf_clients) do + if client.name ~= "null-ls" then + table.insert(buf_client_names, client.name) end end - if lsps == "" then - return msg - else - return lsps - end + vim.list_extend(buf_client_names, null_ls_providers) + return table.concat(buf_client_names, ", ") end table.insert(gls.right, { ShowLspClient = { - provider = get_lsp_client, + provider = get_attached_provider_name, condition = function() local tbl = { ["dashboard"] = true, [" "] = true } if tbl[vim.bo.filetype] then @@ -255,7 +245,11 @@ table.insert(gls.right, { table.insert(gls.right, { Tabstop = { provider = function() - return "Spaces: " .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " + local label = "Spaces: " + if not vim.api.nvim_buf_get_option(0, "expandtab") then + label = "Tab size: " + end + return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, condition = condition.hide_in_width, separator = " ", @@ -311,5 +305,3 @@ table.insert(gls.short_line_left, { highlight = { colors.alt_bg, colors.alt_bg }, }, }) - ---table.insert(gls.short_line_right[1] = {BufferIcon = {provider = 'BufferIcon', highlight = {colors.grey, colors.alt_bg}}}) diff --git a/.config/nvim/lua/core/gitsigns.lua b/.config/nvim/lua/core/gitsigns.lua index bc310ad..0b72689 100644 --- a/.config/nvim/lua/core/gitsigns.lua +++ b/.config/nvim/lua/core/gitsigns.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.gitsigns = { + options.builtin.gitsigns = { signs = { add = { hl = "GitSignsAdd", @@ -44,16 +45,16 @@ M.config = function() sign_priority = 6, update_debounce = 200, status_formatter = nil, -- Use default - use_decoration_api = false, } end M.setup = function() local status_ok, gitsigns = pcall(require, "gitsigns") if not status_ok then + Log:get_default().error "Failed to load gitsigns" return end - gitsigns.setup(O.plugin.gitsigns) + gitsigns.setup(options.builtin.gitsigns) end return M diff --git a/.config/nvim/lua/core/hop.lua b/.config/nvim/lua/core/hop.lua deleted file mode 100644 index d3dd90d..0000000 --- a/.config/nvim/lua/core/hop.lua +++ /dev/null @@ -1,20 +0,0 @@ -vim.api.nvim_set_keymap('n', 's', ":HopChar2", { noremap = true, silent = true }) -vim.api.nvim_set_keymap('n', 'S', ":HopWord", { noremap = true, silent = true }) - -local M = {} - -M.config = function() - O.plugin.hop = { - active = false, - } -end - -M.setup = function() - local status_ok, hop = pcall(require, "hop") - if not status_ok then - return - end - hop.setup(O.plugin.hop) -end - -return M diff --git a/.config/nvim/lua/core/info.lua b/.config/nvim/lua/core/info.lua new file mode 100644 index 0000000..c9d34ce --- /dev/null +++ b/.config/nvim/lua/core/info.lua @@ -0,0 +1,180 @@ +local M = {} +local u = require "utils" +local null_ls_handler = require "lsp.null-ls" +local indent = " " + +M.banner = { + "", + "", + " ⠀⠀⠀ ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀", + " ⣿⣯ ⣿⡟⠀ ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", + "⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", + "⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", + "⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", + "⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", + "", + "", +} + +local function str_list(list) + return "[ " .. table.concat(list, ", ") .. " ]" +end + +local function get_formatter_suggestion_msg(ft) + local supported_formatters = u.get_supported_formatters_by_filetype(ft) + return { + "-------------------------------------------------------------------", + "", + "  HINT ", + "", + indent .. "* List of supported formatters: " .. str_list(supported_formatters), + "", + indent .. "You can enable a supported formatter by adding this to your config.lua", + "", + indent + .. "options.lang." + .. tostring(ft) + .. [[.formatting = { { exe = ']] + .. table.concat(supported_formatters, "|") + .. [[' } }]], + "", + "-------------------------------------------------------------------", + } +end + +local function get_linter_suggestion_msg(ft) + local supported_linters = u.get_supported_linters_by_filetype(ft) + return { + "-------------------------------------------------------------------", + "", + "  HINT ", + "", + indent .. "* List of supported linters: " .. str_list(supported_linters), + "", + indent .. "You can enable a supported linter by adding this to your config.lua", + "", + indent + .. "options.lang." + .. tostring(ft) + .. [[.linters = { { exe = ']] + .. table.concat(supported_linters, "|") + .. [[' } }]], + "", + "-------------------------------------------------------------------", + } +end + +---creates an average size popup +---@param buf_lines a list of lines to print +---@param callback could be used to set syntax highlighting rules for example +---@return bufnr buffer number of the created buffer +---@return win_id window ID of the created popup +function M.create_simple_popup(buf_lines, callback) + -- runtime/lua/vim/lsp/util.lua + local bufnr = vim.api.nvim_create_buf(false, true) + local height_percentage = 0.7 + local width_percentage = 0.8 + local row_start_percentage = (1 - height_percentage) / 2 + local col_start_percentage = (1 - width_percentage) / 2 + local opts = {} + opts.relative = "editor" + opts.height = math.ceil(vim.o.lines * height_percentage) + opts.row = math.ceil(vim.o.lines * row_start_percentage) + opts.col = math.floor(vim.o.columns * col_start_percentage) + opts.width = math.floor(vim.o.columns * width_percentage) + opts.border = { + "┌", + "-", + "┐", + "|", + "┘", + "-", + "└", + "|", + } + + local win_id = vim.api.nvim_open_win(bufnr, true, opts) + + vim.api.nvim_win_set_buf(win_id, bufnr) + -- this needs to be window option! + vim.api.nvim_win_set_option(win_id, "number", false) + vim.cmd "setlocal nocursorcolumn" + vim.cmd "setlocal wrap" + -- set buffer options + vim.api.nvim_buf_set_option(bufnr, "filetype", "lspinfo") + vim.lsp.util.close_preview_autocmd({ "BufHidden", "BufLeave" }, win_id) + buf_lines = vim.lsp.util._trim(buf_lines, {}) + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, buf_lines) + vim.api.nvim_buf_set_option(bufnr, "modifiable", false) + if type(callback) == "function" then + callback() + end + return bufnr, win_id +end + +function M.toggle_popup(ft) + local client = u.get_active_client_by_ft(ft) + local is_client_active = not client.is_stopped() + local client_enabled_caps = require("lsp").get_ls_capabilities(client.id) + local num_caps = vim.tbl_count(client_enabled_caps) + local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft) + + local missing_linters = options.lang[ft].linters._failed_requests or {} + local missing_formatters = options.lang[ft].formatters._failed_requests or {} + + local buf_lines = {} + vim.list_extend(buf_lines, M.banner) + + local header = { + "Detected filetype is: " .. tostring(ft), + "", + "Treesitter active: " .. tostring(next(vim.treesitter.highlighter.active) ~= nil), + "", + "", + } + vim.list_extend(buf_lines, header) + + local lsp_info = { + "Associated language-server: " .. client.name, + indent .. "* Active: " .. tostring(is_client_active) .. ", id: " .. tostring(client.id), + indent .. "* Formatting support: " .. tostring(client.resolved_capabilities.document_formatting), + indent .. "* Capabilities list: " .. table.concat(vim.list_slice(client_enabled_caps, 1, num_caps / 2), ", "), + indent .. indent .. indent .. table.concat(vim.list_slice(client_enabled_caps, ((num_caps / 2) + 1)), ", "), + "", + } + vim.list_extend(buf_lines, lsp_info) + + local null_ls_info = { + "Configured providers: " .. table.concat(null_ls_providers, "  , ") .. "  ", + "", + } + vim.list_extend(buf_lines, null_ls_info) + + local missing_formatters_status + if vim.tbl_count(missing_formatters) > 0 then + missing_formatters_status = { "Missing formatters: " .. table.concat(missing_formatters, "  , ") .. "  ", "" } + vim.list_extend(buf_lines, missing_formatters_status) + end + + local missing_linters_status + if vim.tbl_count(missing_linters) > 0 then + missing_linters_status = { "Missing linters: " .. table.concat(missing_linters, "  , ") .. "  ", "" } + vim.list_extend(buf_lines, missing_linters_status) + end + + vim.list_extend(buf_lines, get_formatter_suggestion_msg(ft)) + + vim.list_extend(buf_lines, get_linter_suggestion_msg(ft)) + + local function set_syntax_hl() + --TODO: highlighting is either inconsistent or not working :\ + vim.cmd("syntax match Identifier /filetype is: .*\\zs\\<" .. ft .. "\\>/") + vim.cmd("syntax match Identifier /server: .*\\zs\\<" .. client.name .. "\\>/") + vim.cmd("syntax match Identifier /providers: .*\\zs\\<" .. table.concat(null_ls_providers, ", ") .. "\\>/") + vim.cmd("syntax match Identifier /formatters: .*\\zs\\<" .. table.concat(missing_formatters, ", ") .. "\\>/") + vim.cmd("syntax match Identifier /linters: .*\\zs\\<" .. table.concat(missing_linters, ", ") .. "\\>/") + end + + return M.create_simple_popup(buf_lines, set_syntax_hl) +end +return M diff --git a/.config/nvim/lua/core/linter.lua b/.config/nvim/lua/core/linter.lua deleted file mode 100644 index 94dff93..0000000 --- a/.config/nvim/lua/core/linter.lua +++ /dev/null @@ -1,33 +0,0 @@ -local M = {} - -M.setup = function() - if O.lint_on_save then - require("utils").define_augroups { - autolint = { - { - "BufWritePost", - "", - ":silent lua require('lint').try_lint()", - }, - { - "BufEnter", - "", - ":silent lua require('lint').try_lint()", - }, - }, - } - end -end - -local status_ok, _ = pcall(require, "lint") -if not status_ok then - return -end - -if not O.lint_on_save then - vim.cmd [[if exists('#autolint#BufWritePost') - :autocmd! autolint - endif]] -end - -return M diff --git a/.config/nvim/lua/core/log.lua b/.config/nvim/lua/core/log.lua new file mode 100644 index 0000000..d364ffb --- /dev/null +++ b/.config/nvim/lua/core/log.lua @@ -0,0 +1,29 @@ +local Log = {} + +--- Creates a log handle based on Plenary.log +---@param opts these are passed verbatim to Plenary.log +---@return log handle +function Log:new(opts) + local status_ok, _ = pcall(require, "plenary.log") + if not status_ok then + return nil + end + + local obj = require("plenary.log").new(opts) + local path = string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), opts.plugin) + + obj.get_path = function() + return path + end + + return obj +end + +--- Creates or retrieves a log handle for the default logfile +--- based on Plenary.log +---@return log handle +function Log:get_default() + return Log:new { plugin = "nvim", level = options.log.level } +end + +return Log diff --git a/.config/nvim/lua/core/nvimtree.lua b/.config/nvim/lua/core/nvimtree.lua index a763c71..698bd6e 100644 --- a/.config/nvim/lua/core/nvimtree.lua +++ b/.config/nvim/lua/core/nvimtree.lua @@ -1,8 +1,10 @@ local M = {} +local Log = require "core.log" -- M.config = function() - O.plugin.nvimtree = { + options.builtin.nvimtree = { side = "left", + width = 30, show_icons = { git = 1, folders = 1, @@ -48,23 +50,54 @@ end M.setup = function() local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") if not status_ok then + Log:get_default().error "Failed to load nvim-tree.config" return end local g = vim.g - for opt, val in pairs(O.plugin.nvimtree) do + for opt, val in pairs(options.builtin.nvimtree) do g["nvim_tree_" .. opt] = val end local tree_cb = nvim_tree_config.nvim_tree_callback - g.nvim_tree_bindings = { - { key = { "l", "", "o" }, cb = tree_cb "edit" }, - { key = "h", cb = tree_cb "close_node" }, - { key = "v", cb = tree_cb "vsplit" }, - } + if not g.nvim_tree_bindings then + g.nvim_tree_bindings = { + { key = { "l", "", "o" }, cb = tree_cb "edit" }, + { key = "h", cb = tree_cb "close_node" }, + { key = "v", cb = tree_cb "vsplit" }, + } + end end -- +M.focus_or_close = function() + local view_status_ok, view = pcall(require, "nvim-tree.view") + if not view_status_ok then + return + end + local a = vim.api + + local curwin = a.nvim_get_current_win() + local curbuf = a.nvim_win_get_buf(curwin) + local bufnr = view.View.bufnr + local winnr = view.get_winnr() + + if view.win_open() then + if curwin == winnr and curbuf == bufnr then + view.close() + if package.loaded["bufferline.state"] then + require("bufferline.state").set_offset(0) + end + else + view.focus() + end + else + view.open() + if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") + end + end +end -- M.toggle_tree = function() local view_status_ok, view = pcall(require, "nvim-tree.view") @@ -77,12 +110,17 @@ M.toggle_tree = function() require("bufferline.state").set_offset(0) end else - if package.loaded["bufferline.state"] then - -- require'bufferline.state'.set_offset(31, 'File Explorer') - require("bufferline.state").set_offset(31, "") + if package.loaded["bufferline.state"] and options.builtin.nvimtree.side == "left" then + require("bufferline.state").set_offset(options.builtin.nvimtree.width + 1, "") end require("nvim-tree").toggle() end end -- +function M.change_tree_dir(dir) + if vim.g.loaded_tree then + require("nvim-tree.lib").change_dir(dir) + end +end +-- return M diff --git a/.config/nvim/lua/core/status_colors.lua b/.config/nvim/lua/core/status_colors.lua index 9a70ddd..71b6277 100644 --- a/.config/nvim/lua/core/status_colors.lua +++ b/.config/nvim/lua/core/status_colors.lua @@ -1,4 +1,4 @@ -O.plugin.galaxyline = { +options.builtin.galaxyline = { active = true, colors = { alt_bg = "#0A0A0A", diff --git a/.config/nvim/lua/core/telescope.lua b/.config/nvim/lua/core/telescope.lua index 48157bc..2b0a013 100644 --- a/.config/nvim/lua/core/telescope.lua +++ b/.config/nvim/lua/core/telescope.lua @@ -1,11 +1,12 @@ local M = {} +local Log = require "core.log" M.config = function() local status_ok, actions = pcall(require, "telescope.actions") if not status_ok then return end - O.plugin.telescope = { + options.builtin.telescope = { active = false, defaults = { find_command = { @@ -39,7 +40,7 @@ M.config = function() borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, color_devicons = true, use_less = true, - set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + set_env = { ["CoptionsLoptionsRTERM"] = "truecolor" }, -- default = nil, file_previewer = require("telescope.previewers").vim_buffer_cat.new, grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, @@ -61,7 +62,7 @@ M.config = function() -- [""] = trouble.open_with_trouble, -- [""] = false, -- [""] = actions.close, - -- Otherwise, just set the mapping to the function that you want it to be. + -- optionstherwise, just set the mapping to the function that you want it to be. -- [""] = actions.select_horizontal, -- Add up multiple actions -- You can perform as many actions in a row as you like @@ -88,10 +89,10 @@ end M.setup = function() local status_ok, telescope = pcall(require, "telescope") if not status_ok then + Log:get_default().error "Failed to load telescope" return end - telescope.setup(O.plugin.telescope) - vim.api.nvim_set_keymap("n", "f", ":Telescope find_files", { noremap = true, silent = true }) + telescope.setup(options.builtin.telescope) end return M diff --git a/.config/nvim/lua/core/terminal.lua b/.config/nvim/lua/core/terminal.lua index 0f93045..2793da2 100644 --- a/.config/nvim/lua/core/terminal.lua +++ b/.config/nvim/lua/core/terminal.lua @@ -1,8 +1,11 @@ local M = {} +local Log = require "core.log" +local utils = require "utils" + M.config = function() - O.plugin["terminal"] = { + options.builtin["terminal"] = { -- size can be a number or function which is passed the current terminal - size = 5, + size = 20, -- open_mapping = [[]], open_mapping = [[]], hide_numbers = true, -- hide the number column in toggleterm buffers @@ -11,7 +14,7 @@ M.config = function() shading_factor = 2, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light start_in_insert = true, insert_mappings = true, -- whether or not the open mapping applies in insert mode - persist_size = true, + persist_size = false, -- direction = 'vertical' | 'horizontal' | 'window' | 'float', direction = "float", close_on_exit = true, -- close the terminal window when the process exits @@ -26,43 +29,105 @@ M.config = function() border = "curved", -- width = , -- height = , - winblend = 3, + winblend = 0, highlights = { border = "Normal", background = "Normal", }, }, + -- Add executables on the config.lua + -- { exec, keymap, name} + -- options.builtin.terminal.execs = {{}} to overwrite + -- options.builtin.terminal.execs[#options.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} + execs = { + { "lazygit", "gg", "LazyGit" }, + }, } end M.setup = function() local status_ok, terminal = pcall(require, "toggleterm") if not status_ok then + Log:get_default().error "Failed to load toggleterm" print(terminal) return end + for _, exec in pairs(options.builtin.terminal.execs) do + require("core.terminal").add_exec(exec[1], exec[2], exec[3]) + end + terminal.setup(options.builtin.terminal) +end + +local function is_installed(exe) + return vim.fn.executable(exe) == 1 +end + +M.add_exec = function(exec, keymap, name) vim.api.nvim_set_keymap( "n", - "gg", - "lua require('core.terminal')._lazygit_toggle()", + "" .. keymap, + "lua require('core.terminal')._exec_toggle('" .. exec .. "')", { noremap = true, silent = true } ) - O.plugin.which_key.mappings["gg"] = "LazyGit" - terminal.setup(O.plugin.terminal) + options.builtin.which_key.mappings[keymap] = name end -local function is_installed(exe) - return vim.fn.executable(exe) == 1 +M._split = function(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do + table.insert(t, str) + end + return t end -M._lazygit_toggle = function() - if is_installed "lazygit" ~= true then - print "Please install lazygit. Check documentation for more information" +M._exec_toggle = function(exec) + local binary = M._split(exec)[1] + if is_installed(binary) ~= true then + print("Please install executable " .. binary .. ". Check documentation for more information") return end local Terminal = require("toggleterm.terminal").Terminal - local lazygit = Terminal:new { cmd = "lazygit", hidden = true } - lazygit:toggle() + local exec_term = Terminal:new { cmd = exec, hidden = true } + exec_term:toggle() +end + +local function get_log_path(name) + --handle custom paths not managed by Plenary.log + local logger = require "core.log" + local file + if name == "nvim" then + file = CACHE_PATH .. "/log" + else + file = logger:new({ plugin = name }):get_path() + end + if utils.is_file(file) then + return file + end +end + +---Toggles a log viewer according to log.viewer.layout_config +---@param name can be the name of any of the managed logs, e,g. "lunarvim" or the default ones {"nvim", "lsp", "packer.nvim"} +M.toggle_log_view = function(name) + local logfile = get_log_path(name) + if not logfile then + return + end + local term_opts = vim.tbl_deep_extend("force", options.builtin.terminal, { + cmd = options.log.viewer.cmd .. " " .. logfile, + open_mapping = options.log.viewer.layout_config.open_mapping, + direction = options.log.viewer.layout_config.direction, + -- TODO: this might not be working as expected + size = options.log.viewer.layout_config.size, + float_opts = options.log.viewer.layout_config.float_opts, + }) + + local Terminal = require("toggleterm.terminal").Terminal + local log_view = Terminal:new(term_opts) + -- require("core.log"):get_default().debug("term", vim.inspect(term_opts)) + log_view:toggle() end return M diff --git a/.config/nvim/lua/core/treesitter.lua b/.config/nvim/lua/core/treesitter.lua index 2b7a2d5..ba70b70 100644 --- a/.config/nvim/lua/core/treesitter.lua +++ b/.config/nvim/lua/core/treesitter.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.treesitter = { + options.builtin.treesitter = { ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -18,7 +19,7 @@ M.config = function() }, -- indent = {enable = true, disable = {"python", "html", "javascript"}}, -- TODO seems to be broken - indent = { enable = { "javascriptreact" } }, + indent = { enable = true, disable = { "yaml" } }, autotag = { enable = false }, textobjects = { swap = { @@ -59,129 +60,16 @@ M.config = function() max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int }, } - - -- -- TODO refactor treesitter - -- -- @usage pass a table with your desired languages - -- treesitter = { - -- ensure_installed = "all", - -- ignore_install = { "haskell" }, - -- highlight = { enabled = true }, - -- -- The below are for treesitter-textobjects plugin - -- textobj_prefixes = { - -- goto_next = "]", -- Go to next - -- goto_previous = "[", -- Go to previous - -- inner = "i", -- Select inside - -- outer = "a", -- Selct around - -- swap = "a", -- Swap with next - -- }, - -- textobj_suffixes = { - -- -- Start and End respectively for the goto keys - -- -- for other keys it only uses the first - -- ["function"] = { "f", "F" }, - -- ["class"] = { "m", "M" }, - -- ["parameter"] = { "a", "A" }, - -- ["block"] = { "k", "K" }, - -- ["conditional"] = { "i", "I" }, - -- ["call"] = { "c", "C" }, - -- ["loop"] = { "l", "L" }, - -- ["statement"] = { "s", "S" }, - -- ["comment"] = { "/", "?" }, - -- }, - -- -- The below is for treesitter hint textobjects plugin - -- hint_labels = { "h", "j", "f", "d", "n", "v", "s", "l", "a" }, - -- }, end M.setup = function() - -- TODO: refacor this whole file and treesitter in general - -- if not package.loaded['nvim-treesitter'] then return end - -- - -- Custom parsers - -- local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - -- parser_config.make = { - -- install_info = { - -- url = "https://github.com/alemuller/tree-sitter-make", -- local path or git repo - -- files = {"src/parser.c"}, - -- requires_generate_from_grammar = true - -- } - -- } - -- parser_config.just = { - -- install_info = { - -- url = "~/dev/tree-sitter-just", -- local path or git repo - -- files = {"src/parser.c"} - -- } - -- -- filetype = "just", -- if filetype does not agrees with parser name - -- -- used_by = {"bar", "baz"} -- additional filetypes that use this parser - -- } - -- Custom text objects - -- local textobj_prefixes = O.treesitter.textobj_prefixes - -- local textobj_suffixes = O.treesitter.textobj_suffixes - -- local textobj_sel_keymaps = {} - -- local textobj_swap_keymaps = {} - -- local textobj_move_keymaps = { - -- enable = O.plugin.ts_textobjects, - -- set_jumps = true, -- whether to set jumps in the jumplist - -- goto_next_start = {}, - -- goto_next_end = {}, - -- goto_previous_start = {}, - -- goto_previous_end = {}, - -- } - -- for obj, suffix in pairs(textobj_suffixes) do - -- if textobj_prefixes["goto_next"] ~= nil then - -- textobj_move_keymaps["goto_next_start"][textobj_prefixes["goto_next"] .. suffix[1]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_next_end"][textobj_prefixes["goto_next"] .. suffix[2]] = "@" .. obj .. ".outer" - -- end - -- if textobj_prefixes["goto_previous"] ~= nil then - -- textobj_move_keymaps["goto_previous_start"][textobj_prefixes["goto_previous"] .. suffix[2]] = "@" .. obj .. ".outer" - -- textobj_move_keymaps["goto_previous_end"][textobj_prefixes["goto_previous"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["inner"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["inner"] .. suffix[1]] = "@" .. obj .. ".inner" - -- end - -- if textobj_prefixes["outer"] ~= nil then - -- textobj_sel_keymaps[textobj_prefixes["outer"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- - -- if textobj_prefixes["swap"] ~= nil then - -- textobj_swap_keymaps[textobj_prefixes["swap"] .. suffix[1]] = "@" .. obj .. ".outer" - -- end - -- end - -- vim.g.ts_hint_textobject_keys = O.treesitter.hint_labels -- Requires https://github.com/mfussenegger/nvim-ts-hint-textobject/pull/2 - -- - -- -- Add which key menu entries - -- local status, wk = pcall(require, "which-key") - -- if status then - -- local normal = { - -- mode = "n", -- Normal mode - -- } - -- local operators = { - -- mode = "o", -- Operator mode - -- } - -- wk.register(textobj_sel_keymaps, operators) - -- wk.register({ - -- ["m"] = "Hint Objects", - -- ["."] = "Textsubject", - -- [";"] = "Textsubject-big", - -- }, operators) - -- wk.register(textobj_swap_keymaps, normal) - -- wk.register({ - -- [textobj_prefixes["swap"]] = "Swap", - -- -- [textobj_prefixes["goto_next"]] = "Jump [", - -- -- [textobj_prefixes["goto_previous"]] = "Jump ]" - -- }, normal) - -- wk.register(textobj_move_keymaps["goto_next_start"], normal) - -- wk.register(textobj_move_keymaps["goto_next_end"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_start"], normal) - -- wk.register(textobj_move_keymaps["goto_previous_end"], normal) - -- end - local status_ok, treesitter_configs = pcall(require, "nvim-treesitter.configs") if not status_ok then + Log:get_default().error "Failed to load nvim-treesitter.configs" return end - treesitter_configs.setup(O.treesitter) + treesitter_configs.setup(options.builtin.treesitter) end return M diff --git a/.config/nvim/lua/core/which-key.lua b/.config/nvim/lua/core/which-key.lua index dabf832..6227a8e 100644 --- a/.config/nvim/lua/core/which-key.lua +++ b/.config/nvim/lua/core/which-key.lua @@ -1,6 +1,7 @@ local M = {} +local Log = require "core.log" M.config = function() - O.plugin.which_key = { + options.builtin.which_key = { active = false, setup = { plugins = { @@ -58,7 +59,7 @@ M.config = function() -- NOTE: Prefer using : over as the latter avoids going back in normal-mode. -- see https://neovim.io/doc/user/map.html#:map-cmd vmappings = { - ["/"] = { ":CommentToggle", "Comment" }, + ["k"] = { ":CommentToggle", "Comment" }, }, mappings = { ["w"] = { "w!", "Save" }, @@ -68,14 +69,36 @@ M.config = function() ["e"] = { "lua require'core.nvimtree'.toggle_tree()", "Explorer" }, ["f"] = { "Telescope find_files", "Find File" }, ["n"] = { 'let @/=""', "No Highlight" }, - ["h"] = { "vsplit", "Vertical Split" }, - ["v"] = { 'split', "Horizontal Split" }, + b = { + name = "Buffers", + j = { "BufferPick", "jump to buffer" }, + f = { "Telescope buffers", "Find buffer" }, + w = { "BufferWipeout", "wipeout buffer" }, + e = { + "BufferCloseAllButCurrent", + "close all but current buffer", + }, + h = { "BufferCloseBuffersLeft", "close all buffers to the left" }, + l = { + "BufferCloseBuffersRight", + "close all BufferLines to the right", + }, + D = { + "BufferOrderByDirectory", + "sort BufferLines automatically by directory", + }, + L = { + "BufferOrderByLanguage", + "sort BufferLines automatically by language", + }, + }, p = { name = "Packer", c = { "PackerCompile", "Compile" }, i = { "PackerInstall", "Install" }, - r = { "lua require('utils').reload_config()", "Reload" }, + r = { "lua require('utils').reload_lv_config()", "Reload" }, s = { "PackerSync", "Sync" }, + S = { "PackerStatus", "Status" }, u = { "PackerUpdate", "Update" }, }, @@ -119,18 +142,24 @@ M.config = function() "Telescope lsp_workspace_diagnostics", "Workspace Diagnostics", }, - f = { "silent FormatWrite", "Format" }, + -- f = { "silent FormatWrite", "Format" }, + f = { "lua vim.lsp.buf.formatting()", "Format" }, i = { "LspInfo", "Info" }, j = { - "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})", + "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = options.lsp.popup_border}})", "Next Diagnostic", }, k = { - "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})", + "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = options.lsp.popup_border}})", "Prev Diagnostic", }, - l = { "silent lua require('lint').try_lint()", "Lint" }, - q = { "Telescope quickfix", "Quickfix" }, + p = { + name = "Peek", + d = { "lua require('lsp.peek').Peek('definition')", "Definition" }, + t = { "lua require('lsp.peek').Peek('typeDefinition')", "Type Definition" }, + i = { "lua require('lsp.peek').Peek('implementation')", "Implementation" }, + }, + q = { "lua vim.lsp.diagnostic.set_loclist()", "Quickfix" }, r = { "lua vim.lsp.buf.rename()", "Rename" }, s = { "Telescope lsp_document_symbols", "Document Symbols" }, S = { @@ -138,6 +167,14 @@ M.config = function() "Workspace Symbols", }, }, + I = { + name = "+nvim", + k = { "lua require('keymappings').print()", "View nvim's default keymappings" }, + i = { + "lua require('core.info').toggle_popup(vim.bo.filetype)", + "Toggle nvim Info", + }, + }, s = { name = "Search", @@ -170,32 +207,22 @@ M.setup = function() -- end local status_ok, which_key = pcall(require, "which-key") if not status_ok then + Log:get_default "Failed to load whichkey" return end - which_key.setup(O.plugin.which_key.setup) - - local opts = O.plugin.which_key.opts - local vopts = O.plugin.which_key.vopts + which_key.setup(options.builtin.which_key.setup) - local mappings = O.plugin.which_key.mappings - local vmappings = O.plugin.which_key.vmappings + local opts = options.builtin.which_key.opts + local vopts = options.builtin.which_key.vopts - -- if O.plugin.ts_playground.active then - -- vim.api.nvim_set_keymap("n", "Th", ":TSHighlightCapturesUnderCursor", { noremap = true, silent = true }) - -- mappings[""] = "Highlight Capture" - -- end - - if O.plugin.zen.active then - vim.api.nvim_set_keymap("n", "z", ":ZenMode", { noremap = true, silent = true }) - mappings["z"] = "Zen" - end + local mappings = options.builtin.which_key.mappings + local vmappings = options.builtin.which_key.vmappings local wk = require "which-key" wk.register(mappings, opts) wk.register(vmappings, vopts) - wk.register(O.user_which_key, opts) end return M diff --git a/.config/nvim/lua/core/zen.lua b/.config/nvim/lua/core/zen.lua deleted file mode 100644 index 99a5d76..0000000 --- a/.config/nvim/lua/core/zen.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} -M.config = function() - O.plugin["zen"] = { - window = { - backdrop = 1, - height = 0.85, -- height of the Zen window - options = { - signcolumn = "no", -- disable signcolumn - number = false, -- disable number column - relativenumber = false, -- disable relative numbers - -- cursorline = false, -- disable cursorline - -- cursorcolumn = false, -- disable cursor column - -- foldcolumn = "0", -- disable fold column - -- list = false, -- disable whitespace characters - }, - }, - plugins = { - gitsigns = { enabled = false }, -- disables git signs - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - }, - } -end - -M.setup = function() - local status_ok, zen_mode = pcall(require, "zen-mode") - if not status_ok then - return - end - zen_mode.setup(O.plugin.zen) -end - -return M -- cgit v1.2.3-70-g09d2