diff options
Diffstat (limited to 'lua')
42 files changed, 2215 insertions, 1576 deletions
diff --git a/lua/lv-utils/init.lua b/lua/core/autocmds.lua index d2d23cfb..9280da9e 100644 --- a/lua/lv-utils/init.lua +++ b/lua/core/autocmds.lua @@ -1,54 +1,6 @@ -local lv_utils = {} - -function lv_utils.reload_lv_config() - vim.cmd "source ~/.config/nvim/lv-config.lua" - vim.cmd "source ~/.config/nvim/lua/plugins.lua" - vim.cmd "source ~/.config/nvim/lua/settings.lua" - vim.cmd "source ~/.config/nvim/lua/core/formatter.lua" - vim.cmd ":PackerCompile" - vim.cmd ":PackerInstall" - -- vim.cmd ":PackerClean" -end - -function lv_utils.check_lsp_client_active(name) - local clients = vim.lsp.get_active_clients() - for _, client in pairs(clients) do - if client.name == name then - return true - end - end - return false -end - -function lv_utils.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 - -function lv_utils.unrequire(m) - package.loaded[m] = nil - _G[m] = nil -end - -lv_utils.define_augroups { +local autocommands = {} +lvim.autocommands = { _general_settings = { { "TextYankPost", @@ -75,13 +27,21 @@ lv_utils.define_augroups { "*", "setlocal formatoptions-=c formatoptions-=r formatoptions-=o", }, - { "BufWritePost", "lv-config.lua", "lua require('lv-utils').reload_lv_config()" }, + { "BufWritePost", "lv-config.lua", "lua require('utils').reload_lv_config()" }, + { + "FileType", + "qf", + "set nobuflisted", + }, -- { "VimLeavePre", "*", "set title set titleold=" }, }, - _solidity = { + _filetypechanges = { { "BufWinEnter", ".tf", "setlocal filetype=hcl" }, { "BufRead", "*.tf", "setlocal filetype=hcl" }, { "BufNewFile", "*.tf", "setlocal filetype=hcl" }, + { "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'}, @@ -95,6 +55,9 @@ lv_utils.define_augroups { { "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>" }, }, @@ -118,19 +81,29 @@ lv_utils.define_augroups { -- {'InsertEnter', '*', 'if &cursorline | let g:ms_cursorlineoff = 1 | setlocal nocursorline | endif'}, -- {'InsertLeave', '*', 'if exists("g:ms_cursorlineoff") | setlocal cursorline | endif'}, -- }, - _user_autocommands = O.user_autocommands, + custom_groups = {}, } -vim.cmd [[ - function! QuickFixToggle() - if empty(filter(getwininfo(), 'v:val.quickfix')) - copen - else - cclose - endif -endfunction -]] +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 -return lv_utils + vim.cmd "augroup END" + end +end --- TODO: find a new home for these autocommands +return autocommands diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index b8dad5f3..f0111db6 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -1,7 +1,7 @@ -- if not package.loaded['nvim-autopairs'] then -- return -- end -local status_ok, autopairs = pcall(require, "nvim-autopairs") +local status_ok, _ = pcall(require, "nvim-autopairs") if not status_ok then return end diff --git a/lua/core/bufferline.lua b/lua/core/bufferline.lua index d4e4b4fe..c5677580 100644 --- a/lua/core/bufferline.lua +++ b/lua/core/bufferline.lua @@ -1,28 +1,2 @@ -vim.api.nvim_set_keymap("n", "<S-x>", ":BufferClose<CR>", { noremap = true, silent = true }) 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 }) -vim.api.nvim_set_keymap("n", "<leader>c", ":BufferClose<CR>", { noremap = true, silent = true }) - -O.plugin.which_key.mappings["b"] = { - name = "Buffers", - j = { "<cmd>BufferPick<cr>", "jump to buffer" }, - f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, - w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, - e = { - "<cmd>BufferCloseAllButCurrent<cr>", - "close all but current buffer", - }, - h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, - l = { - "<cmd>BufferCloseBuffersRight<cr>", - "close all BufferLines to the right", - }, - D = { - "<cmd>BufferOrderByDirectory<cr>", - "sort BufferLines automatically by directory", - }, - L = { - "<cmd>BufferOrderByLanguage<cr>", - "sort BufferLines automatically by language", - }, -} diff --git a/lua/core/commands.lua b/lua/core/commands.lua new file mode 100644 index 00000000..c42b385d --- /dev/null +++ b/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/lua/core/compe.lua b/lua/core/compe.lua index c8152ad1..801e2dd8 100644 --- a/lua/core/compe.lua +++ b/lua/core/compe.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.completion = { + lvim.builtin.compe = { enabled = true, autocomplete = true, debug = false, @@ -30,18 +30,20 @@ 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" }, } end M.setup = function() - vim.g.vsnip_snippet_dir = O.vsnip_dir + vim.g.vsnip_snippet_dir = lvim.vsnip_dir local status_ok, compe = pcall(require, "compe") if not status_ok then return end - compe.setup(O.completion) + compe.setup(lvim.builtin.compe) local t = function(str) return vim.api.nvim_replace_termcodes(str, true, true, true) @@ -81,16 +83,29 @@ M.setup = function() end end - 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 }) - 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", "<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 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 +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 bc76e221..30e3aef9 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dap = { + lvim.builtin.dap = { active = false, breakpoint = { text = "", @@ -17,10 +17,10 @@ M.setup = function() return end - vim.fn.sign_define("DapBreakpoint", O.plugin.dap.breakpoint) + vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) dap.defaults.fallback.terminal_win_cmd = "50vsplit new" - O.user_which_key["d"] = { + lvim.builtin.which_key.mappings["d"] = { name = "Debug", t = { "<cmd>lua require'dap'.toggle_breakpoint()<cr>", "Toggle Breakpoint" }, b = { "<cmd>lua require'dap'.step_back()<cr>", "Step Back" }, @@ -38,4 +38,21 @@ M.setup = function() } end +-- TODO put this up there ^^^ call in ftplugin + +-- M.dap = function() +-- if lvim.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("python_dbg", {}) +-- end +-- end +-- +-- M.dap = function() +-- -- gem install readapt ruby-debug-ide +-- if lvim.plugin.dap.active then +-- local dap_install = require "dap-install" +-- dap_install.config("ruby_vsc_dbg", {}) +-- end +-- end + return M diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index e58b6f06..8d196458 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.dashboard = { + lvim.builtin.dashboard = { active = false, search_handler = "telescope", custom_header = { @@ -43,7 +43,8 @@ M.config = function() }, d = { description = { " Settings " }, - command = ":e " .. CONFIG_PATH .. "/lv-config.lua", + -- command = ":e " .. CONFIG_PATH .. "/lv-config.lua", + command = ":e ~/.config/lvim/lv-config.lua", }, }, @@ -54,23 +55,25 @@ 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 = lvim.builtin.dashboard.custom_header - vim.g.dashboard_default_executive = O.plugin.dashboard.search_handler + vim.g.dashboard_default_executive = lvim.builtin.dashboard.search_handler - vim.g.dashboard_custom_section = O.plugin.dashboard.custom_section + vim.g.dashboard_custom_section = lvim.builtin.dashboard.custom_section + + lvim.builtin.which_key.mappings[";"] = { "<cmd>Dashboard<CR>", "Dashboard" } -- f = { -- description = { " Neovim Config Files" }, -- command = "Telescope find_files cwd=" .. CONFIG_PATH, -- }, -- e = {description = {' Marks '}, command = 'Telescope marks'} - vim.cmd "let g:dashboard_session_directory = $HOME..'/.config/nvim/.sessions'" - vim.cmd "let packages = len(globpath('~/.local/share/nvim/site/pack/packer/start', '*', 0, 1))" + vim.cmd 'let g:dashboard_session_directory = "~/.config/lvim/.sessions"' + vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" vim.api.nvim_exec( [[ - let g:dashboard_custom_footer = ['LuaJIT loaded '..packages..' plugins'] + let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins '] ]], false ) @@ -78,8 +81,9 @@ 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("lv-utils").define_augroups { + -- vim.g.dashboard_custom_footer = lvim.dashboard.footer + + require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disapear will do more testing { @@ -90,7 +94,7 @@ M.setup = function() { "FileType", "dashboard", - "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=2", + "set showtabline=0 | autocmd BufLeave <buffer> set showtabline=" .. vim.opt.showtabline._value, }, { "FileType", "dashboard", "nnoremap <silent> <buffer> q :q<CR>" }, }, diff --git a/lua/core/floatterm.lua b/lua/core/floatterm.lua deleted file mode 100644 index 3d7e0e6e..00000000 --- a/lua/core/floatterm.lua +++ /dev/null @@ -1,76 +0,0 @@ -local M = {} -M.config = function() - O.plugin.floatterm = { - active = false, - dimensions = { - height = 0.9, - width = 0.9, - x = 0.5, - y = 0.3, - }, - border = "single", -- or 'double' - } -end - -M.setup = function() - local status_ok, fterm = pcall(require, "FTerm") - if not status_ok then - return - end - - fterm.setup(O.plugin.floatterm) - - -- Create LazyGit Terminal - local term = require "FTerm.terminal" - local lazy = term:new():setup { - cmd = "lazygit", - dimensions = O.plugin.floatterm.dimensions, - } - - local function is_installed(exe) - return vim.fn.executable(exe) == 1 - end - - -- Use this to toggle gitui in a floating terminal - function _G.__fterm_lazygit() - if is_installed "lazygit" ~= true then - print "Please install lazygit. Check documentation for more information" - return - end - lazy:toggle() - end - - -- Map esc to exit inside lazygit - -- vim.api.nvim_exec( - -- [[ - -- function LazyGitNativation() - -- echom &filetype - -- if &filetype ==# 'FTerm' - -- tnoremap <Esc> q - -- tnoremap <C-v><Esc> <Esc> - -- endif - -- endfunction - -- ]], - -- false - -- ) - - O.plugin.which_key.mappings["gg"] = "LazyGit" - vim.api.nvim_set_keymap("n", "<A-i>", "<CMD>lua require('FTerm').toggle()<CR>", { noremap = true, silent = true }) - vim.api.nvim_set_keymap("n", "<leader>gg", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true }) - - vim.api.nvim_set_keymap( - "t", - "<A-i>", - "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>", - { noremap = true, silent = true } - ) - vim.api.nvim_set_keymap("n", "<A-l>", "<CMD>lua _G.__fterm_lazygit()<CR>", { noremap = true, silent = true }) - vim.api.nvim_set_keymap( - "t", - "<A-l>", - "<C-\\><C-n><CMD>lua _G.__fterm_lazygit()<CR>", - { noremap = true, silent = true } - ) -end - -return M diff --git a/lua/core/formatter.lua b/lua/core/formatter.lua deleted file mode 100644 index 05de74ab..00000000 --- a/lua/core/formatter.lua +++ /dev/null @@ -1,60 +0,0 @@ --- autoformat -if O.format_on_save then - require("lv-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, formatter = 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/lua/core/galaxyline.lua b/lua/core/galaxyline.lua index 281202a8..abc7c369 100644 --- a/lua/core/galaxyline.lua +++ b/lua/core/galaxyline.lua @@ -7,9 +7,9 @@ if not status_ok then 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, lvim.colorscheme .. ".palette") if not palette_status_ok then - colors = O.plugin.galaxyline.colors + colors = lvim.builtin.galaxyline.colors end local condition = require "galaxyline.condition" @@ -266,7 +266,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,7 +315,7 @@ table.insert(gls.short_line_left, { provider = "FileTypeName", separator = " ", separator_highlight = { "NONE", colors.alt_bg }, - highlight = { colors.grey, colors.alt_bg }, + highlight = { colors.alt_bg, colors.alt_bg }, }, }) @@ -319,7 +323,7 @@ table.insert(gls.short_line_left, { SFileName = { provider = "SFileName", condition = condition.buffer_not_empty, - highlight = { colors.grey, colors.alt_bg }, + highlight = { colors.alt_bg, colors.alt_bg }, }, }) diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index bc310ad6..2a5060be 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.gitsigns = { + lvim.builtin.gitsigns = { signs = { add = { hl = "GitSignsAdd", @@ -53,7 +53,7 @@ M.setup = function() if not status_ok then return end - gitsigns.setup(O.plugin.gitsigns) + gitsigns.setup(lvim.builtin.gitsigns) end return M diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index cb3eacea..dd1f4f36 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -1,86 +1,87 @@ --- --if not package.loaded['nvim-tree.view'] then --- -- return --- --end --- local M = {} -local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") -if not status_ok then - return +-- +M.config = function() + lvim.builtin.nvimtree = { + side = "left", + show_icons = { + git = 1, + folders = 1, + files = 1, + folder_arrows = 1, + tree_width = 30, + }, + ignore = { ".git", "node_modules", ".cache" }, + auto_open = 1, + auto_close = 1, + quit_on_open = 0, + follow = 1, + hide_dotfiles = 1, + git_hl = 1, + root_folder_modifier = ":t", + tab_open = 0, + allow_resize = 1, + lsp_diagnostics = 1, + auto_ignore_ft = { "startify", "dashboard" }, + icons = { + default = "", + symlink = "", + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + deleted = "", + untracked = "U", + ignored = "◌", + }, + folder = { + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + }, + }, + } end -- M.setup = function() + local status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") + if not status_ok then + return + end local g = vim.g - vim.o.termguicolors = true - - g.nvim_tree_side = "left" - g.nvim_tree_width = 30 - g.nvim_tree_ignore = { ".git", "node_modules", ".cache" } - g.nvim_tree_auto_open = 1 - g.nvim_tree_auto_close = 1 - g.nvim_tree_quit_on_open = 0 - g.nvim_tree_follow = 1 - g.nvim_tree_indent_markers = 1 - g.nvim_tree_hide_dotfiles = 1 - g.nvim_tree_git_hl = 1 - g.nvim_tree_root_folder_modifier = ":t" - g.nvim_tree_tab_open = 0 - g.nvim_tree_allow_resize = 1 - g.nvim_tree_lsp_diagnostics = 1 - g.nvim_tree_auto_ignore_ft = { "startify", "dashboard" } - - g.nvim_tree_show_icons = { - git = 1, - folders = 1, - files = 1, - folder_arrows = 1, - } + for opt, val in pairs(lvim.builtin.nvimtree) do + g["nvim_tree_" .. opt] = val + end - vim.g.nvim_tree_icons = { - default = "", - symlink = "", - git = { - unstaged = "", - staged = "S", - unmerged = "", - renamed = "➜", - deleted = "", - untracked = "U", - ignored = "◌", - }, - folder = { - default = "", - open = "", - empty = "", - empty_open = "", - symlink = "", - }, - } local tree_cb = nvim_tree_config.nvim_tree_callback - vim.g.nvim_tree_bindings = { + 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 - -local view_status_ok, view = pcall(require, "nvim-tree.view") -if not view_status_ok then - return -end +-- +-- M.toggle_tree = function() + local view_status_ok, view = pcall(require, "nvim-tree.view") + if not view_status_ok then + return + end if view.win_open() then require("nvim-tree").close() if package.loaded["bufferline.state"] then require("bufferline.state").set_offset(0) end else - if package.loaded["bufferline.state"] then + 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, "") end - require("nvim-tree").find_file(true) + require("nvim-tree").toggle() end end -- diff --git a/lua/core/status_colors.lua b/lua/core/status_colors.lua index ddb4aa98..37e9d7c9 100644 --- a/lua/core/status_colors.lua +++ b/lua/core/status_colors.lua @@ -1,4 +1,4 @@ -O.plugin.galaxyline = { +lvim.builtin.galaxyline = { active = true, colors = { alt_bg = "#2E2E2E", diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 5a067d67..65760d6c 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -5,17 +5,9 @@ M.config = function() return end - O.plugin.telescope = { + lvim.builtin.telescope = { active = false, defaults = { - find_command = { - "rg", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - "--smart-case", - }, prompt_prefix = " ", selection_caret = " ", entry_prefix = " ", @@ -33,7 +25,7 @@ M.config = function() file_sorter = require("telescope.sorters").get_fzy_sorter, file_ignore_patterns = {}, generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, - path_display = { "shorten" }, + path_display = { shorten = 5 }, winblend = 0, border = {}, borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, @@ -89,8 +81,7 @@ M.setup = function() if not status_ok then return end - telescope.setup(O.plugin.telescope) - vim.api.nvim_set_keymap("n", "<Leader>f", ":Telescope find_files<CR>", { noremap = true, silent = true }) + telescope.setup(lvim.builtin.telescope) end return M diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua new file mode 100644 index 00000000..015341df --- /dev/null +++ b/lua/core/terminal.lua @@ -0,0 +1,91 @@ +local M = {} +M.config = function() + lvim.builtin["terminal"] = { + -- size can be a number or function which is passed the current terminal + size = 5, + -- open_mapping = [[<c-\>]], + open_mapping = [[<c-t>]], + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + 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, + -- direction = 'vertical' | 'horizontal' | 'window' | 'float', + direction = "float", + close_on_exit = true, -- close the terminal window when the process exits + shell = vim.o.shell, -- change the default shell + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_win_open' + -- see :h nvim_win_open for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + -- border = 'single' | 'double' | 'shadow' | 'curved' | ... other options supported by win open + border = "curved", + -- width = <value>, + -- height = <value>, + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, + -- Add executables on the lv-config file + -- { 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" } }, + } +end + +M.setup = function() + local status_ok, terminal = pcall(require, "toggleterm") + if not status_ok then + print(terminal) + return + end + for _, exec in pairs(lvim.builtin.terminal.execs) do + require("core.terminal").add_exec(exec[1], exec[2], exec[3]) + end + terminal.setup(lvim.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", + "<leader>" .. keymap, + "<cmd>lua require('core.terminal')._exec_toggle('" .. exec .. "')<CR>", + { noremap = true, silent = true } + ) + lvim.builtin.which_key.mappings[keymap] = name +end + +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._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 exec_term = Terminal:new { cmd = exec, hidden = true } + exec_term:toggle() +end + +return M diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua index 2b7a2d54..cfc58bb7 100644 --- a/lua/core/treesitter.lua +++ b/lua/core/treesitter.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.treesitter = { + lvim.builtin.treesitter = { ensure_installed = {}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages ignore_install = {}, matchup = { @@ -18,7 +18,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 +59,15 @@ 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 = "<leader>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 return end - treesitter_configs.setup(O.treesitter) + treesitter_configs.setup(lvim.builtin.treesitter) end return M diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index c3255705..9d4e7744 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -1,6 +1,6 @@ local M = {} M.config = function() - O.plugin.which_key = { + lvim.builtin.which_key = { active = false, setup = { plugins = { @@ -64,16 +64,38 @@ M.config = function() ["w"] = { "<cmd>w!<CR>", "Save" }, ["q"] = { "<cmd>q!<CR>", "Quit" }, ["/"] = { "<cmd>CommentToggle<CR>", "Comment" }, - ["c"] = { "<cmd>BufferClose<CR>", "Close Buffer" }, + ["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" }, - [";"] = { "<cmd>Dashboard<CR>", "Dashboard" }, + b = { + name = "Buffers", + j = { "<cmd>BufferPick<cr>", "jump to buffer" }, + f = { "<cmd>Telescope buffers<cr>", "Find buffer" }, + w = { "<cmd>BufferWipeout<cr>", "wipeout buffer" }, + e = { + "<cmd>BufferCloseAllButCurrent<cr>", + "close all but current buffer", + }, + h = { "<cmd>BufferCloseBuffersLeft<cr>", "close all buffers to the left" }, + l = { + "<cmd>BufferCloseBuffersRight<cr>", + "close all BufferLines to the right", + }, + D = { + "<cmd>BufferOrderByDirectory<cr>", + "sort BufferLines automatically by directory", + }, + L = { + "<cmd>BufferOrderByLanguage<cr>", + "sort BufferLines automatically by language", + }, + }, p = { name = "Packer", c = { "<cmd>PackerCompile<cr>", "Compile" }, i = { "<cmd>PackerInstall<cr>", "Install" }, - r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" }, + r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" }, s = { "<cmd>PackerSync<cr>", "Sync" }, u = { "<cmd>PackerUpdate<cr>", "Update" }, }, @@ -118,19 +140,21 @@ M.config = function() "<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics", }, - f = { "<cmd>silent FormatWrite<cr>", "Format" }, + -- f = { "<cmd>silent FormatWrite<cr>", "Format" }, + f = { "<cmd>lua vim.lsp.buf.formatting()<cr>", "Format" }, i = { "<cmd>LspInfo<cr>", "Info" }, j = { - "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<cr>", "Next Diagnostic", }, k = { - "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<cr>", + "<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" }, r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, - s = { "<cmd> Telescope lsp_document_symbols<cr>", "Document Symbols" }, + s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" }, S = { "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", "Workspace Symbols", @@ -149,6 +173,10 @@ M.config = function() t = { "<cmd>Telescope live_grep<cr>", "Text" }, k = { "<cmd>Telescope keymaps<cr>", "Keymaps" }, C = { "<cmd>Telescope commands<cr>", "Commands" }, + p = { + "<cmd>lua require('telescope.builtin.internal').colorscheme({enable_preview = true})<cr>", + "Colorscheme with Preview", + }, }, T = { name = "Treesitter", @@ -167,29 +195,18 @@ M.setup = function() 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(lvim.builtin.which_key.setup) - local mappings = O.plugin.which_key.mappings - local vmappings = O.plugin.which_key.vmappings + local opts = lvim.builtin.which_key.opts + local vopts = lvim.builtin.which_key.vopts - -- if O.plugin.ts_playground.active then - -- vim.api.nvim_set_keymap("n", "<leader>Th", ":TSHighlightCapturesUnderCursor<CR>", { noremap = true, silent = true }) - -- mappings[""] = "Highlight Capture" - -- end - - if O.plugin.zen.active then - vim.api.nvim_set_keymap("n", "<leader>z", ":ZenMode<CR>", { noremap = true, silent = true }) - mappings["z"] = "Zen" - end + local mappings = lvim.builtin.which_key.mappings + local vmappings = lvim.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/lua/core/zen.lua b/lua/core/zen.lua deleted file mode 100644 index 99a5d769..00000000 --- a/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 diff --git a/lua/default-config.lua b/lua/default-config.lua index b10c9590..77087fe5 100644 --- a/lua/default-config.lua +++ b/lua/default-config.lua @@ -1,305 +1,924 @@ -CONFIG_PATH = vim.fn.stdpath "config" +CONFIG_PATH = os.getenv "HOME" .. "/.local/share/lunarvim/lvim" DATA_PATH = vim.fn.stdpath "data" CACHE_PATH = vim.fn.stdpath "cache" TERMINAL = vim.fn.expand "$TERMINAL" USER = vim.fn.expand "$USER" -O = { - leader_key = "space", +lvim = { + leader = "space", colorscheme = "spacegray", line_wrap_cursor_movement = true, transparent_window = false, format_on_save = true, - vsnip_dir = vim.fn.stdpath "config" .. "/snippets", + vsnip_dir = os.getenv "HOME" .. "/.config/snippets", + database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 }, + keys = {}, - default_options = { - backup = false, -- creates a backup file - clipboard = "unnamedplus", -- allows neovim to access the system clipboard - cmdheight = 2, -- more space in the neovim command line for displaying messages - colorcolumn = "99999", -- fixes indentline for now - completeopt = { "menuone", "noselect" }, - conceallevel = 0, -- so that `` is visible in markdown files - fileencoding = "utf-8", -- the encoding written to a file - guifont = "monospace:h17", -- the font used in graphical neovim applications - hidden = true, -- required to keep multiple buffers and open multiple buffers - hlsearch = false, -- highlight all matches on previous search pattern - ignorecase = true, -- ignore case in search patterns - mouse = "a", -- allow the mouse to be used in neovim - pumheight = 10, -- pop up menu height - showmode = false, -- we don't need to see things like -- INSERT -- anymore - showtabline = 2, -- always show tabs - smartcase = true, -- smart case - smartindent = true, -- make indenting smarter again - splitbelow = true, -- force all horizontal splits to go below current window - splitright = true, -- force all vertical splits to go to the right of current window - swapfile = false, -- creates a swapfile - termguicolors = true, -- set term gui colors (most terminals support this) - timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) - title = true, -- set the title of window to the value of the titlestring - -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = CACHE_PATH .. "/undo", -- set an undo directory - undofile = true, -- enable persisten undo - updatetime = 300, -- faster completion - writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited - expandtab = true, -- convert tabs to spaces - shiftwidth = 2, -- the number of spaces inserted for each indentation - tabstop = 2, -- insert 2 spaces for a tab - cursorline = true, -- highlight the current line - number = true, -- set numbered lines - relativenumber = false, -- set relative numbered lines - numberwidth = 4, -- set number column width to 2 {default 4} - signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time - wrap = false, -- display lines as one long line - spell = false, - spelllang = "en", - scrolloff = 8, -- is one of my fav + -- TODO why do we need this? + builtin = { + lspinstall = {}, + telescope = {}, + compe = {}, + autopairs = {}, + treesitter = {}, + nvimtree = {}, + gitsigns = {}, + which_key = {}, + comment = {}, + rooter = {}, + galaxyline = {}, + bufferline = {}, + dap = {}, + dashboard = {}, + terminal = {}, }, - plugin = {}, - - -- TODO: refactor for tree - auto_close_tree = 0, - nvim_tree_disable_netrw = 0, - lsp = { + diagnostics = { + virtual_text = { + prefix = "", + spacing = 0, + }, + signs = true, + underline = true, + }, + override = {}, document_highlight = true, popup_border = "single", + default_keybinds = true, + on_attach_callback = nil, }, - database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 }, - - -- TODO: just using mappings (leader mappings) - user_which_key = {}, - - user_plugins = { + plugins = { -- use lv-config.lua for this not put here }, - user_autocommands = { - { "FileType", "qf", "set nobuflisted" }, - }, + autocommands = {}, +} + +local schemas = nil +local common_on_attach = require("lsp").common_on_attach +local common_capabilities = require("lsp").common_capabilities() +local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") +if status_ok then + schemas = jsonls_settings.get_default_schemas() +end - formatters = { - filetype = {}, +-- TODO move all of this into lang specific files, only require when using +lvim.lang = { + c = { + formatter = { + exe = "clang_format", + args = {}, + stdin = true, + }, + linters = { + "clangtidy", + }, + lsp = { + provider = "clangd", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + "--background-index", + "--header-insertion=never", + "--cross-file-rename", + "--clang-tidy", + "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + cpp = { + formatter = { + exe = "clang_format", + args = {}, + stdin = true, + }, + linters = { + "cppcheck", + "clangtidy", + }, + lsp = { + provider = "clangd", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + "--background-index", + "--header-insertion=never", + "--cross-file-rename", + "--clang-tidy", + "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + cs = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "omnisharp", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/csharp/omnisharp/run", + "--languageserver", + "--hostPID", + tostring(vim.fn.getpid()), + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + cmake = { + formatter = { + exe = "clang_format", + args = {}, + }, + linters = {}, + lsp = { + provider = "cmake", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + clojure = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "clojure_lsp", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/clojure/clojure-lsp", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + css = { + formatter = { + exe = "prettier", + args = {}, + }, + linters = {}, + lsp = { + provider = "cssls", + setup = { + cmd = { + "node", + DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + dart = { + formatter = { + exe = "dart", + args = { "format" }, + stdin = true, + }, + linters = {}, + lsp = { + provider = "dartls", + setup = { + cmd = { + "dart", + "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", + "--lsp", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + docker = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "dockerls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + elixir = { + formatter = { + exe = "mix", + args = { "format" }, + stdin = true, + }, + linters = {}, + lsp = { + provider = "elixirls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + elm = { + formatter = { + exe = "", + args = {}, + stdin = true, + }, + linters = {}, + lsp = { + provider = "elmls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server", + }, + on_attach = common_on_attach, + init_options = { + elmAnalyseTrigger = "change", + elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format", + elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/", + elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test", + }, + }, + }, + }, + erlang = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "erlangls", + setup = { + cmd = { + "erlang_ls", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + emmet = { active = false }, + fish = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "", + setup = { + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + go = { + formatter = { + exe = "gofmt", + args = {}, + stdin = true, + }, + linters = { + "golangcilint", + "revive", + }, + lsp = { + provider = "gopls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/go/gopls", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + graphql = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "graphql", + setup = { + cmd = { + "graphql-lsp", + "server", + "-m", + "stream", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + html = { + formatter = { + exe = "prettier", + args = {}, + }, + linters = { + "tidy", + -- https://docs.errata.ai/vale/scoping#html + "vale", + }, + lsp = { + provider = "html", + setup = { + cmd = { + "node", + DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + java = { + formatter = { + exe = "prettier", + args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0) }, + }, + linters = {}, + lsp = { + provider = "jdtls", + setup = { + cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + json = { + formatter = { + exe = "python", + args = { "-m", "json.tool" }, + stdin = true, + }, + linters = {}, + lsp = { + provider = "jsonls", + setup = { + cmd = { + "node", + DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + settings = { + json = { + schemas = schemas, + -- = { + -- { + -- fileMatch = { "package.json" }, + -- url = "https://json.schemastore.org/package.json", + -- }, + -- }, + }, + }, + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, + }, + }, + }, + }, + julia = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "julials", + setup = { + { + "julia", + "--startup-file=no", + "--history-file=no", + -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl", + CONFIG_PATH .. "/utils/julia/run.jl", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, }, + kotlin = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "kotlin_language_server", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server", + }, + on_attach = common_on_attach, + root_dir = function(fname) + local util = require "lspconfig/util" - -- TODO move all of this into lang specific files, only require when using - lang = { - cmake = { - formatter = { - exe = "clang-format", - args = {}, - }, - }, - clang = { - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - cross_file_rename = true, - header_insertion = "never", - filetypes = { "c", "cpp", "objc" }, - formatter = { - exe = "clang-format", - args = {}, + local root_files = { + "settings.gradle", -- Gradle (multi-project) + "settings.gradle.kts", -- Gradle (multi-project) + "build.xml", -- Ant + "pom.xml", -- Maven + } + + local fallback_root_files = { + "build.gradle", -- Gradle + "build.gradle.kts", -- Gradle + } + return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname) + end, }, }, - css = { - virtual_text = true, - }, - dart = { - sdk_path = "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", - formatter = { - exe = "dart", - args = { "format" }, - }, - }, - docker = {}, - efm = {}, - elm = {}, - emmet = { active = false }, - elixir = {}, - graphql = {}, - go = { - formatter = { - exe = "gofmt", - args = {}, - }, - }, - html = {}, - java = { - java_tools = { - active = false, - }, - formatter = { - exe = "prettier", - args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, - }, - }, - json = { - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - formatter = { - exe = "python", - args = { "-m", "json.tool" }, - }, - }, - kotlin = {}, - latex = { - auto_save = false, - ignore_errors = {}, - }, - lua = { - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - formatter = { - exe = "stylua", - args = {}, - stdin = false, - }, - }, - php = { - format = { - format = { - default = "psr12", - }, - }, - environment = { - php_version = "7.4", - }, - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - filetypes = { "php", "phtml" }, - formatter = { - exe = "phpcbf", - args = { "--standard=PSR12", vim.api.nvim_buf_get_name(0) }, - stdin = false, - }, - }, - python = { - -- @usage can be flake8 or yapf - linter = "", - isort = false, - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - analysis = { - type_checking = "basic", - auto_search_paths = true, - use_library_code_types = true, - }, - formatter = { - exe = "yapf", - args = {}, + }, + lua = { + formatter = { + exe = "stylua", + args = {}, + }, + linters = { "luacheck" }, + lsp = { + provider = "sumneko_lua", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", + "-E", + DATA_PATH .. "/lspinstall/lua/main.lua", + }, + on_attach = common_on_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + -- Setup your lua path + path = vim.split(package.path, ";"), + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim", "lvim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = { + [vim.fn.expand "~/.local/share/lunarvim/lvim/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, + }, + maxPreload = 100000, + preloadFileSize = 1000, + }, + }, + }, }, }, - ruby = { - diagnostics = { - virtualtext = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - filetypes = { "rb", "erb", "rakefile", "ruby" }, - formatter = { - exe = "rufo", - args = { "-x" }, - }, - }, - rust = { - rust_tools = { - active = false, - parameter_hints_prefix = "<-", - other_hints_prefix = "=>", -- prefix for all the other hints (type, chaining) + }, + php = { + formatter = { + exe = "phpcbf", + args = { "--standard=PSR12", vim.api.nvim_buf_get_name(0) }, + }, + linters = {}, + lsp = { + provider = "intelephense", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", + "--stdio", + }, + on_attach = common_on_attach, + filetypes = { "php", "phtml" }, + settings = { + intelephense = { + environment = { + phpVersion = "7.4", + }, + }, + }, }, - -- @usage can be clippy - formatter = { - exe = "rustfmt", - args = { "--emit=stdout", "--edition=2018" }, - }, - linter = "", - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, + }, + }, + puppet = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "puppet", + setup = { + on_attach = require("lsp").common_on_attach, + capabilities = require("lsp").common_capabilities(), }, }, - sh = { - -- @usage can be 'shellcheck' - linter = "", - -- @usage can be 'shfmt' - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - formatter = { - exe = "shfmt", - args = { "-w" }, - stdin = false, - }, - }, - svelte = {}, - tailwindcss = { - active = false, - filetypes = { - "html", - "css", - "scss", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", + }, + javascript = { + -- @usage can be prettier or eslint + formatter = { + exe = "prettier", + args = {}, + }, + linters = { + "eslint", + }, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + on_attach = require("lsp").common_on_attach, + capabilities = require("lsp").common_capabilities(), }, }, - terraform = { - formatter = { - exe = "terraform", - args = { "fmt" }, - stdin = false, + }, + javascriptreact = { + -- @usage can be prettier or eslint + formatter = { + exe = "prettier", + args = {}, + }, + linters = { + "eslint", + }, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + on_attach = require("lsp").common_on_attach, + capabilities = require("lsp").common_capabilities(), }, }, - tsserver = { - -- @usage can be 'eslint' or 'eslint_d' - linter = "", - diagnostics = { - virtual_text = { spacing = 0, prefix = "" }, - signs = true, - underline = true, - }, - formatter = { - exe = "prettier", - args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, - }, - }, - vim = {}, - yaml = { - formatter = { - exe = "prettier", - args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, + }, + python = { + -- @usage can be flake8 or yapf + formatter = { + exe = "black", + args = {}, + }, + linters = { + "flake8", + "pylint", + "mypy", + }, + lsp = { + provider = "pyright", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")' + -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' + r = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "r_language_server", + setup = { + cmd = { + "R", + "--slave", + "-e", + "languageserver::run()", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + ruby = { + formatter = { + exe = "rufo", + args = {}, + }, + linters = { "ruby" }, + lsp = { + provider = "solargraph", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", + "stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + rust = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "rust_analyzer", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/rust/rust-analyzer", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + scala = { + formatter = { + exe = "", + args = {}, + }, + linters = { "" }, + lsp = { + provider = "metals", + setup = { + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + sh = { + -- @usage can be 'shfmt' + formatter = { + exe = "shfmt", + args = {}, + }, + -- @usage can be 'shellcheck' + linters = { "shellcheck" }, + lsp = { + provider = "bashls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", + "start", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + svelte = { + formatter = { + exe = "", + args = {}, + }, + linters = {}, + lsp = { + provider = "svelte", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + swift = { + formatter = { + exe = "swiftformat", + args = {}, + }, + linters = {}, + lsp = { + provider = "sourcekit", + setup = { + cmd = { + "xcrun", + "sourcekit-lsp", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + tailwindcss = { + active = false, + filetypes = { + "html", + "css", + "scss", + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + }, + }, + terraform = { + formatter = { + exe = "", + args = {}, + stdin = false, + }, + linters = {}, + lsp = { + provider = "terraformls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/terraform/terraform-ls", + "serve", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + tex = { + formatter = { + exe = "latexindent", + args = {}, + stdin = false, + }, + linters = { "chktex" }, + lsp = { + provider = "texlab", + setup = { + cmd = { DATA_PATH .. "/lspinstall/latex/texlab" }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + typescript = { + -- @usage can be prettier or eslint + formatter = { + exe = "prettier", + args = {}, + }, + linters = { + "eslint", + }, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + on_attach = require("lsp").common_on_attach, + capabilities = require("lsp").common_capabilities(), + }, + }, + }, + typescriptreact = { + -- @usage can be prettier or eslint + formatter = { + exe = "prettier", + args = {}, + }, + linters = { + "eslint", + }, + lsp = { + provider = "tsserver", + setup = { + cmd = { + -- TODO: + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + on_attach = require("lsp").common_on_attach, + capabilities = require("lsp").common_capabilities(), + }, + }, + }, + vim = { + formatter = { + exe = "", + args = {}, + }, + linters = { "" }, + lsp = { + provider = "vimls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + vue = { + formatter = { + exe = "prettier", + args = {}, + }, + linters = {}, + lsp = { + provider = "vetur", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + yaml = { + formatter = { + exe = "prettier", + args = {}, + }, + linters = {}, + lsp = { + provider = "yamlls", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", + "--stdio", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, + }, + }, + }, + zig = { + formatter = { + exe = "", + args = {}, + stdin = false, + }, + linters = {}, + lsp = { + provider = "zls", + setup = { + cmd = { + "zls", + }, + on_attach = common_on_attach, + capabilities = common_capabilities, }, }, }, } +require("core.which-key").config() require "core.status_colors" require("core.gitsigns").config() require("core.compe").config() require("core.dashboard").config() require("core.dap").config() -require("core.floatterm").config() -require("core.zen").config() +require("core.terminal").config() require("core.telescope").config() require("core.treesitter").config() -require("core.which-key").config() +require("core.nvimtree").config() diff --git a/lua/keymappings.lua b/lua/keymappings.lua index fed362aa..c791418e 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -1,42 +1,41 @@ -local function register_mappings(mappings, default_options) - for mode, mode_mappings in pairs(mappings) do - for _, mapping in pairs(mode_mappings) do - local options = #mapping == 3 and table.remove(mapping) or default_options - local prefix, cmd = unpack(mapping) - pcall(vim.api.nvim_set_keymap, mode, prefix, cmd, options) - end - end -end +local utils = require "utils" + +local opts = { + nnoremap = { noremap = true, silent = true }, + inoremap = { noremap = true, silent = true }, + vnoremap = { noremap = true, silent = true }, + xnoremap = { noremap = true, silent = true }, + generic = { silent = true }, +} -local mappings = { - i = { -- Insert mode +local default_keys = { + insert_mode = { -- I hate escape { "jk", "<ESC>" }, { "kj", "<ESC>" }, { "jj", "<ESC>" }, - -- Move current line / block with Alt-j/k ala vscode. { "<A-j>", "<Esc>:m .+1<CR>==gi" }, { "<A-k>", "<Esc>:m .-2<CR>==gi" }, - - -- Terminal window navigation - { "<C-h>", "<C-\\><C-N><C-w>h" }, - { "<C-j>", "<C-\\><C-N><C-w>j" }, - { "<C-k>", "<C-\\><C-N><C-w>k" }, - { "<C-l>", "<C-\\><C-N><C-w>l" }, + -- navigation + { "<A-Up>", "<C-\\><C-N><C-w>h" }, + { "<A-Down>", "<C-\\><C-N><C-w>j" }, + { "<A-Left>", "<C-\\><C-N><C-w>k" }, + { "<A-Right>", "<C-\\><C-N><C-w>l" }, }, - n = { -- Normal mode + + normal_mode = { -- Better window movement - { "<C-h>", "<C-w>h", { silent = true } }, - { "<C-j>", "<C-w>j", { silent = true } }, - { "<C-k>", "<C-w>k", { silent = true } }, - { "<C-l>", "<C-w>l", { silent = true } }, + { "<C-h>", "<C-w>h" }, + { "<C-j>", "<C-w>j" }, + { "<C-k>", "<C-w>k" }, + { "<C-l>", "<C-w>l" }, -- Resize with arrows - { "<C-Up>", ":resize -2<CR>", { silent = true } }, - { "<C-Down>", ":resize +2<CR>", { silent = true } }, - { "<C-Left>", ":vertical resize -2<CR>", { silent = true } }, - { "<C-Right>", ":vertical resize +2<CR>", { silent = true } }, + { "<C-Up>", ":resize -2<CR>" }, + { "<C-Down>", ":resize +2<CR>" }, + { "<C-Left>", ":vertical resize -2<CR>" }, + { "<C-Right>", ":vertical resize +2<CR>" }, -- Tab switch buffer -- { "<TAB>", ":bnext<CR>" }, @@ -49,17 +48,20 @@ local mappings = { -- QuickFix { "]q", ":cnext<CR>" }, { "[q", ":cprev<CR>" }, + { "<C-q>", ":call QuickFixToggle()<CR>" }, -- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}}, }, - t = { -- Terminal mode + + term_mode = { -- Terminal window navigation { "<C-h>", "<C-\\><C-N><C-w>h" }, { "<C-j>", "<C-\\><C-N><C-w>j" }, { "<C-k>", "<C-\\><C-N><C-w>k" }, { "<C-l>", "<C-\\><C-N><C-w>l" }, }, - v = { -- Visual/Select mode + + visual_mode = { -- Better indenting { "<", "<gv" }, { ">", ">gv" }, @@ -67,7 +69,8 @@ local mappings = { -- { "p", '"0p', { silent = true } }, -- { "P", '"0P', { silent = true } }, }, - x = { -- Visual mode + + visual_block_mode = { -- Move selected line / block of text in visual mode { "K", ":move '<-2<CR>gv-gv" }, { "J", ":move '>+1<CR>gv-gv" }, @@ -76,31 +79,37 @@ local mappings = { { "<A-j>", ":m '>+1<CR>gv-gv" }, { "<A-k>", ":m '<-2<CR>gv-gv" }, }, - [""] = { - -- Toggle the QuickFix window - { "<C-q>", ":call QuickFixToggle()<CR>" }, - }, } --- TODO: fix this if vim.fn.has "mac" == 1 then - mappings["n"][5][1] = "<A-Up>" - mappings["n"][6][1] = "<A-Down>" - mappings["n"][7][1] = "<A-Left>" - mappings["n"][8][1] = "<A-Right>" + -- TODO: fix this + default_keys.normal_mode[5][1] = "<A-Up>" + default_keys.normal_mode[6][1] = "<A-Down>" + default_keys.normal_mode[7][1] = "<A-Left>" + default_keys.normal_mode[8][1] = "<A-Right>" end -register_mappings(mappings, { silent = true, noremap = true }) +if lvim.leader == " " or lvim.leader == "space" then + vim.g.mapleader = " " +else + vim.g.mapleader = lvim.leader +end -vim.cmd 'inoremap <expr> <c-j> ("\\<C-n>")' -vim.cmd 'inoremap <expr> <c-k> ("\\<C-p>")' +local function get_user_keys(mode) + if lvim.keys[mode] == nil then + return default_keys[mode] + else + return lvim.keys[mode] + end +end --- vim.cmd('inoremap <expr> <TAB> (\"\\<C-n>\")') --- vim.cmd('inoremap <expr> <S-TAB> (\"\\<C-p>\")') +utils.add_keymap_normal_mode(opts.nnoremap, get_user_keys "normal_mode") +utils.add_keymap_insert_mode(opts.inoremap, get_user_keys "insert_mode") +utils.add_keymap_visual_mode(opts.vnoremap, get_user_keys "visual_mode") +utils.add_keymap_visual_block_mode(opts.xnoremap, get_user_keys "visual_block_mode") +utils.add_keymap_term_mode(opts.generic, get_user_keys "term_mode") --- vim.cmd([[ --- map p <Plug>(miniyank-autoput) --- map P <Plug>(miniyank-autoPut) --- map <leader>n <Plug>(miniyank-cycle) --- map <leader>N <Plug>(miniyank-cycleback) --- ]]) +-- navigate tab completion with <c-j> and <c-k> +-- runs conditionally +vim.cmd 'inoremap <expr> <C-j> pumvisible() ? "\\<C-n>" : "\\<C-j>"' +vim.cmd 'inoremap <expr> <C-k> pumvisible() ? "\\<C-p>" : "\\<C-k>"' diff --git a/lua/lsp/angular-ls.lua b/lua/lsp/angular-ls.lua deleted file mode 100644 index 818faf38..00000000 --- a/lua/lsp/angular-ls.lua +++ /dev/null @@ -1,6 +0,0 @@ --- TODO: find correct root filetype --- :LspInstall angular -require("lspconfig").angularls.setup { - cmd = { DATA_PATH .. "/lspinstall/angular/node_modules/@angular/language-server/bin/ngserver", "--stdio" }, - on_attach = require("lsp").common_on_attach, -} diff --git a/lua/lsp/emmet-ls.lua b/lua/lsp/emmet-ls.lua deleted file mode 100644 index e38747ac..00000000 --- a/lua/lsp/emmet-ls.lua +++ /dev/null @@ -1,23 +0,0 @@ --- if not package.loaded['lspconfig'] then --- return --- end - -local nvim_lsp = require "lspconfig" -local configs = require "lspconfig/configs" -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities.textDocument.completion.completionItem.snippetSupport = true - -configs.emmet_ls = { - default_config = { - cmd = { "emmet-ls", "--stdio" }, - filetypes = { "html", "css", "javascript", "typescript", "vue" }, - root_dir = function() - return vim.loop.cwd() - end, - settings = {}, - }, -} - -nvim_lsp.emmet_ls.setup { - -- on_attach = on_attach; -} diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 01f82737..5a0d6c1e 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,4 +1,5 @@ --- TODO: figure out why this don't work +local lsp_config = {} + vim.fn.sign_define( "LspDiagnosticsSignError", { texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError" } @@ -16,37 +17,68 @@ vim.fn.sign_define( { texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation" } ) -vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>" -vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>" -vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>" -vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>" -vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp'.PeekDefinition()<CR>" -vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>" --- vim.cmd('nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>') -vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = O.lsp.popup_border}})<CR>" -vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = O.lsp.popup_border}})<CR>" --- scroll down hover doc or scroll in definition preview --- scroll up hover doc -vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()' +-- local opts = { border = "single" } +-- TODO revisit this +-- local border = { +-- { "🭽", "FloatBorder" }, +-- { "▔", "FloatBorder" }, +-- { "🭾", "FloatBorder" }, +-- { "▕", "FloatBorder" }, +-- { "🭿", "FloatBorder" }, +-- { "▁", "FloatBorder" }, +-- { "🭼", "FloatBorder" }, +-- { "▏", "FloatBorder" }, +-- } + +-- My font didn't like this :/ +-- vim.api.nvim_set_keymap( +-- "n", +-- "gl", +-- '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = { { "🭽", "FloatBorder" }, { "▔", "FloatBorder" }, { "🭾", "FloatBorder" }, { "▕", "FloatBorder" }, { "🭿", "FloatBorder" }, { "▁", "FloatBorder" }, { "🭼", "FloatBorder" }, { "▏", "FloatBorder" }, } })<CR>', +-- { noremap = true, silent = true } +-- ) + +function lsp_config.setup_default_bindings() + if lvim.lsp.default_keybinds then + vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>" + vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>" + vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>" + vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>" + vim.api.nvim_set_keymap( + "n", + "gl", + '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })<CR>', + { noremap = true, silent = true } + ) + + vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp'.PeekDefinition()<CR>" + vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>" + vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>" + vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>" + -- vim.cmd "nnoremap <silent> <tab> <cmd>lua vim.lsp.buf.signature_help()<CR>" + -- scroll down hover doc or scroll in definition preview + -- scroll up hover doc + vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()' + end +end -- Set Default Prefix. -- Note: You can set a prefix per lsp server in the lv-globals.lua file -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { - prefix = "", - spacing = 0, - }, - signs = true, - underline = true, -}) +function lsp_config.setup_handlers() + vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = lvim.lsp.diagnostics.virtual_text, + signs = lvim.lsp.diagnostics.signs, + underline = lvim.lsp.document_highlight, + }) -vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { - border = O.lsp.popup_border, -}) + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = lvim.lsp.popup_border, + }) -vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = O.lsp.popup_border, -}) + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = lvim.lsp.popup_border, + }) +end -- symbols for autocomplete vim.lsp.protocol.CompletionItemKind = { @@ -84,7 +116,10 @@ autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]] -- Java -- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR> -local function documentHighlight(client, bufnr) +local function lsp_highlight_document(client) + if lvim.lsp.document_highlight == false then + return -- we don't need further + end -- Set autocommands conditional on server_capabilities if client.resolved_capabilities.document_highlight then vim.api.nvim_exec( @@ -102,7 +137,6 @@ local function documentHighlight(client, bufnr) ) end end -local lsp_config = {} -- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/ function lsp_config.preview_location(location, context, before_context) @@ -126,7 +160,7 @@ function lsp_config.preview_location(location, context, before_context) false ) local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - return vim.lsp.util.open_floating_preview(contents, filetype, { border = O.lsp.popup_border }) + return vim.lsp.util.open_floating_preview(contents, filetype, { border = lvim.lsp.popup_border }) end function lsp_config.preview_location_callback(_, method, result) @@ -169,65 +203,102 @@ function lsp_config.PeekImplementation() end end -if O.lsp.document_highlight then - function lsp_config.common_on_attach(client, bufnr) - documentHighlight(client, bufnr) +function lsp_config.common_on_attach(client, bufnr) + if lvim.lsp.on_attach_callback then + lvim.lsp.on_attach_callback(client, bufnr) end + lsp_highlight_document(client) end -function lsp_config.tsserver_on_attach(client, bufnr) - -- lsp_config.common_on_attach(client, bufnr) +local function no_formatter_on_attach(client, bufnr) + if lvim.lsp.on_attach_callback then + lvim.lsp.on_attach_callback(client, bufnr) + end + lsp_highlight_document(client) client.resolved_capabilities.document_formatting = false +end - local ts_utils = require "nvim-lsp-ts-utils" - - -- defaults - ts_utils.setup { - debug = false, - disable_commands = false, - enable_import_on_completion = false, - import_all_timeout = 5000, -- ms - - -- eslint - eslint_enable_code_actions = true, - eslint_enable_disable_comments = true, - eslint_bin = O.lang.tsserver.linter, - eslint_config_fallback = nil, - eslint_enable_diagnostics = true, - - -- formatting - enable_formatting = O.lang.tsserver.autoformat, - formatter = O.lang.tsserver.formatter.exe, - formatter_config_fallback = nil, - - -- parentheses completion - complete_parens = false, - signature_help_in_parens = false, - - -- update imports on file move - update_imports_on_move = false, - require_confirmation_on_move = false, - watch_dir = nil, +function lsp_config.common_capabilities() + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem.snippetSupport = true + capabilities.textDocument.completion.completionItem.resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, } - - -- required to fix code action ranges - ts_utils.setup_client(client) - - -- TODO: keymap these? - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gs", ":TSLspOrganize<CR>", {silent = true}) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", {silent = true}) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":TSLspRenameFile<CR>", {silent = true}) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", ":TSLspImportAll<CR>", {silent = true}) + return capabilities end -require("lv-utils").define_augroups { +require("core.autocmds").define_augroups { _general_lsp = { { "FileType", "lspinfo", "nnoremap <silent> <buffer> q :q<CR>" }, }, } --- Use a loop to conveniently both setup defined servers --- and map buffer local keybindings when the language server attaches --- local servers = {"pyright", "tsserver"} --- for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup {on_attach = on_attach} end +local function is_table(t) + return type(t) == "table" +end + +local function is_string(t) + return type(t) == "string" +end + +local function has_value(tab, val) + for _, value in ipairs(tab) do + if value == val then + return true + end + end + + return false +end + +function lsp_config.setup(lang) + local lang_server = lvim.lang[lang].lsp + local provider = lang_server.provider + if require("utils").check_lsp_client_active(provider) then + return + end + + local overrides = lvim.lsp.override + + if is_table(overrides) then + if has_value(overrides, lang) then + return + end + end + + if is_string(overrides) then + if overrides == lang then + return + end + end + local sources = require("lsp.null-ls").setup(lang) + + for _, source in pairs(sources) do + local method = source.method + local format_method = "NULL_LS_FORMATTING" + + if is_table(method) then + if has_value(method, format_method) then + lang_server.setup.on_attach = no_formatter_on_attach + end + end + + if is_string(method) then + if method == format_method then + lang_server.setup.on_attach = no_formatter_on_attach + end + end + end + + if provider == "" or provider == nil then + return + end + + require("lspconfig")[provider].setup(lang_server.setup) +end + return lsp_config diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua new file mode 100644 index 00000000..48924be5 --- /dev/null +++ b/lua/lsp/null-ls.lua @@ -0,0 +1,83 @@ +local M = {} + +local null_ls = require "null-ls" +local sources = {} + +local local_executables = { "prettier", "prettierd", "prettier_d_slim", "eslint_d", "eslint" } + +local function is_table(t) + return type(t) == "table" +end + +local function is_string(t) + return type(t) == "string" +end + +local function has_value(tab, val) + for _, value in ipairs(tab) do + if value == val then + return true + end + end + + return false +end + +local find_local_exe = function(exe) + vim.cmd "let root_dir = FindRootDirectory()" + local root_dir = vim.api.nvim_get_var "root_dir" + local local_exe = root_dir .. "/node_modules/.bin/" .. exe + return local_exe +end + +local function setup_ls(exe, type) + if has_value(local_executables, exe) then + local smart_executable = null_ls.builtins[type][exe] + local local_executable = find_local_exe(exe) + if vim.fn.executable(local_executable) == 1 then + smart_executable._opts.command = local_executable + table.insert(sources, smart_executable) + else + if vim.fn.executable(exe) == 1 then + table.insert(sources, smart_executable) + end + end + else + if vim.fn.executable(exe) == 1 then + table.insert(sources, null_ls.builtins[type][exe]) + end + end + null_ls.register { sources = sources } +end + +-- TODO: for linters and formatters with spaces and '-' replace with '_' +local function setup(filetype, type) + local executables = nil + if type == "diagnostics" then + executables = lvim.lang[filetype].linters + end + if type == "formatting" then + executables = lvim.lang[filetype].formatter.exe + end + + if is_table(executables) then + for _, exe in pairs(executables) do + if exe ~= "" then + setup_ls(exe, type) + end + end + end + if is_string(executables) and executables ~= "" then + setup_ls(executables, type) + end +end + +-- TODO: return the formatter if one was registered, then turn off the builtin formatter +function M.setup(filetype) + setup(filetype, "formatting") + setup(filetype, "diagnostics") + lvim.sources = sources + return sources +end + +return M diff --git a/lua/lsp/svelte-ls.lua b/lua/lsp/svelte-ls.lua deleted file mode 100644 index e5ddb3b3..00000000 --- a/lua/lsp/svelte-ls.lua +++ /dev/null @@ -1,5 +0,0 @@ --- TODO: what is a svelte filetype -require("lspconfig").svelte.setup { - cmd = { DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", "--stdio" }, - on_attach = require("lsp").common_on_attach, -} diff --git a/lua/lsp/tailwindcss-ls.lua b/lua/lsp/tailwindcss-ls.lua deleted file mode 100644 index 38c1e7cc..00000000 --- a/lua/lsp/tailwindcss-ls.lua +++ /dev/null @@ -1,13 +0,0 @@ --- TODO: what is a tailwindcss filetype -local lspconfig = require "lspconfig" - -lspconfig.tailwindcss.setup { - cmd = { - "node", - DATA_PATH .. "/lspinstall/tailwindcss/tailwindcss-intellisense/extension/dist/server/tailwindServer.js", - "--stdio", - }, - filetypes = O.lang.tailwindcss.filetypes, - root_dir = require("lspconfig/util").root_pattern("tailwind.config.js", "postcss.config.ts", ".postcssrc"), - on_attach = require("lsp").common_on_attach, -} diff --git a/lua/lsp/ts-fmt-lint.lua b/lua/lsp/ts-fmt-lint.lua deleted file mode 100644 index a73b817e..00000000 --- a/lua/lsp/ts-fmt-lint.lua +++ /dev/null @@ -1,49 +0,0 @@ --- Example configuations here: https://github.com/mattn/efm-langserver --- You can look for project scope Prettier and Eslint with e.g. vim.fn.glob("node_modules/.bin/prettier") etc. If it is not found revert to global Prettier where needed. -local M = {} - -M.setup = function() - local tsserver_args = {} - - if O.lang.tsserver.linter == "eslint" or O.lang.tsserver.linter == "eslint_d" then - local eslint = { - lintCommand = O.lang.tsserver.linter .. " -f unix --stdin --stdin-filename {INPUT}", - lintStdin = true, - lintFormats = { "%f:%l:%c: %m" }, - lintIgnoreExitCode = true, - formatCommand = O.lang.tsserver.linter .. " --fix-to-stdout --stdin --stdin-filename=${INPUT}", - formatStdin = true, - } - table.insert(tsserver_args, eslint) - end - - require("lspconfig").efm.setup { - -- init_options = {initializationOptions}, - cmd = { DATA_PATH .. "/lspinstall/efm/efm-langserver" }, - init_options = { documentFormatting = true, codeAction = false }, - root_dir = require("lspconfig").util.root_pattern(".git/", "package.json"), - filetypes = { - "vue", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", - "javascript.jsx", - "typescript.tsx", - }, - settings = { - rootMarkers = { ".git/", "package.json" }, - languages = { - vue = tsserver_args, - javascript = tsserver_args, - javascriptreact = tsserver_args, - ["javascript.jsx"] = tsserver_args, - typescript = tsserver_args, - ["typescript.tsx"] = tsserver_args, - typescriptreact = tsserver_args, - }, - }, - } -end - -return M diff --git a/lua/lsp/tsserver-ls.lua b/lua/lsp/tsserver-ls.lua deleted file mode 100644 index 8ed801e8..00000000 --- a/lua/lsp/tsserver-ls.lua +++ /dev/null @@ -1,67 +0,0 @@ -vim.cmd "let proj = FindRootDirectory()" -local root_dir = vim.api.nvim_get_var "proj" - --- use the global prettier if you didn't find the local one -local prettier_instance = root_dir .. "/node_modules/.bin/prettier" -if vim.fn.executable(prettier_instance) ~= 1 then - prettier_instance = O.lang.tsserver.formatter.exe -end - -O.formatters.filetype["javascriptreact"] = { - function() - return { - exe = prettier_instance, - -- TODO: allow user to override this - args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, - stdin = true, - } - end, -} -O.formatters.filetype["javascript"] = O.formatters.filetype["javascriptreact"] - -require("formatter.config").set_defaults { - logging = false, - filetype = O.formatters.filetype, -} - -if require("lv-utils").check_lsp_client_active "tsserver" then - return -end - --- npm install -g typescript typescript-language-server --- require'snippets'.use_suggested_mappings() --- local capabilities = vim.lsp.protocol.make_client_capabilities() --- capabilities.textDocument.completion.completionItem.snippetSupport = true; --- local on_attach_common = function(client) --- print("LSP Initialized") --- require'completion'.on_attach(client) --- require'illuminate'.on_attach(client) --- end -require("lspconfig").tsserver.setup { - cmd = { - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - }, - on_attach = require("lsp").tsserver_on_attach, - -- This makes sure tsserver is not used for formatting (I prefer prettier) - -- on_attach = require'lsp'.common_on_attach, - root_dir = require("lspconfig/util").root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git"), - settings = { documentFormatting = false }, - handlers = { - ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = O.lang.tsserver.diagnostics.virtual_text, - signs = O.lang.tsserver.diagnostics.signs, - underline = O.lang.tsserver.diagnostics.underline, - update_in_insert = true, - }), - }, -} -require("lsp.ts-fmt-lint").setup() diff --git a/lua/lv-user/README.md b/lua/lv-user/README.md deleted file mode 100644 index 789001a2..00000000 --- a/lua/lv-user/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# User Config - -If you have found this directory then you are probably advanced enough to add your own config. All `lua` files you create here will be available in lv-config. - -**NOTE** I may update this readme in the future so I recommend not changing anything in this file specifically diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua new file mode 100644 index 00000000..b7e68a1e --- /dev/null +++ b/lua/plugin-loader.lua @@ -0,0 +1,49 @@ +local plugin_loader = {} + +function plugin_loader:init() + local execute = vim.api.nvim_command + local fn = vim.fn + + local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim" + if fn.empty(fn.glob(install_path)) > 0 then + execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path) + execute "packadd packer.nvim" + end + + local packer_ok, packer = pcall(require, "packer") + if not packer_ok then + return + end + + local util = require "packer.util" + + packer.init { + package_root = util.join_paths "~/.local/share/lunarvim/site/pack/", + compile_path = util.join_paths("~/.config/lvim", "plugin", "packer_compiled.lua"), + git = { clone_timeout = 300 }, + display = { + open_fn = function() + return util.float { border = "single" } + end, + }, + } + + self.packer = packer + return self +end + +function plugin_loader:load(configurations) + return self.packer.startup(function(use) + for _, plugins in ipairs(configurations) do + for _, plugin in ipairs(plugins) do + use(plugin) + end + end + end) +end + +return { + init = function() + return plugin_loader:init() + end, +} diff --git a/lua/plugins.lua b/lua/plugins.lua index 129bc91d..0fd477de 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,123 +1,126 @@ -local execute = vim.api.nvim_command -local fn = vim.fn - -local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" - -if fn.empty(fn.glob(install_path)) > 0 then - execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path) - execute "packadd packer.nvim" -end - -local packer_ok, packer = pcall(require, "packer") -if not packer_ok then - return -end - -packer.init { - -- package_root = require("packer.util").join_paths(vim.fn.stdpath "data", "lvim", "pack"), - git = { clone_timeout = 300 }, - display = { - open_fn = function() - return require("packer.util").float { border = "single" } - end, - }, -} - -return require("packer").startup(function(use) +return { -- Packer can manage itself as an optional plugin - use "wbthomason/packer.nvim" - - -- TODO: refactor all of this (for now it works, but yes I know it could be wrapped in a simpler function) - use { "neovim/nvim-lspconfig" } - use { + { "wbthomason/packer.nvim" }, + { "neovim/nvim-lspconfig" }, + { "tamago324/nlsp-settings.nvim" }, + { "jose-elias-alvarez/null-ls.nvim" }, + { "kabouzeid/nvim-lspinstall", event = "VimEnter", config = function() - require("lspinstall").setup() + local lspinstall = require "lspinstall" + lspinstall.setup() + if lvim.builtin.lspinstall.on_config_done then + lvim.builtin.lspinstall.on_config_done(lspinstall) + end end, - } + }, - use { "nvim-lua/popup.nvim" } - use { "nvim-lua/plenary.nvim" } - use { "tjdevries/astronauta.nvim" } + { "nvim-lua/popup.nvim" }, + { "nvim-lua/plenary.nvim" }, + { "tjdevries/astronauta.nvim" }, -- Telescope - use { + { "nvim-telescope/telescope.nvim", - config = [[require('core.telescope').setup()]], - } + config = function() + require("core.telescope").setup() + if lvim.builtin.telescope.on_config_done then + lvim.builtin.telescope.on_config_done(require "telescope") + end + end, + }, - -- Autocomplete - use { + -- Completion & Snippets + { "hrsh7th/nvim-compe", - -- event = "InsertEnter", + event = "InsertEnter", config = function() require("core.compe").setup() + if lvim.builtin.compe.on_config_done then + lvim.builtin.compe.on_config_done(require "compe") + end end, - } + wants = "vim-vsnip", + requires = { + { + "hrsh7th/vim-vsnip", + wants = "friendly-snippets", + event = "InsertCharPre", + }, + { + "rafamadriz/friendly-snippets", + event = "InsertCharPre", + }, + }, + }, -- Autopairs - use { + { "windwp/nvim-autopairs", -- event = "InsertEnter", - after = { "telescope.nvim" }, + after = "nvim-compe", config = function() require "core.autopairs" + if lvim.builtin.autopairs.on_config_done then + lvim.builtin.autopairs.on_config_done(require "nvim-autopairs") + end end, - } - - -- Snippets - - use { "hrsh7th/vim-vsnip", event = "InsertEnter" } - use { "rafamadriz/friendly-snippets", event = "InsertEnter" } + }, -- Treesitter - use { + { "nvim-treesitter/nvim-treesitter", + branch = "0.5-compat", + -- run = ":TSUpdate", config = function() require("core.treesitter").setup() + if lvim.builtin.treesitter.on_config_done then + lvim.builtin.treesitter.on_config_done(require "nvim-treesitter.configs") + end end, - } - - -- Formatter.nvim - use { - "mhartington/formatter.nvim", - config = function() - require "core.formatter" - end, - } + }, -- NvimTree - use { + { "kyazdani42/nvim-tree.lua", -- event = "BufWinOpen", -- cmd = "NvimTreeToggle", - commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb", + -- commit = "fd7f60e242205ea9efc9649101c81a07d5f458bb", config = function() require("core.nvimtree").setup() + if lvim.builtin.nvimtree.on_config_done then + lvim.builtin.nvimtree.on_config_done(require "nvim-tree.config") + end end, - } + }, - use { + { "lewis6991/gitsigns.nvim", config = function() require("core.gitsigns").setup() + if lvim.builtin.gitsigns.on_config_done then + lvim.builtin.gitsigns.on_config_done(require "gitsigns") + end end, event = "BufRead", - } + }, - -- whichkey - use { + -- Whichkey + { "folke/which-key.nvim", config = function() require("core.which-key").setup() + if lvim.builtin.which_key.on_config_done then + lvim.builtin.which_key.on_config_done(require "which-key") + end end, event = "BufWinEnter", - } + }, -- Comments - use { + { "terrortylor/nvim-comment", event = "BufRead", config = function() @@ -126,129 +129,104 @@ return require("packer").startup(function(use) return end nvim_comment.setup() + if lvim.builtin.comment.on_config_done then + lvim.builtin.comment.on_config_done(nvim_comment) + end end, - } + }, -- vim-rooter - use { + { "airblade/vim-rooter", config = function() vim.g.rooter_silent_chdir = 1 + vim.g.rooter_patterns = { + ".git", + "_darcs", + ".hg", + ".bzr", + ".svn", + "Makefile", + "package.json", + "package-lock.json", + } + if lvim.builtin.rooter.on_config_done then + lvim.builtin.rooter.on_config_done() + end end, - } + }, -- Icons - use { "kyazdani42/nvim-web-devicons" } + { "kyazdani42/nvim-web-devicons" }, -- Status Line and Bufferline - use { + { "glepnir/galaxyline.nvim", config = function() require "core.galaxyline" + if lvim.builtin.galaxyline.on_config_done then + lvim.builtin.galaxyline.on_config_done(require "galaxyline") + end end, event = "BufWinEnter", - disable = not O.plugin.galaxyline.active, - } + disable = not lvim.builtin.galaxyline.active, + }, - use { + { "romgrk/barbar.nvim", config = function() require "core.bufferline" + if lvim.builtin.bufferline.on_config_done then + lvim.builtin.bufferline.on_config_done() + end end, event = "BufWinEnter", - } + }, -- Debugging - use { + { "mfussenegger/nvim-dap", -- event = "BufWinEnter", config = function() require("core.dap").setup() + if lvim.builtin.dap.on_config_done then + lvim.builtin.dap.on_config_done(require "dap") + end end, - disable = not O.plugin.dap.active, - } + disable = not lvim.builtin.dap.active, + }, -- Debugger management - use { + { "Pocco81/DAPInstall.nvim", -- event = "BufWinEnter", -- event = "BufRead", - disable = not O.plugin.dap.active, - } - - -- Builtins, these do not load by default + disable = not lvim.builtin.dap.active, + }, -- Dashboard - use { + { "ChristianChiarulli/dashboard-nvim", event = "BufWinEnter", config = function() require("core.dashboard").setup() + if lvim.builtin.dashboard.on_config_done then + lvim.builtin.dashboard.on_config_done(require "dashboard") + end end, - disable = not O.plugin.dashboard.active, - } + disable = not lvim.builtin.dashboard.active, + }, - -- TODO: remove in favor of akinsho/nvim-toggleterm.lua - -- Floating terminal - use { - "numToStr/FTerm.nvim", + -- Terminal + { + "akinsho/nvim-toggleterm.lua", event = "BufWinEnter", config = function() - require("core.floatterm").setup() - end, - disable = not O.plugin.floatterm.active, - } - - -- Zen Mode - use { - "folke/zen-mode.nvim", - cmd = "ZenMode", - event = "BufRead", - config = function() - require("core.zen").setup() + require("core.terminal").setup() + if lvim.builtin.terminal.on_config_done then + lvim.builtin.terminal.on_config_done(require "toggleterm") + end end, - disable = not O.plugin.zen.active, - } - - --------------------------------------------------------------------------------- - - -- LANGUAGE SPECIFIC GOES HERE - use { - "lervag/vimtex", - ft = "tex", - } - - -- Rust tools - -- TODO: use lazy loading maybe? - use { - "simrat39/rust-tools.nvim", - disable = not O.lang.rust.rust_tools.active, - } - - -- Elixir - use { "elixir-editors/vim-elixir", ft = { "elixir", "eelixir", "euphoria3" } } - - -- Javascript / Typescript - use { - "jose-elias-alvarez/nvim-lsp-ts-utils", - ft = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - }, - } - - use { - "mfussenegger/nvim-jdtls", - -- ft = { "java" }, - disable = not O.lang.java.java_tools.active, - } - - -- Install user plugins - for _, plugin in pairs(O.user_plugins) do - packer.use(plugin) - end -end) + disable = not lvim.builtin.terminal.active, + }, +} diff --git a/lua/settings.lua b/lua/settings.lua index e4ee9e24..d96c1338 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -1,60 +1,78 @@ ---- HELPERS --- +local M = {} -local cmd = vim.cmd -local opt = vim.opt +M.load_options = function() + local opt = vim.opt ---- VIM ONLY COMMANDS --- + local default_options = { + backup = false, -- creates a backup file + clipboard = "unnamedplus", -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + colorcolumn = "99999", -- fixes indentline for now + completeopt = { "menuone", "noselect" }, + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = "utf-8", -- the encoding written to a file + foldmethod = "manual", -- folding, set to "expr" for treesitter based folding + foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding + guifont = "monospace:h17", -- the font used in graphical neovim applications + hidden = true, -- required to keep multiple buffers and open multiple buffers + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = "a", -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) + title = true, -- set the title of window to the value of the titlestring + -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to + undodir = CACHE_PATH .. "/undo", -- set an undo directory + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 2, -- the number of spaces inserted for each indentation + tabstop = 2, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = false, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + spell = false, + spelllang = "en", + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + } --- VIM ONLY COMMANDS ---cmd "filetype plugin on"cmd('let &titleold="' .. TERMINAL .. '"')cmd "set inccommand=split"cmd "set iskeyword+=-" -cmd "filetype plugin on" -cmd('let &titleold="' .. TERMINAL .. '"') -cmd "set inccommand=split" -cmd "set iskeyword+=-" + --- SETTINGS --- -if O.line_wrap_cursor_movement then - cmd "set whichwrap+=<,>,[,],h,l" -end + opt.shortmess:append "c" -if O.transparent_window then - cmd "au ColorScheme * hi Normal ctermbg=none guibg=none" - cmd "au ColorScheme * hi SignColumn ctermbg=none guibg=none" - cmd "let &fcs='eob: '" + for k, v in pairs(default_options) do + vim.opt[k] = v + end end ---- SETTINGS --- - -opt.shortmess:append "c" - -local disabled_built_ins = { - "netrw", - "netrwPlugin", - "netrwSettings", - "netrwFileHandlers", - "gzip", - "zip", - "zipPlugin", - "tar", - "tarPlugin", -- 'man', - "getscript", - "getscriptPlugin", - "vimball", - "vimballPlugin", - "2html_plugin", - "logipat", - "rrhelper", - "spellfile_plugin", - -- 'matchit', 'matchparen', 'shada_plugin', -} - -if O.leader_key == " " or O.leader_key == "space" then - vim.g.mapleader = ' ' -else - vim.g.mapleader = O.leader_key -end +M.load_commands = function() + local cmd = vim.cmd + if lvim.line_wrap_cursor_movement then + cmd "set whichwrap+=<,>,[,],h,l" + end -for _, plugin in pairs(disabled_built_ins) do - vim.g["loaded_" .. plugin] = 1 + if lvim.transparent_window then + cmd "au ColorScheme * hi Normal ctermbg=none guibg=none" + cmd "au ColorScheme * hi SignColumn ctermbg=none guibg=none" + cmd "au ColorScheme * hi NormalNC ctermbg=none guibg=none" + cmd "au ColorScheme * hi MsgArea ctermbg=none guibg=none" + cmd "au ColorScheme * hi TelescopeBorder ctermbg=none guibg=none" + cmd "au ColorScheme * hi NvimTreeNormal ctermbg=none guibg=none" + cmd "let &fcs='eob: '" + end end -for k, v in pairs(O.default_options) do - vim.opt[k] = v -end +return M diff --git a/lua/spacegray/Git.lua b/lua/spacegray/Git.lua index f1a2ed39..b47ccf23 100644 --- a/lua/spacegray/Git.lua +++ b/lua/spacegray/Git.lua @@ -1,10 +1,10 @@ local Git = { - SignAdd = {fg = C.sign_add, }, - SignChange = {fg = C.sign_change, }, - SignDelete = {fg = C.sign_delete, }, - GitSignsAdd = {fg = C.sign_add, }, - GitSignsChange = {fg = C.sign_change, }, - GitSignsDelete = {fg = C.sign_delete, }, + SignAdd = { fg = C.sign_add }, + SignChange = { fg = C.sign_change }, + SignDelete = { fg = C.sign_delete }, + GitSignsAdd = { fg = C.sign_add }, + GitSignsChange = { fg = C.sign_change }, + GitSignsDelete = { fg = C.sign_delete }, } -return Git
\ No newline at end of file +return Git diff --git a/lua/spacegray/LSP.lua b/lua/spacegray/LSP.lua index eb674175..2dfa07ff 100644 --- a/lua/spacegray/LSP.lua +++ b/lua/spacegray/LSP.lua @@ -1,92 +1,92 @@ local LSP = { - LspDiagnosticsDefaultError = {fg = C.error_red, }, - LspDiagnosticsDefaultWarning = {fg = C.warning_orange, }, - LspDiagnosticsDefaultInformation = {fg = C.info_yellow, }, - LspDiagnosticsDefaultHint = {fg = C.hint_blue, }, - LspDiagnosticsVirtualTextError = {fg = C.error_red, }, - LspDiagnosticsVirtualTextWarning = {fg = C.warning_orange, }, - LspDiagnosticsVirtualTextInformation = {fg = C.info_yellow, }, - LspDiagnosticsVirtualTextHint = {fg = C.hint_blue, }, - LspDiagnosticsFloatingError = {fg = C.error_red, }, - LspDiagnosticsFloatingWarning = {fg = C.warning_orange, }, - LspDiagnosticsFloatingInformation = {fg = C.info_yellow, }, - LspDiagnosticsFloatingHint = {fg = C.hint_blue, }, - LspDiagnosticsSignError = {fg = C.error_red, }, - LspDiagnosticsSignWarning = {fg = C.warning_orange, }, - LspDiagnosticsSignInformation = {fg = C.info_yellow, }, - LspDiagnosticsSignHint = {fg = C.hint_blue, }, - LspDiagnosticsError = {fg = C.error_red, }, - LspDiagnosticsWarning = {fg = C.warning_orange, }, - LspDiagnosticsInformation = {fg = C.info_yellow, }, - LspDiagnosticsHint = {fg = C.hint_blue, }, - LspDiagnosticsUnderlineError = {fg = C.error_red, }, - LspDiagnosticsUnderlineWarning = {fg = C.warning_orange, }, - LspDiagnosticsUnderlineInformation = {fg = C.info_yellow, }, - LspDiagnosticsUnderlineHint = {fg = C.hint_blue, }, - QuickScopePrimary = {fg = C.cyan_test, style = "underline", }, - QuickScopeSecondary = {fg = C.purple_test, style = "underline", }, - TelescopeSelection = {fg = C.hint_blue, }, - TelescopeMatching = {fg = C.info_yellow, style = "bold", }, - TelescopeBorder = {fg = C.cyan, bg = C.bg, }, - NvimTreeFolderIcon = {fg = C.blue, }, - NvimTreeIndentMarker = {fg = C.gray, }, - NvimTreeNormal = {fg = C.light_gray, bg = C.alt_bg, }, - NvimTreeVertSplit = {fg = C.alt_bg, bg = C.alt_bg, }, - NvimTreeFolderName = {fg = C.blue, }, - NvimTreeOpenedFolderName = {fg = C.cyan, style = "italic", }, - NvimTreeImageFile = {fg = C.purple, }, - NvimTreeSpecialFile = {fg = C.orange, }, - NvimTreeGitStaged = {fg = C.sign_add, }, - NvimTreeGitNew = {fg = C.sign_add, }, - NvimTreeGitDirty = {fg = C.sign_add, }, - NvimTreeGitDeleted = {fg = C.sign_delete, }, - NvimTreeGitMerge = {fg = C.sign_change, }, - NvimTreeGitRenamed = {fg = C.sign_change, }, - NvimTreeSymlink = {fg = C.cyan, }, - NvimTreeRootFolder = {fg = C.fg, style = "bold", }, - NvimTreeExecFile = {fg = C.green, }, - BufferCurrent = {fg = C.fg, bg = C.bg, }, - BufferCurrentIndex = {fg = C.fg, bg = C.bg, }, - BufferCurrentMod = {fg = C.info_yellow, bg = C.bg, }, - BufferCurrentSign = {fg = C.hint_blue, bg = C.bg, }, - BufferCurrentTarget = {fg = C.red, bg = C.bg, style = "bold", }, - BufferVisible = {fg = C.fg, bg = C.bg, }, - BufferVisibleIndex = {fg = C.fg, bg = C.bg, }, - BufferVisibleMod = {fg = C.info_yellow, bg = C.bg, }, - BufferVisibleSign = {fg = C.hint_blue, bg = C.bg, }, - BufferVisibleTarget = {fg = C.red, bg = C.bg, style = "bold", }, - BufferInactive = {fg = C.gray, bg = C.alt_bg, }, - BufferInactiveIndex = {fg = C.gray, bg = C.alt_bg, }, - BufferInactiveMod = {fg = C.info_yellow, bg = C.alt_bg, }, - BufferInactiveSign = {fg = C.gray, bg = C.alt_bg, }, - BufferInactiveTarget = {fg = C.red, bg = C.alt_bg, style = "bold", }, - StatusLine = {fg = C.alt_bg, }, - StatusLineNC = {fg = C.alt_bg, }, - StatusLineSeparator = {fg = C.alt_bg, }, - StatusLineTerm = {fg = C.alt_bg, }, - StatusLineTermNC = {fg = C.alt_bg, }, - CodiVirtualText = {fg = C.pale_purple, }, - IndentBlanklineContextChar = {fg = C.accent, }, - DashboardHeader = {fg = C.blue, }, - DashboardCenter = {fg = C.purple, }, - DashboardFooter = {fg = C.cyan, }, - CompeDocumentation = {bg = C.alt_bg, }, - DiffViewNormal = {fg = C.gray, bg = C.alt_bg, }, - DiffviewStatusAdded = {fg = C.sign_add, }, - DiffviewStatusModified = {fg = C.sign_change, }, - DiffviewStatusRenamed = {fg = C.sign_change, }, - DiffviewStatusDeleted = {fg = C.sign_delete, }, - DiffviewFilePanelInsertion = {fg = C.sign_add, }, - DiffviewFilePanelDeletion = {fg = C.sign_delete, }, - DiffviewVertSplit = {bg = C.bg, }, - diffAdded = {fg = C.sign_add, }, - diffRemoved = {fg = C.sign_delete, }, - diffFileId = {fg = C.blue, style = "bold,reverse", }, - diffFile = {fg = C.alt_bg, }, - diffNewFile = {fg = C.green, }, - diffOldFile = {fg = C.red, }, - debugPc = {bg = C.cyan, }, - debugBreakpoint = {fg = C.red, style = "reverse", }, + LspDiagnosticsDefaultError = { fg = C.error_red }, + LspDiagnosticsDefaultWarning = { fg = C.warning_orange }, + LspDiagnosticsDefaultInformation = { fg = C.info_yellow }, + LspDiagnosticsDefaultHint = { fg = C.hint_blue }, + LspDiagnosticsVirtualTextError = { fg = C.error_red }, + LspDiagnosticsVirtualTextWarning = { fg = C.warning_orange }, + LspDiagnosticsVirtualTextInformation = { fg = C.info_yellow }, + LspDiagnosticsVirtualTextHint = { fg = C.hint_blue }, + LspDiagnosticsFloatingError = { fg = C.error_red }, + LspDiagnosticsFloatingWarning = { fg = C.warning_orange }, + LspDiagnosticsFloatingInformation = { fg = C.info_yellow }, + LspDiagnosticsFloatingHint = { fg = C.hint_blue }, + LspDiagnosticsSignError = { fg = C.error_red }, + LspDiagnosticsSignWarning = { fg = C.warning_orange }, + LspDiagnosticsSignInformation = { fg = C.info_yellow }, + LspDiagnosticsSignHint = { fg = C.hint_blue }, + LspDiagnosticsError = { fg = C.error_red }, + LspDiagnosticsWarning = { fg = C.warning_orange }, + LspDiagnosticsInformation = { fg = C.info_yellow }, + LspDiagnosticsHint = { fg = C.hint_blue }, + LspDiagnosticsUnderlineError = { fg = C.error_red }, + LspDiagnosticsUnderlineWarning = { fg = C.warning_orange }, + LspDiagnosticsUnderlineInformation = { fg = C.info_yellow }, + LspDiagnosticsUnderlineHint = { fg = C.hint_blue }, + QuickScopePrimary = { fg = C.cyan_test, style = "underline" }, + QuickScopeSecondary = { fg = C.purple_test, style = "underline" }, + TelescopeSelection = { fg = C.hint_blue }, + TelescopeMatching = { fg = C.info_yellow, style = "bold" }, + TelescopeBorder = { fg = C.cyan, bg = C.bg }, + NvimTreeFolderIcon = { fg = C.blue }, + NvimTreeIndentMarker = { fg = C.gray }, + NvimTreeNormal = { fg = C.light_gray, bg = C.alt_bg }, + NvimTreeVertSplit = { fg = C.alt_bg, bg = C.alt_bg }, + NvimTreeFolderName = { fg = C.blue }, + NvimTreeOpenedFolderName = { fg = C.cyan, style = "italic" }, + NvimTreeImageFile = { fg = C.purple }, + NvimTreeSpecialFile = { fg = C.orange }, + NvimTreeGitStaged = { fg = C.sign_add }, + NvimTreeGitNew = { fg = C.sign_add }, + NvimTreeGitDirty = { fg = C.sign_add }, + NvimTreeGitDeleted = { fg = C.sign_delete }, + NvimTreeGitMerge = { fg = C.sign_change }, + NvimTreeGitRenamed = { fg = C.sign_change }, + NvimTreeSymlink = { fg = C.cyan }, + NvimTreeRootFolder = { fg = C.fg, style = "bold" }, + NvimTreeExecFile = { fg = C.green }, + BufferCurrent = { fg = C.fg, bg = C.bg }, + BufferCurrentIndex = { fg = C.fg, bg = C.bg }, + BufferCurrentMod = { fg = C.info_yellow, bg = C.bg }, + BufferCurrentSign = { fg = C.hint_blue, bg = C.bg }, + BufferCurrentTarget = { fg = C.red, bg = C.bg, style = "bold" }, + BufferVisible = { fg = C.fg, bg = C.bg }, + BufferVisibleIndex = { fg = C.fg, bg = C.bg }, + BufferVisibleMod = { fg = C.info_yellow, bg = C.bg }, + BufferVisibleSign = { fg = C.hint_blue, bg = C.bg }, + BufferVisibleTarget = { fg = C.red, bg = C.bg, style = "bold" }, + BufferInactive = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveIndex = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveMod = { fg = C.info_yellow, bg = C.alt_bg }, + BufferInactiveSign = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveTarget = { fg = C.red, bg = C.alt_bg, style = "bold" }, + StatusLine = { fg = C.alt_bg }, + StatusLineNC = { fg = C.alt_bg }, + StatusLineSeparator = { fg = C.alt_bg }, + StatusLineTerm = { fg = C.alt_bg }, + StatusLineTermNC = { fg = C.alt_bg }, + CodiVirtualText = { fg = C.pale_purple }, + IndentBlanklineContextChar = { fg = C.accent }, + DashboardHeader = { fg = C.blue }, + DashboardCenter = { fg = C.purple }, + DashboardFooter = { fg = C.cyan }, + CompeDocumentation = { bg = C.alt_bg }, + DiffViewNormal = { fg = C.gray, bg = C.alt_bg }, + DiffviewStatusAdded = { fg = C.sign_add }, + DiffviewStatusModified = { fg = C.sign_change }, + DiffviewStatusRenamed = { fg = C.sign_change }, + DiffviewStatusDeleted = { fg = C.sign_delete }, + DiffviewFilePanelInsertion = { fg = C.sign_add }, + DiffviewFilePanelDeletion = { fg = C.sign_delete }, + DiffviewVertSplit = { bg = C.bg }, + diffAdded = { fg = C.sign_add }, + diffRemoved = { fg = C.sign_delete }, + diffFileId = { fg = C.blue, style = "bold,reverse" }, + diffFile = { fg = C.alt_bg }, + diffNewFile = { fg = C.green }, + diffOldFile = { fg = C.red }, + debugPc = { bg = C.cyan }, + debugBreakpoint = { fg = C.red, style = "reverse" }, } -return LSP
\ No newline at end of file +return LSP diff --git a/lua/spacegray/Treesitter.lua b/lua/spacegray/Treesitter.lua index 95348406..01dfacb5 100644 --- a/lua/spacegray/Treesitter.lua +++ b/lua/spacegray/Treesitter.lua @@ -1,56 +1,56 @@ local Treesitter = { - TSComment = {fg = C.gray, }, - TSAnnotation = {fg = C.purple, }, - TSAttribute = {fg = C.cyan, }, - TSConstructor = {fg = C.purple, }, - TSType = {fg = C.purple, }, - TSTypeBuiltin = {fg = C.purple, }, - TSConditional = {fg = C.blue, }, - TSException = {fg = C.blue, }, - TSInclude = {fg = C.blue, }, - TSKeyword = {fg = C.blue, }, - TSKeywordFunction = {fg = C.blue, }, - TSLabel = {fg = C.blue, }, - TSNamespace = {fg = C.blue, }, - TSRepeat = {fg = C.blue, }, - TSConstant = {fg = C.orange, }, - TSConstBuiltin = {fg = C.orange, }, - TSFloat = {fg = C.red, }, - TSNumber = {fg = C.red, }, - TSBoolean = {fg = C.red, }, - TSCharacter = {fg = C.light_green, }, - TSError = {fg = C.error_red, }, - TSFunction = {fg = C.yellow, }, - TSFuncBuiltin = {fg = C.yellow, }, - TSMethod = {fg = C.yellow, }, - TSConstMacro = {fg = C.cyan, }, - TSFuncMacro = {fg = C.cyan, }, - TSVariable = {fg = C.white, }, - TSVariableBuiltin = {fg = C.cyan, }, - TSProperty = {fg = C.cyan, }, - TSOperator = {fg = C.gray_blue, }, - TSField = {fg = C.white, }, - TSParameter = {fg = C.white, }, - TSParameterReference = {fg = C.white, }, - TSSymbol = {fg = C.white, }, - TSText = {fg = C.fg, }, - TSPunctDelimiter = {fg = C.gray, }, - TSTagDelimiter = {fg = C.gray, }, - TSPunctBracket = {fg = C.gray, }, - TSPunctSpecial = {fg = C.gray, }, - TSString = {fg = C.green, }, - TSStringRegex = {fg = C.light_green, }, - TSStringEscape = {fg = C.light_green, }, - TSTag = {fg = C.blue, }, - TSEmphasis = {style = "italic", }, - TSUnderline = {style = "underline", }, - TSTitle = {fg = C.blue, style = "bold", }, - TSLiteral = {fg = C.green, }, - TSURI = {fg = C.cyan, style = "underline", }, - TSKeywordOperator = {fg = C.blue, }, - TSStructure = {fg = C.purple_test, }, - TSStrong = {fg = C.yellow, }, - TSQueryLinterError = {fg = C.warning_orange, }, + TSComment = { fg = C.gray }, + TSAnnotation = { fg = C.purple }, + TSAttribute = { fg = C.cyan }, + TSConstructor = { fg = C.purple }, + TSType = { fg = C.purple }, + TSTypeBuiltin = { fg = C.purple }, + TSConditional = { fg = C.blue }, + TSException = { fg = C.blue }, + TSInclude = { fg = C.blue }, + TSKeyword = { fg = C.blue }, + TSKeywordFunction = { fg = C.blue }, + TSLabel = { fg = C.blue }, + TSNamespace = { fg = C.blue }, + TSRepeat = { fg = C.blue }, + TSConstant = { fg = C.orange }, + TSConstBuiltin = { fg = C.orange }, + TSFloat = { fg = C.red }, + TSNumber = { fg = C.red }, + TSBoolean = { fg = C.red }, + TSCharacter = { fg = C.light_green }, + TSError = { fg = C.error_red }, + TSFunction = { fg = C.yellow }, + TSFuncBuiltin = { fg = C.yellow }, + TSMethod = { fg = C.yellow }, + TSConstMacro = { fg = C.cyan }, + TSFuncMacro = { fg = C.cyan }, + TSVariable = { fg = C.white }, + TSVariableBuiltin = { fg = C.cyan }, + TSProperty = { fg = C.cyan }, + TSOperator = { fg = C.gray_blue }, + TSField = { fg = C.white }, + TSParameter = { fg = C.white }, + TSParameterReference = { fg = C.white }, + TSSymbol = { fg = C.white }, + TSText = { fg = C.fg }, + TSPunctDelimiter = { fg = C.gray }, + TSTagDelimiter = { fg = C.gray }, + TSPunctBracket = { fg = C.gray }, + TSPunctSpecial = { fg = C.gray }, + TSString = { fg = C.green }, + TSStringRegex = { fg = C.light_green }, + TSStringEscape = { fg = C.light_green }, + TSTag = { fg = C.blue }, + TSEmphasis = { style = "italic" }, + TSUnderline = { style = "underline" }, + TSTitle = { fg = C.blue, style = "bold" }, + TSLiteral = { fg = C.green }, + TSURI = { fg = C.cyan, style = "underline" }, + TSKeywordOperator = { fg = C.blue }, + TSStructure = { fg = C.purple_test }, + TSStrong = { fg = C.yellow }, + TSQueryLinterError = { fg = C.warning_orange }, } -return Treesitter
\ No newline at end of file +return Treesitter diff --git a/lua/spacegray/Whichkey.lua b/lua/spacegray/Whichkey.lua index 2c02f11b..f382d784 100644 --- a/lua/spacegray/Whichkey.lua +++ b/lua/spacegray/Whichkey.lua @@ -1,9 +1,9 @@ local Whichkey = { - WhichKey = {fg = C.purple, }, - WhichKeySeperator = {fg = C.green, }, - WhichKeyGroup = {fg = C.blue, }, - WhichKeyDesc = {fg = C.cyan, }, - WhichKeyFloat = {bg = C.alt_bg, }, + WhichKey = { fg = C.purple }, + WhichKeySeperator = { fg = C.green }, + WhichKeyGroup = { fg = C.blue }, + WhichKeyDesc = { fg = C.cyan }, + WhichKeyFloat = { bg = C.alt_bg }, } -return Whichkey
\ No newline at end of file +return Whichkey diff --git a/lua/spacegray/config.lua b/lua/spacegray/config.lua index f9c10951..ebac7109 100644 --- a/lua/spacegray/config.lua +++ b/lua/spacegray/config.lua @@ -3,21 +3,21 @@ local config vim = vim or { g = {}, o = {} } local function opt(key, default) - if vim.g[key] == nil then - return default - end - if vim.g[key] == 0 then - return false - end - return vim.g[key] + if vim.g[key] == nil then + return default + end + if vim.g[key] == 0 then + return false + end + return vim.g[key] end config = { - transparent_background = opt("transparent_background", false), - italic_comments = opt("italic_keywords", true) and "italic" or "NONE", - italic_keywords = opt("italic_keywords", true) and "italic" or "NONE", - italic_functions = opt("italic_function", false) and "italic" or "NONE", - italic_variables = opt("italic_variables", true) and "italic" or "NONE", + transparent_background = opt("transparent_background", false), + italic_comments = opt("italic_keywords", true) and "italic" or "NONE", + italic_keywords = opt("italic_keywords", true) and "italic" or "NONE", + italic_functions = opt("italic_function", false) and "italic" or "NONE", + italic_variables = opt("italic_variables", true) and "italic" or "NONE", } -return config
\ No newline at end of file +return config diff --git a/lua/spacegray/highlights.lua b/lua/spacegray/highlights.lua index 9a20b46d..e8700d8f 100644 --- a/lua/spacegray/highlights.lua +++ b/lua/spacegray/highlights.lua @@ -1,99 +1,99 @@ local highlights = { - Normal = {fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg, }, - SignColumn = {bg = C.bg, }, - MsgArea = {fg = C.fg, bg = C.bg, }, - ModeMsg = {fg = C.fg, bg = C.bg, }, - MsgSeparator = {fg = C.fg, bg = C.bg, }, - SpellBad = {fg = C.error_red, style = "underline", }, - SpellCap = {fg = C.yellow, style = "underline", }, - SpellLocal = {fg = C.green, style = "underline", }, - SpellRare = {fg = C.purple, style = "underline", }, - NormalNC = {fg = C.fg, bg = C.bg, }, - Pmenu = {fg = C.white, bg = C.accent, }, - PmenuSel = {fg = C.alt_bg, bg = C.blue, }, - WildMenu = {fg = C.alt_bg, bg = C.blue, }, - CursorLineNr = {fg = C.light_gray, style = "bold", }, - Comment = {fg = C.gray, style = "italic", }, - Folded = {fg = C.accent, bg = C.alt_bg, }, - FoldColumn = {fg = C.accent, bg = C.alt_bg, }, - LineNr = {fg = C.gray, }, - FloatBoder = {fg = C.gray, bg = C.alt_bg, }, - Whitespace = {fg = C.gray, }, - VertSplit = {fg = C.bg, bg = C.accent, }, - CursorLine = {bg = C.alt_bg, }, - CursorColumn = {bg = C.alt_bg, }, - ColorColumn = {bg = C.alt_bg, }, - NormalFloat = {bg = C.alt_bg, }, - Visual = {bg = C.alt_bg, }, - VisualNOS = {bg = C.alt_bg, }, - WarningMsg = {fg = C.error_red, bg = C.bg, }, - DiffAdd = {fg = C.alt_bg, bg = C.sign_add, }, - DiffChange = {fg = C.alt_bg, bg = C.sign_change, style = "underline", }, - DiffDelete = {fg = C.alt_bg, bg = C.sign_delete, }, - QuickFixLine = {bg = C.accent, }, - PmenuSbar = {bg = C.alt_bg, }, - PmenuThumb = {bg = C.white, }, - MatchWord = {style = "underline", }, - MatchParen = {fg = C.pale_purple, bg = C.bg, style = "underline", }, - MatchWordCur = {style = "underline", }, - MatchParenCur = {style = "underline", }, - Cursor = {fg = C.cursor_fg, bg = C.cursor_bg, }, - lCursor = {fg = C.cursor_fg, bg = C.cursor_bg, }, - CursorIM = {fg = C.cursor_fg, bg = C.cursor_bg, }, - TermCursor = {fg = C.cursor_fg, bg = C.cursor_bg, }, - TermCursorNC = {fg = C.cursor_fg, bg = C.cursor_bg, }, - Conceal = {fg = C.accent, }, - Directory = {fg = C.blue, }, - SpecialKey = {fg = C.blue, style = "bold", }, - Title = {fg = C.blue, style = "bold", }, - ErrorMsg = {fg = C.error_red, bg = C.bg, style = "bold", }, - Search = {fg = C.hint_blue, bg = C.alt_bg, }, - IncSearch = {fg = C.hint_blue, bg = C.alt_bg, }, - Substitute = {fg = C.alt_bg, bg = C.gray_blue, }, - MoreMsg = {fg = C.cyan, }, - Question = {fg = C.cyan, }, - EndOfBuffer = {fg = C.bg, }, - NonText = {fg = C.bg, }, - Variable = {fg = C.white, }, - String = {fg = C.green, }, - Character = {fg = C.light_green, }, - Constant = {fg = C.orange, }, - Number = {fg = C.red, }, - Boolean = {fg = C.red, }, - Float = {fg = C.red, }, - Identifier = {fg = C.white, }, - Function = {fg = C.yellow, }, - Operator = {fg = C.gray_blue, }, - Type = {fg = C.purple, }, - StorageClass = {fg = C.purple, }, - Structure = {fg = C.purple, }, - Typedef = {fg = C.purple, }, - Keyword = {fg = C.blue, }, - Statement = {fg = C.blue, }, - Conditional = {fg = C.blue, }, - Repeat = {fg = C.blue, }, - Label = {fg = C.blue, }, - Exception = {fg = C.blue, }, - Include = {fg = C.blue, }, - PreProc = {fg = C.cyan, }, - Define = {fg = C.cyan, }, - Macro = {fg = C.cyan, }, - PreCondit = {fg = C.cyan, }, - Special = {fg = C.orange, }, - SpecialChar = {fg = C.orange, }, - Tag = {fg = C.blue, }, - Debug = {fg = C.red, }, - Delimiter = {fg = C.gray, }, - SpecialComment = {fg = C.gray, }, - Underlined = {style = "underline", }, - Bold = {style = "bold", }, - Italic = {style = "italic", }, - Ignore = {fg = C.cyan, bg = C.bg, style = "bold", }, - Todo = {fg = C.red, bg = C.bg, style = "bold", }, - Error = {fg = C.error_red, bg = C.bg, style = "bold", }, - TabLine = {fg = C.white, bg = C.alt_bg, }, - TabLineSel = {fg = C.white, bg = C.alt_bg, }, - TabLineFill = {fg = C.white, bg = C.alt_bg, }, + Normal = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, + SignColumn = { bg = C.bg }, + MsgArea = { fg = C.fg, bg = C.bg }, + ModeMsg = { fg = C.fg, bg = C.bg }, + MsgSeparator = { fg = C.fg, bg = C.bg }, + SpellBad = { fg = C.error_red, style = "underline" }, + SpellCap = { fg = C.yellow, style = "underline" }, + SpellLocal = { fg = C.green, style = "underline" }, + SpellRare = { fg = C.purple, style = "underline" }, + NormalNC = { fg = C.fg, bg = C.bg }, + Pmenu = { fg = C.white, bg = C.accent }, + PmenuSel = { fg = C.alt_bg, bg = C.blue }, + WildMenu = { fg = C.alt_bg, bg = C.blue }, + CursorLineNr = { fg = C.light_gray, style = "bold" }, + Comment = { fg = C.gray, style = "italic" }, + Folded = { fg = C.accent, bg = C.alt_bg }, + FoldColumn = { fg = C.accent, bg = C.alt_bg }, + LineNr = { fg = C.gray }, + FloatBorder = { fg = C.gray, bg = C.alt_bg }, + Whitespace = { fg = C.gray }, + VertSplit = { fg = C.bg, bg = C.accent }, + CursorLine = { bg = C.alt_bg }, + CursorColumn = { bg = C.alt_bg }, + ColorColumn = { bg = C.alt_bg }, + NormalFloat = { bg = C.alt_bg }, + Visual = { bg = C.alt_bg }, + VisualNOS = { bg = C.alt_bg }, + WarningMsg = { fg = C.warning_orange, bg = C.bg }, + DiffAdd = { fg = C.alt_bg, bg = C.sign_add }, + DiffChange = { fg = C.alt_bg, bg = C.sign_change, style = "underline" }, + DiffDelete = { fg = C.alt_bg, bg = C.sign_delete }, + QuickFixLine = { bg = C.accent }, + PmenuSbar = { bg = C.alt_bg }, + PmenuThumb = { bg = C.white }, + MatchWord = { style = "underline" }, + MatchParen = { fg = C.pale_purple, bg = C.bg, style = "underline" }, + MatchWordCur = { style = "underline" }, + MatchParenCur = { style = "underline" }, + Cursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + lCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + CursorIM = { fg = C.cursor_fg, bg = C.cursor_bg }, + TermCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + TermCursorNC = { fg = C.cursor_fg, bg = C.cursor_bg }, + Conceal = { fg = C.accent }, + Directory = { fg = C.blue }, + SpecialKey = { fg = C.blue, style = "bold" }, + Title = { fg = C.blue, style = "bold" }, + ErrorMsg = { fg = C.error_red, bg = C.bg, style = "bold" }, + Search = { fg = C.hint_blue, bg = C.alt_bg }, + IncSearch = { fg = C.hint_blue, bg = C.alt_bg }, + Substitute = { fg = C.alt_bg, bg = C.gray_blue }, + MoreMsg = { fg = C.cyan }, + Question = { fg = C.cyan }, + EndOfBuffer = { fg = C.bg }, + NonText = { fg = C.bg }, + Variable = { fg = C.white }, + String = { fg = C.green }, + Character = { fg = C.light_green }, + Constant = { fg = C.orange }, + Number = { fg = C.red }, + Boolean = { fg = C.red }, + Float = { fg = C.red }, + Identifier = { fg = C.white }, + Function = { fg = C.yellow }, + Operator = { fg = C.gray_blue }, + Type = { fg = C.purple }, + StorageClass = { fg = C.purple }, + Structure = { fg = C.purple }, + Typedef = { fg = C.purple }, + Keyword = { fg = C.blue }, + Statement = { fg = C.blue }, + Conditional = { fg = C.blue }, + Repeat = { fg = C.blue }, + Label = { fg = C.blue }, + Exception = { fg = C.blue }, + Include = { fg = C.blue }, + PreProc = { fg = C.cyan }, + Define = { fg = C.cyan }, + Macro = { fg = C.cyan }, + PreCondit = { fg = C.cyan }, + Special = { fg = C.orange }, + SpecialChar = { fg = C.orange }, + Tag = { fg = C.blue }, + Debug = { fg = C.red }, + Delimiter = { fg = C.gray }, + SpecialComment = { fg = C.gray }, + Underlined = { style = "underline" }, + Bold = { style = "bold" }, + Italic = { style = "italic" }, + Ignore = { fg = C.cyan, bg = C.bg, style = "bold" }, + Todo = { fg = C.red, bg = C.bg, style = "bold" }, + Error = { fg = C.error_red, bg = C.bg, style = "bold" }, + TabLine = { fg = C.white, bg = C.alt_bg }, + TabLineSel = { fg = C.white, bg = C.alt_bg }, + TabLineFill = { fg = C.white, bg = C.alt_bg }, } -return highlights
\ No newline at end of file +return highlights diff --git a/lua/spacegray/init.lua b/lua/spacegray/init.lua index 0a8e748e..8da13a06 100644 --- a/lua/spacegray/init.lua +++ b/lua/spacegray/init.lua @@ -1,26 +1,30 @@ -vim.api.nvim_command("hi clear") -if vim.fn.exists("syntax_on") then - vim.api.nvim_command("syntax reset") +vim.api.nvim_command "hi clear" +if vim.fn.exists "syntax_on" then + vim.api.nvim_command "syntax reset" end vim.o.background = "dark" vim.o.termguicolors = true vim.g.colors_name = "spacegray" -local util = require("spacegray.util") -Config = require("spacegray.config") -C = require("spacegray.palette") -local highlights = require("spacegray.highlights") -local Treesitter = require("spacegray.Treesitter") -local markdown = require("spacegray.markdown") -local Whichkey = require("spacegray.Whichkey") -local Git = require("spacegray.Git") -local LSP = require("spacegray.LSP") - +local util = require "spacegray.util" +Config = require "spacegray.config" +C = require "spacegray.palette" +local highlights = require "spacegray.highlights" +local Treesitter = require "spacegray.Treesitter" +local markdown = require "spacegray.markdown" +local Whichkey = require "spacegray.Whichkey" +local Git = require "spacegray.Git" +local LSP = require "spacegray.LSP" local skeletons = { - highlights, Treesitter, markdown, Whichkey, Git, LSP + highlights, + Treesitter, + markdown, + Whichkey, + Git, + LSP, } for _, skeleton in ipairs(skeletons) do - util.initialise(skeleton) -end
\ No newline at end of file + util.initialise(skeleton) +end diff --git a/lua/spacegray/markdown.lua b/lua/spacegray/markdown.lua index 19863dc8..2b83e056 100644 --- a/lua/spacegray/markdown.lua +++ b/lua/spacegray/markdown.lua @@ -1,27 +1,27 @@ local markdown = { - markdownBlockquote = {fg = C.accent, }, - markdownBold = {fg = C.yellow, style = "bold", }, - markdownCode = {fg = C.green, }, - markdownCodeBlock = {fg = C.green, }, - markdownCodeDelimiter = {fg = C.green, }, - markdownH1 = {fg = C.blue, }, - markdownH2 = {fg = C.blue, }, - markdownH3 = {fg = C.blue, }, - markdownH4 = {fg = C.blue, }, - markdownH5 = {fg = C.blue, }, - markdownH6 = {fg = C.blue, }, - markdownHeadingDelimiter = {fg = C.red, }, - markdownHeadingRule = {fg = C.accent, }, - markdownId = {fg = C.purple, }, - markdownIdDeclaration = {fg = C.blue, }, - markdownIdDelimiter = {fg = C.light_gray, }, - markdownLinkDelimiter = {fg = C.light_gray, }, - markdownItalic = {style = "italic", }, - markdownLinkText = {fg = C.blue, }, - markdownListMarker = {fg = C.red, }, - markdownOrderedListMarker = {fg = C.red, }, - markdownRule = {fg = C.accent, }, - markdownUrl = {fg = C.cyan, style = "underline", }, + markdownBlockquote = { fg = C.accent }, + markdownBold = { fg = C.yellow, style = "bold" }, + markdownCode = { fg = C.green }, + markdownCodeBlock = { fg = C.green }, + markdownCodeDelimiter = { fg = C.green }, + markdownH1 = { fg = C.blue }, + markdownH2 = { fg = C.blue }, + markdownH3 = { fg = C.blue }, + markdownH4 = { fg = C.blue }, + markdownH5 = { fg = C.blue }, + markdownH6 = { fg = C.blue }, + markdownHeadingDelimiter = { fg = C.red }, + markdownHeadingRule = { fg = C.accent }, + markdownId = { fg = C.purple }, + markdownIdDeclaration = { fg = C.blue }, + markdownIdDelimiter = { fg = C.light_gray }, + markdownLinkDelimiter = { fg = C.light_gray }, + markdownItalic = { style = "italic" }, + markdownLinkText = { fg = C.blue }, + markdownListMarker = { fg = C.red }, + markdownOrderedListMarker = { fg = C.red }, + markdownRule = { fg = C.accent }, + markdownUrl = { fg = C.cyan, style = "underline" }, } -return markdown
\ No newline at end of file +return markdown diff --git a/lua/spacegray/util.lua b/lua/spacegray/util.lua index 1cc5a009..dbac18a2 100644 --- a/lua/spacegray/util.lua +++ b/lua/spacegray/util.lua @@ -1,22 +1,25 @@ local M = {} local function highlight(group, properties) - local bg = properties.bg == nil and "" or "guibg=" .. properties.bg - local fg = properties.fg == nil and "" or "guifg=" .. properties.fg - local style = properties.style == nil and "" or "gui=" .. properties.style + local bg = properties.bg == nil and "" or "guibg=" .. properties.bg + local fg = properties.fg == nil and "" or "guifg=" .. properties.fg + local style = properties.style == nil and "" or "gui=" .. properties.style - local cmd = table.concat({ - "highlight", group, bg, fg, style - }, " ") + local cmd = table.concat({ + "highlight", + group, + bg, + fg, + style, + }, " ") - vim.api.nvim_command(cmd) + vim.api.nvim_command(cmd) end - function M.initialise(skeleton) - for group, properties in pairs(skeleton) do - highlight(group, properties) - end + for group, properties in pairs(skeleton) do + highlight(group, properties) + end end -return M
\ No newline at end of file +return M diff --git a/lua/utils/init.lua b/lua/utils/init.lua new file mode 100644 index 00000000..94058487 --- /dev/null +++ b/lua/utils/init.lua @@ -0,0 +1,149 @@ +local utils = {} + +-- recursive Print (structure, limit, separator) +local function r_inspect_settings(structure, limit, separator) + limit = limit or 100 -- default item limit + separator = separator or "." -- indent string + if limit < 1 then + print "ERROR: Item limit reached." + return limit - 1 + end + if structure == nil then + io.write("-- O", separator:sub(2), " = nil\n") + return limit - 1 + end + local ts = type(structure) + + if ts == "table" then + for k, v in pairs(structure) do + -- replace non alpha keys wih ["key"] + if tostring(k):match "[^%a_]" then + k = '["' .. tostring(k) .. '"]' + end + limit = r_inspect_settings(v, limit, separator .. "." .. tostring(k)) + if limit < 0 then + break + end + end + return limit + end + + if ts == "string" then + -- escape sequences + structure = string.format("%q", structure) + end + separator = separator:gsub("%.%[", "%[") + if type(structure) == "function" then + -- don't print functions + io.write("-- lvim", separator:sub(2), " = function ()\n") + else + io.write("lvim", separator:sub(2), " = ", tostring(structure), "\n") + end + return limit - 1 +end + +function utils.generate_settings() + -- Opens a file in append mode + local file = io.open("lv-settings.lua", "w") + + -- sets the default output file as test.lua + io.output(file) + + -- write all `lvim` related settings to `lv-settings.lua` file + r_inspect_settings(lvim, 10000, ".") + + -- closes the open file + io.close(file) +end + +-- autoformat +function utils.toggle_autoformat() + if lvim.format_on_save then + require("core.autocmds").define_augroups { + autoformat = { + { + "BufWritePre", + "*", + ":silent lua vim.lsp.buf.formatting_sync()", + }, + }, + } + end + + if not lvim.format_on_save then + vim.cmd [[ + if exists('#autoformat#BufWritePre') + :autocmd! autoformat + endif + ]] + end +end + +function utils.reload_lv_config() + vim.cmd "source ~/.local/share/lunarvim/lvim/lua/settings.lua" + vim.cmd "source ~/.config/lvim/lv-config.lua" + vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua" + local plugins = require "plugins" + local plugin_loader = require("plugin-loader").init() + utils.toggle_autoformat() + plugin_loader:load { plugins, lvim.plugins } + vim.cmd ":PackerCompile" + vim.cmd ":PackerInstall" + -- vim.cmd ":PackerClean" +end + +function utils.check_lsp_client_active(name) + local clients = vim.lsp.get_active_clients() + for _, client in pairs(clients) do + if client.name == name then + return true + end + end + return false +end + +function utils.add_keymap(mode, opts, keymaps) + for _, keymap in ipairs(keymaps) do + vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts) + end +end + +function utils.add_keymap_normal_mode(opts, keymaps) + utils.add_keymap("n", opts, keymaps) +end + +function utils.add_keymap_visual_mode(opts, keymaps) + utils.add_keymap("v", opts, keymaps) +end + +function utils.add_keymap_visual_block_mode(opts, keymaps) + utils.add_keymap("x", opts, keymaps) +end + +function utils.add_keymap_insert_mode(opts, keymaps) + utils.add_keymap("i", opts, keymaps) +end + +function utils.add_keymap_term_mode(opts, keymaps) + utils.add_keymap("t", opts, keymaps) +end + +function utils.unrequire(m) + package.loaded[m] = nil + _G[m] = nil +end + +function utils.gsub_args(args) + if args == nil or type(args) ~= "table" then + return args + end + local buffer_filepath = vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) + for i = 1, #args do + args[i] = string.gsub(args[i], "${FILEPATH}", buffer_filepath) + end + return args +end + +return utils + +-- TODO: find a new home for these autocommands |