diff options
| author | christianchiarulli <[email protected]> | 2021-08-11 16:33:41 -0400 | 
|---|---|---|
| committer | christianchiarulli <[email protected]> | 2021-08-11 16:33:41 -0400 | 
| commit | 83013c0d4f1467f546c38719c61909decfcb8151 (patch) | |
| tree | 143773ea73c64d953db699e6e621926e44653fc2 /lua/core | |
| parent | f6407e0bdb9c2875bc8f186929ce183af391b2a9 (diff) | |
| parent | 5a7630cac761e91335d2f25cb07a81271569c791 (diff) | |
Merge branch 'rolling' of github.com:ChristianChiarulli/LunarVim
Diffstat (limited to 'lua/core')
| -rw-r--r-- | lua/core/autocmds.lua | 16 | ||||
| -rw-r--r-- | lua/core/autopairs.lua | 5 | ||||
| -rw-r--r-- | lua/core/bufferline.lua | 22 | ||||
| -rw-r--r-- | lua/core/commands.lua | 2 | ||||
| -rw-r--r-- | lua/core/compe.lua | 65 | ||||
| -rw-r--r-- | lua/core/dap.lua | 4 | ||||
| -rw-r--r-- | lua/core/dashboard.lua | 9 | ||||
| -rw-r--r-- | lua/core/galaxyline.lua | 12 | ||||
| -rw-r--r-- | lua/core/gitsigns.lua | 3 | ||||
| -rw-r--r-- | lua/core/info.lua | 222 | ||||
| -rw-r--r-- | lua/core/log.lua | 29 | ||||
| -rw-r--r-- | lua/core/nvimtree.lua | 54 | ||||
| -rw-r--r-- | lua/core/rooter.lua | 15 | ||||
| -rw-r--r-- | lua/core/telescope.lua | 10 | ||||
| -rw-r--r-- | lua/core/terminal.lua | 50 | ||||
| -rw-r--r-- | lua/core/treesitter.lua | 2 | ||||
| -rw-r--r-- | lua/core/which-key.lua | 40 | 
17 files changed, 492 insertions, 68 deletions
| diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 89590454..91278544 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -3,6 +3,11 @@ local autocommands = {}  lvim.autocommands = {    _general_settings = {      { +      "Filetype", +      "*", +      "lua require('utils.ft').do_filetype(vim.fn.expand(\"<amatch>\"))", +    }, +    {        "TextYankPost",        "*",        "lua require('vim.highlight').on_yank({higroup = 'Search', timeout = 200})", @@ -27,7 +32,7 @@ lvim.autocommands = {        "*",        "setlocal formatoptions-=c formatoptions-=r formatoptions-=o",      }, -    { "BufWritePost", "lv-config.lua", "lua require('utils').reload_lv_config()" }, +    { "BufWritePost", USER_CONFIG_PATH, "lua require('utils').reload_lv_config()" },      {        "FileType",        "qf", @@ -51,13 +56,14 @@ lvim.autocommands = {    --     {'BufWinEnter', '.gmi', 'setlocal filetype=markdown'}, {'BufRead', '*.gmi', 'setlocal filetype=markdown'},    --     {'BufNewFile', '*.gmi', 'setlocal filetype=markdown'}    -- }, +  _git = { +    { "FileType", "gitcommit", "setlocal wrap" }, +    { "FileType", "gitcommit", "setlocal spell" }, +  },    _markdown = {      { "FileType", "markdown", "setlocal wrap" },      { "FileType", "markdown", "setlocal spell" },    }, -  _tab_bindings = { -    { "FileType", "*", "lua require'core.compe'.set_tab_keybindings()" }, -  },    _buffer_bindings = {      { "FileType", "floaterm", "nnoremap <silent> <buffer> q :q<CR>" },    }, @@ -66,7 +72,7 @@ lvim.autocommands = {      { "VimResized", "*", "wincmd =" },    },    _packer_compile = { -    -- will cause split windows to be resized evenly if main window is resized +    -- will run PackerCompile after writing plugins.lua      { "BufWritePost", "plugins.lua", "PackerCompile" },    },    _general_lsp = { diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index f0111db6..a5f21a1b 100644 --- a/lua/core/autopairs.lua +++ b/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" @@ -25,9 +27,10 @@ MUtils.completion_confirm = function()  end  if package.loaded["compe"] then +  local map_complete_optional = vim.bo.filetype ~= "tex"    require("nvim-autopairs.completion.compe").setup {      map_cr = true, --  map <CR> on insert mode -    map_complete = true, -- it will auto insert `(` after select function or method item +    map_complete = map_complete_optional, -- it will auto insert `(` after select function or method item    }  end diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua index c5677580..8989ce21 100644 --- a/lua/core/bufferline.lua +++ b/lua/core/bufferline.lua @@ -1,2 +1,20 @@ -vim.api.nvim_set_keymap("n", "<S-l>", ":BufferNext<CR>", { noremap = true, silent = true }) -vim.api.nvim_set_keymap("n", "<S-h>", ":BufferPrevious<CR>", { noremap = true, silent = true }) +local M = {} + +M.config = function() +  lvim.builtin.bufferline = { +    active = true, +    keymap = { +      normal_mode = { +        ["<S-l>"] = ":BufferNext<CR>", +        ["<S-h>"] = ":BufferPrevious<CR>", +      }, +    }, +  } +end + +M.setup = function() +  local keymap = require "keymappings" +  keymap.append_to_defaults(lvim.builtin.bufferline.keymap) +end + +return M diff --git a/lua/core/commands.lua b/lua/core/commands.lua index c42b385d..22170c85 100644 --- a/lua/core/commands.lua +++ b/lua/core/commands.lua @@ -10,6 +10,8 @@ M.defaults = {      endif    endfunction    ]], +  -- :LvimInfo +  [[command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype)]],  }  M.load = function(commands) diff --git a/lua/core/compe.lua b/lua/core/compe.lua index 801e2dd8..c2f97e27 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    lvim.builtin.compe = {      enabled = true, @@ -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,8 +39,22 @@ M.config = function()        emoji = { kind = " ﲃ  (Emoji)", filetypes = { "markdown", "text" } },        -- for emoji press : (idk if that in compe tho)      }, -    -- FileTypes in this list won't trigger auto-complete when TAB is pressed.  Hitting TAB will insert a tab character -    exclude_filetypes = { "md", "markdown", "mdown", "mkd", "mkdn", "mdwn", "text", "txt" }, + +    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 @@ -40,6 +63,7 @@ M.setup = function()    local status_ok, compe = pcall(require, "compe")    if not status_ok then +    Log:get_default().error "Failed to load compe"      return    end @@ -64,12 +88,13 @@ M.setup = function()    _G.tab_complete = function()      if vim.fn.pumvisible() == 1 then        return t "<C-n>" -    elseif vim.fn.call("vsnip#available", { 1 }) == 1 then -      return t "<Plug>(vsnip-expand-or-jump)" +    elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then +      return t "<Plug>(vsnip-jump-next)"      elseif check_back_space() then        return t "<Tab>"      else -      return vim.fn["compe#complete"]() +      -- return vim.fn["compe#complete"]() -- < use this if you want <tab> to always offer completion +      return t "<Tab>"      end    end @@ -83,29 +108,13 @@ M.setup = function()      end    end -  vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true }) -  -- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true }) -  vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true }) -  vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true }) -  vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true }) -end +  local keymap = require "keymappings" +  keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts) -local is_excluded = function(file_type) -  for _, type in ipairs(lvim.builtin.compe.exclude_filetypes) do -    if type == file_type then -      return true -    end -  end -  return false +  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 })  end -M.set_tab_keybindings = function() -  local file_type = vim.fn.expand "%:e" -  if is_excluded(file_type) == false then -    vim.api.nvim_buf_set_keymap(0, "i", "<Tab>", "v:lua.tab_complete()", { expr = true }) -    vim.api.nvim_buf_set_keymap(0, "s", "<Tab>", "v:lua.tab_complete()", { expr = true }) -    vim.api.nvim_buf_set_keymap(0, "i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) -    vim.api.nvim_buf_set_keymap(0, "s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true }) -  end -end  return M diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 30e3aef9..4e21cc4c 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    lvim.builtin.dap = {      active = false, @@ -14,6 +15,7 @@ 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 @@ -34,7 +36,7 @@ M.setup = function()      p = { "<cmd>lua require'dap'.pause.toggle()<cr>", "Pause" },      r = { "<cmd>lua require'dap'.repl.toggle()<cr>", "Toggle Repl" },      s = { "<cmd>lua require'dap'.continue()<cr>", "Start" }, -    q = { "<cmd>lua require'dap'.stop()<cr>", "Quit" }, +    q = { "<cmd>lua require'dap'.close()<cr>", "Quit" },    }  end diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 8d196458..d5e5bfe9 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -43,12 +43,11 @@ M.config = function()        },        d = {          description = { "  Settings           " }, -        -- command = ":e " .. CONFIG_PATH .. "/lv-config.lua", -        command = ":e ~/.config/lvim/lv-config.lua", +        command = ":e " .. USER_CONFIG_PATH,        },      }, -    footer = { "chrisatmachine.com" }, +    footer = { "lunarvim.org" },    }  end @@ -73,7 +72,7 @@ M.setup = function()    vim.api.nvim_exec(      [[ -    let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins '] +    let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins  ']  ]],      false    ) @@ -85,7 +84,7 @@ M.setup = function()    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", diff --git a/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index aafe99bc..ee0a317d 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -1,8 +1,10 @@  -- 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 @@ -202,21 +204,19 @@ table.insert(gls.right, {  local function get_attached_provider_name(msg)    msg = msg or "LSP Inactive" - -  local buf_ft = vim.bo.filetype    local buf_clients = vim.lsp.buf_get_clients()    if next(buf_clients) == nil then      return msg    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, lvim.lang[buf_ft].linters[1]) -      table.insert(buf_client_names, lvim.lang[buf_ft].formatter.exe) -    else +    if client.name ~= "null-ls" then        table.insert(buf_client_names, client.name)      end    end +  vim.list_extend(buf_client_names, null_ls_providers)    return table.concat(buf_client_names, ", ")  end diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index 2a5060be..9e023762 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    lvim.builtin.gitsigns = {      signs = { @@ -44,13 +45,13 @@ 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(lvim.builtin.gitsigns) diff --git a/lua/core/info.lua b/lua/core/info.lua new file mode 100644 index 00000000..56fc3ca2 --- /dev/null +++ b/lua/core/info.lua @@ -0,0 +1,222 @@ +local M = {} +local u = require "utils" +local null_ls_handler = require "lsp.null-ls" +local indent = "  " + +M.banner = { +  " ", +  indent +    .. "⠀⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀   ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  ⠀⠀     ⠀⠀⠀   ⠀⠀ ⣺⡿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀", +  indent +    .. "⠀⣿⠇⠀⠀⠀⠀⠀⣤⡄⠀⠀⢠⣤⡄⠀.⣠⣤⣤⣤⡀⠀⠀⢀⣤⣤⣤⣤⡄⠀⠀⠀⣤⣄⣤⣤⣤⠀⠀ ⣿⣯  ⣿⡟⠀   ⣤⣤⠀⠀⠀⠀⣠⣤⣤⣤⣄⣤⣤", +  indent +    .. "⢠⣿⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⣸⣿⠁⠀⣿⣿⠉⠀⠈⣿⡇⠀⠀⠛⠋⠀⠀⢹⣿⠀⠀⠀⣿⠏⠀⠸⠿⠃⠀⣿⣿⠀⣰⡟⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡟⢸⣿⡇⢀⣿", +  indent +    .. "⣸⡇⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⣿⡟⠀⢠⣿⡇⠀⠀⢰⣿⡇⠀⣰⣾⠟⠛⠛⣻⡇⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⢻⣿⢰⣿⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⢸⣿⠇⢸⣿⠀⢸⡏", +  indent +    .. "⣿⣧⣤⣤⣤⡄⠀⠘⣿⣤⣤⡤⣿⠇⠀⢸⣿⠁⠀⠀⣼⣿⠀⠀⢿⣿⣤⣤⠔⣿⠃⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⢸⣿⣿⠋⠀⠀⠀⢠⣤⣤⣿⣥⣤⡄⠀⣼⣿⠀⣸⡏⠀⣿⠃", +  indent +    .. "⠉⠉⠉⠉⠉⠁⠀⠀⠈⠉⠉⠀⠉⠀⠀⠈⠉⠀⠀⠀⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠈⠉⠉⠉⠉⠉⠁⠀⠉⠁⠀⠉⠁⠀⠉⠀", +  "", +} + +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 { +    indent +      .. "───────────────────────────────────────────────────────────────────", +    "", +    indent .. " HINT ", +    "", +    indent .. "* List of supported formatters: " .. str_list(supported_formatters), +    indent .. "* Configured formatter needs to be installed and executable.", +    indent .. "* Enable installed formatter(s) with following config in ~/.config/lvim/config.lua", +    "", +    indent .. "  lvim.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 { +    indent +      .. "───────────────────────────────────────────────────────────────────", +    "", +    indent .. " HINT ", +    "", +    indent .. "* List of supported linters: " .. str_list(supported_linters), +    indent .. "* Configured linter needs to be installed and executable.", +    indent .. "* Enable installed linter(s) with following config in ~/.config/lvim/config.lua", +    "", +    indent +      .. "  lvim.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.9 +  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.min(math.ceil(vim.o.lines * height_percentage), #buf_lines) +  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.style = "minimal" +  opts.border = "rounded" +  --[[ +  opts.border = { +    lvim.builtin.telescope.defaults.borderchars[5], -- "┌", +    lvim.builtin.telescope.defaults.borderchars[3], -- "-", +    lvim.builtin.telescope.defaults.borderchars[6], -- "┐", +    lvim.builtin.telescope.defaults.borderchars[2], -- "|", +    lvim.builtin.telescope.defaults.borderchars[7], -- "┘", +    lvim.builtin.telescope.defaults.borderchars[3], -- "-", +    lvim.builtin.telescope.defaults.borderchars[8], -- "└", +    lvim.builtin.telescope.defaults.borderchars[4], -- "|", +  } +  --]] + +  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 + +local function tbl_set_highlight(terms, highlight_group) +  if type(terms) ~= "table" then +    return +  end + +  for _, v in pairs(terms) do +    vim.cmd('let m=matchadd("' .. highlight_group .. '", "' .. v .. '")') +  end +end + +function M.toggle_popup(ft) +  local client = u.get_active_client_by_ft(ft) +  local is_client_active = false +  local client_enabled_caps = {} +  local client_name = "" +  local client_id = 0 +  local document_formatting = false +  local missing_linters = {} +  local missing_formatters = {} +  local num_caps = 0 +  local null_ls_providers = null_ls_handler.get_registered_providers_by_filetype(ft) +  if client ~= nil then +    is_client_active = not client.is_stopped() +    client_enabled_caps = require("lsp").get_ls_capabilities(client.id) +    num_caps = vim.tbl_count(client_enabled_caps) +    client_name = client.name +    client_id = client.id +    document_formatting = client.resolved_capabilities.document_formatting +  end +  if lvim.lang[ft] ~= nil then +    missing_linters = lvim.lang[ft].linters._failed_requests or {} +    missing_formatters = lvim.lang[ft].formatters._failed_requests or {} +  end + +  local buf_lines = {} +  vim.list_extend(buf_lines, M.banner) + +  local header = { +    indent .. "Detected filetype:     " .. tostring(ft), +    indent .. "Treesitter active:     " .. tostring(next(vim.treesitter.highlighter.active) ~= nil), +    "", +  } +  vim.list_extend(buf_lines, header) + +  local lsp_info = { +    indent .. "Language Server Protocol (LSP) info", +    indent .. "* Associated server:   " .. client_name, +    indent .. "* Active:              " .. tostring(is_client_active) .. " (id: " .. tostring(client_id) .. ")", +    indent .. "* Supports formatting: " .. tostring(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 = { +    indent .. "Formatters and linters", +    indent .. "* 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 = { +      indent .. "* 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 = { +      indent .. "* Missing linters:      " .. table.concat(missing_linters, "  , ") .. "  ", +    } +    vim.list_extend(buf_lines, missing_linters_status) +  end + +  vim.list_extend(buf_lines, { "" }) + +  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() +    vim.cmd [[highlight LvimInfoIdentifier gui=bold]] +    vim.cmd [[highlight link LvimInfoHeader Type]] +    vim.cmd [[let m=matchadd("DashboardHeader", "Language Server Protocol (LSP) info")]] +    vim.cmd [[let m=matchadd("DashboardHeader", "Formatters and linters")]] +    vim.cmd('let m=matchadd("LvimInfoIdentifier", " ' .. ft .. '$")') +    vim.cmd 'let m=matchadd("string", "true")' +    vim.cmd 'let m=matchadd("error", "false")' +    tbl_set_highlight(null_ls_providers, "LvimInfoIdentifier") +    tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") +    tbl_set_highlight(missing_linters, "LvimInfoIdentifier") +    -- tbl_set_highlight(u.get_supported_formatters_by_filetype(ft), "LvimInfoIdentifier") +    -- tbl_set_highlight(u.get_supported_linters_by_filetype(ft), "LvimInfoIdentifier") +    vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') +  end + +  return M.create_simple_popup(buf_lines, set_syntax_hl) +end +return M diff --git a/lua/core/log.lua b/lua/core/log.lua new file mode 100644 index 00000000..5dd5622e --- /dev/null +++ b/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 = "lunarvim", level = lvim.log.level } +end + +return Log diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index dd1f4f36..4d15b1b5 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,8 +1,10 @@  local M = {} +local Log = require "core.log"  --  M.config = function()    lvim.builtin.nvimtree = {      side = "left", +    width = 30,      show_icons = {        git = 1,        folders = 1, @@ -48,6 +50,7 @@ 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 @@ -58,13 +61,44 @@ M.setup = function()    local tree_cb = nvim_tree_config.nvim_tree_callback -  g.nvim_tree_bindings = { -    { key = { "l", "<CR>", "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", "<CR>", "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 lvim.builtin.nvimtree.side == "left" then +      -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') +      require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") +    end +  end +end  --  M.toggle_tree = function()    local view_status_ok, view = pcall(require, "nvim-tree.view") @@ -78,11 +112,17 @@ M.toggle_tree = function()      end    else      if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then -      -- require'bufferline.state'.set_offset(31, 'File Explorer') -      require("bufferline.state").set_offset(31, "") +      -- require'bufferline.state'.set_offset(lvim.builtin.nvimtree.width + 1, 'File Explorer') +      require("bufferline.state").set_offset(lvim.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/lua/core/rooter.lua b/lua/core/rooter.lua new file mode 100644 index 00000000..8ebdf7cc --- /dev/null +++ b/lua/core/rooter.lua @@ -0,0 +1,15 @@ +local M = {} +function M.config() +  lvim.builtin.rooter = { +    --- This is on by default since it's currently the expected behavior. +    ---@usage set to false to disable vim-rooter. +    active = true, +    silent_chdir = 1, +    manual_only = 0, +  } +end +function M.setup() +  vim.g.rooter_silent_chdir = lvim.builtin.rooter.silent_chdir +  vim.g.rooter_manual_only = lvim.builtin.rooter.manual_only +end +return M diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 65760d6c..f4d154b0 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    local status_ok, actions = pcall(require, "telescope.actions")    if not status_ok then @@ -40,11 +41,11 @@ M.config = function()        -- buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker,        mappings = {          i = { -          ["<C-n>"] = actions.cycle_history_next, -          ["<C-p>"] = actions.cycle_history_prev, +          ["<C-n>"] = actions.move_selection_next, +          ["<C-p>"] = actions.move_selection_previous,            ["<C-c>"] = actions.close, -          ["<C-j>"] = actions.move_selection_next, -          ["<C-k>"] = actions.move_selection_previous, +          ["<C-j>"] = actions.cycle_history_next, +          ["<C-k>"] = actions.cycle_history_prev,            ["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,            ["<CR>"] = actions.select_default + actions.center,            -- To disable a keymap, put [map] = false @@ -79,6 +80,7 @@ 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(lvim.builtin.telescope) diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 015341df..818038fd 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,8 +1,11 @@  local M = {} +local Log = require "core.log" +local utils = require "utils" +  M.config = function()    lvim.builtin["terminal"] = {      -- size can be a number or function which is passed the current terminal -    size = 5, +    size = 20,      -- open_mapping = [[<c-\>]],      open_mapping = [[<c-t>]],      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 @@ -32,17 +35,20 @@ M.config = function()          background = "Normal",        },      }, -    -- Add executables on the lv-config file +    -- Add executables on the config.lua      -- { exec, keymap, name}      -- lvim.builtin.terminal.execs = {{}} to overwrite      -- lvim.builtin.terminal.execs[#lvim.builtin.terminal.execs+1] = {"gdb", "tg", "GNU Debugger"} -    execs = { { "lazygit", "gg", "LazyGit" } }, +    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 @@ -88,4 +94,40 @@ M._exec_toggle = function(exec)    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", lvim.builtin.terminal, { +    cmd = lvim.log.viewer.cmd .. " " .. logfile, +    open_mapping = lvim.log.viewer.layout_config.open_mapping, +    direction = lvim.log.viewer.layout_config.direction, +    -- TODO: this might not be working as expected +    size = lvim.log.viewer.layout_config.size, +    float_opts = lvim.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/lua/core/treesitter.lua b/lua/core/treesitter.lua index cfc58bb7..0a8a2ff2 100644 --- a/lua/core/treesitter.lua +++ b/lua/core/treesitter.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    lvim.builtin.treesitter = {      ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages @@ -64,6 +65,7 @@ end  M.setup = function()    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 diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 9d4e7744..96f3a8f7 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,4 +1,5 @@  local M = {} +local Log = require "core.log"  M.config = function()    lvim.builtin.which_key = {      active = false, @@ -67,7 +68,7 @@ M.config = function()        ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" },        ["e"] = { "<cmd>lua require'core.nvimtree'.toggle_tree()<CR>", "Explorer" },        ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" }, -      ["h"] = { '<cmd>let @/=""<CR>', "No Highlight" }, +      ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" },        b = {          name = "Buffers",          j = { "<cmd>BufferPick<cr>", "jump to buffer" }, @@ -97,6 +98,7 @@ M.config = function()          i = { "<cmd>PackerInstall<cr>", "Install" },          r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" },          s = { "<cmd>PackerSync<cr>", "Sync" }, +        S = { "<cmd>PackerStatus<cr>", "Status" },          u = { "<cmd>PackerUpdate<cr>", "Update" },        }, @@ -151,8 +153,13 @@ M.config = function()            "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<cr>",            "Prev Diagnostic",          }, -        l = { "<cmd>silent lua require('lint').try_lint()<cr>", "Lint" }, -        q = { "<cmd>Telescope quickfix<cr>", "Quickfix" }, +        p = { +          name = "Peek", +          d = { "<cmd>lua require('lsp.peek').Peek('definition')<cr>", "Definition" }, +          t = { "<cmd>lua require('lsp.peek').Peek('typeDefinition')<cr>", "Type Definition" }, +          i = { "<cmd>lua require('lsp.peek').Peek('implementation')<cr>", "Implementation" }, +        }, +        q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Quickfix" },          r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },          s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },          S = { @@ -160,7 +167,31 @@ M.config = function()            "Workspace Symbols",          },        }, - +      L = { +        name = "+LunarVim", +        k = { "<cmd>lua require('keymappings').print()<cr>", "View LunarVim's default keymappings" }, +        i = { +          "<cmd>lua require('core.info').toggle_popup(vim.bo.filetype)<cr>", +          "Toggle LunarVim Info", +        }, +        l = { +          name = "+logs", +          d = { +            "<cmd>lua require('core.terminal').toggle_log_view('lunarvim')<cr>", +            "view default log", +          }, +          D = { "<cmd>edit ~/.cache/nvim/lunarvim.log<cr>", "Open the default logfile" }, +          n = { "<cmd>lua require('core.terminal').toggle_log_view('lsp')<cr>", "view lsp log" }, +          N = { "<cmd>edit ~/.cache/nvim/log<cr>", "Open the Neovim logfile" }, +          l = { "<cmd>lua require('core.terminal').toggle_log_view('nvim')<cr>", "view neovim log" }, +          L = { "<cmd>edit ~/.cache/nvim/lsp.log<cr>", "Open the LSP logfile" }, +          p = { +            "<cmd>lua require('core.terminal').toggle_log_view('packer.nvim')<cr>", +            "view packer log", +          }, +          P = { "<cmd>edit ~/.cache/nvim/packer.nvim.log<cr>", "Open the Packer logfile" }, +        }, +      },        s = {          name = "Search",          b = { "<cmd>Telescope git_branches<cr>", "Checkout branch" }, @@ -192,6 +223,7 @@ 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 | 
