diff --git a/lua/core/cli.lua b/lua/core/cli.lua index c20047f..2da2e81 100644 --- a/lua/core/cli.lua +++ b/lua/core/cli.lua @@ -2,192 +2,164 @@ local cli = {} local helper = require('core.helper') function cli:env_init() - self.module_path = helper.path_join(self.config_path, 'lua', 'modules') - self.lazy_dir = helper.path_join(self.data_path, 'lazy') - - package.path = package.path - .. ';' - .. self.rtp - .. '/lua/vim/?.lua;' - .. self.module_path - .. '/?.lua;' - local shared = assert(loadfile(helper.path_join(self.rtp, 'lua', 'vim', 'shared.lua'))) - _G.vim = shared() + self.module_path = helper.path_join(self.config_path, 'lua', 'modules') + self.lazy_dir = helper.path_join(self.data_path, 'lazy') + + package.path = package.path .. ';' .. self.rtp .. '/lua/vim/?.lua;' .. + self.module_path .. '/?.lua;' + local shared = assert(loadfile(helper.path_join(self.rtp, 'lua', 'vim', + 'shared.lua'))) + _G.vim = shared() end function cli:get_all_packages() - local pack = require('core.pack') - local p = io.popen('find "' .. cli.module_path .. '" -type f') - if not p then - return - end - - for file in p:lines() do - if file:find('package.lua') then - local module = file:match(cli.module_path .. '/(.+).lua$') - require(module) - end - end - p:close() - - local lazy_keyword = { - 'keys', - 'ft', - 'cmd', - 'event', - 'lazy', - } - - local function generate_node(tbl, list) - local node = tbl[1] - list[node] = {} - list[node].type = tbl.dev and 'Local Plugin' or 'Remote Plugin' - - local check_lazy = function(t, data) - vim.tbl_filter(function(k) - if vim.tbl_contains(lazy_keyword, k) then - data.load = type(t[k]) == 'table' and table.concat(t[k], ',') or t[k] - return true + local pack = require('core.pack') + local p = io.popen('find "' .. cli.module_path .. '" -type f') + if not p then return end + + for file in p:lines() do + if file:find('package.lua') then + local module = file:match(cli.module_path .. '/(.+).lua$') + require(module) end - return false - end, vim.tbl_keys(t)) end + p:close() + + local lazy_keyword = {'keys', 'ft', 'cmd', 'event', 'lazy'} + + local function generate_node(tbl, list) + local node = tbl[1] + list[node] = {} + list[node].type = tbl.dev and 'Local Plugin' or 'Remote Plugin' + + local check_lazy = function(t, data) + vim.tbl_filter(function(k) + if vim.tbl_contains(lazy_keyword, k) then + data.load = type(t[k]) == 'table' and + table.concat(t[k], ',') or t[k] + return true + end + return false + end, vim.tbl_keys(t)) + end - check_lazy(tbl, list[node]) + check_lazy(tbl, list[node]) - if tbl.dependencies then - for _, v in pairs(tbl.dependencies) do - if type(v) == 'string' then - v = { v } - end + if tbl.dependencies then + for _, v in pairs(tbl.dependencies) do + if type(v) == 'string' then v = {v} end - list[v[1]] = { - from_depend = true, - load_after = node, - } + list[v[1]] = {from_depend = true, load_after = node} - list[v[1]].type = v.dev and 'Local Plugin' or 'Remote Plugin' - check_lazy(v, list[v[1]]) - end + list[v[1]].type = v.dev and 'Local Plugin' or 'Remote Plugin' + check_lazy(v, list[v[1]]) + end + end end - end - local list = {} - for _, data in pairs(pack.repos or {}) do - if type(data) == string then - data = { data } + local list = {} + for _, data in pairs(pack.repos or {}) do + if type(data) == string then data = {data} end + generate_node(data, list) end - generate_node(data, list) - end - return list + return list end function cli:boot_strap() - helper.blue('🔸 Search plugin management lazy.nvim in local') - if helper.isdir(self.lazy_dir) then - helper.green('🔸 Found lazy.nvim skip download') - return - end - helper.run_git('lazy.nvim', 'git clone https://github.com/folke/lazy.nvim ' .. self.lazy_dir, 'Install') - helper.success('lazy.nvim') + helper.blue('🔸 Search plugin management lazy.nvim in local') + if helper.isdir(self.lazy_dir) then + helper.green('🔸 Found lazy.nvim skip download') + return + end + helper.run_git('lazy.nvim', + 'git clone https://github.com/folke/lazy.nvim ' .. + self.lazy_dir, 'Install') + helper.success('lazy.nvim') end function cli:installer(type) - cli:boot_strap() - - local packages = cli:get_all_packages() - ---@diagnostic disable-next-line: unused-local, param-type-mismatch - local res = {} - for name, v in pairs(packages or {}) do - if v.type:find('Remote') then - local non_user_name = vim.split(name, '/')[2] - local path = self.lazy_dir .. helper.path_sep .. non_user_name - if helper.isdir(path) and type == 'install' then - helper.purple('\t🥯 Skip already in plugin ' .. name) - else - local url = 'git clone https://github.com/' - local cmd = type == 'install' and url .. name .. ' ' .. path or 'git -C ' .. path .. ' pull' - local failed = helper.run_git(name, cmd, type) - table.insert(res, failed) - end - else - helper.purple('\t🥯 Skip local plugin ' .. name) + cli:boot_strap() + + local packages = cli:get_all_packages() + ---@diagnostic disable-next-line: unused-local, param-type-mismatch + local res = {} + for name, v in pairs(packages or {}) do + if v.type:find('Remote') then + local non_user_name = vim.split(name, '/')[2] + local path = self.lazy_dir .. helper.path_sep .. non_user_name + if helper.isdir(path) and type == 'install' then + helper.purple('\t🥯 Skip already in plugin ' .. name) + else + local url = 'git clone https://github.com/' + local cmd = type == 'install' and url .. name .. ' ' .. path or + 'git -C ' .. path .. ' pull' + local failed = helper.run_git(name, cmd, type) + table.insert(res, failed) + end + else + helper.purple('\t🥯 Skip local plugin ' .. name) + end + end + if not vim.tbl_contains(res, true) then + helper.green( + '🎉 Congratulations Config install or update success. Enjoy ^^') + return end - end - if not vim.tbl_contains(res, true) then - helper.green('🎉 Congratulations Config install or update success. Enjoy ^^') - return - end - helper.red('Some plugins not install or update success please run install again') + helper.red( + 'Some plugins not install or update success please run install again') end -function cli.install() - cli:installer('install') -end +function cli.install() cli:installer('install') end -function cli.update() - cli:installer('update') -end +function cli.update() cli:installer('update') end -function cli.clean() - os.execute('rm -rf ' .. cli.lazy_dir) -end +function cli.clean() os.execute('rm -rf ' .. cli.lazy_dir) end function cli.doctor(pack_name) - local list = cli:get_all_packages() - if not list then - return - end - - helper.yellow('🔹 Total: ' .. vim.tbl_count(list) + 1 .. ' Plugins') - local packs = pack_name and { [pack_name] = list[pack_name] } or list - for k, v in pairs(packs) do - helper.blue('\t' .. '✨' .. k) - if v.type then - helper.write('purple')('\tType: ') - helper.write('white')(v.type) - print() - end - if v.load then - helper.write('purple')('\tLoad: ') - helper.write('white')(v.load) - print() - end + local list = cli:get_all_packages() + if not list then return end + + helper.yellow('🔹 Total: ' .. vim.tbl_count(list) + 1 .. ' Plugins') + local packs = pack_name and {[pack_name] = list[pack_name]} or list + for k, v in pairs(packs) do + helper.blue('\t' .. '✨' .. k) + if v.type then + helper.write('purple')('\tType: ') + helper.write('white')(v.type) + print() + end + if v.load then + helper.write('purple')('\tLoad: ') + helper.write('white')(v.load) + print() + end - if v.from_depend then - helper.write('purple')('\tDepend: ') - helper.write('white')(v.load_after) - print() + if v.from_depend then + helper.write('purple')('\tDepend: ') + helper.write('white')(v.load_after) + print() + end end - end end function cli.modules() - local p = io.popen('find "' .. cli.module_path .. '" -type d') - if not p then - return - end - local res = {} - - for dict in p:lines() do - dict = vim.split(dict, helper.path_sep) - if dict[#dict] ~= 'modules' then - table.insert(res, dict[#dict]) + local p = io.popen('find "' .. cli.module_path .. '" -type d') + if not p then return end + local res = {} + + for dict in p:lines() do + dict = vim.split(dict, helper.path_sep) + if dict[#dict] ~= 'modules' then table.insert(res, dict[#dict]) end end - end - helper.green('Found ' .. #res .. ' Modules in Local') - for _, v in pairs(res) do - helper.write('yellow')('\t✅ ' .. v) - print() - end + helper.green('Found ' .. #res .. ' Modules in Local') + for _, v in pairs(res) do + helper.write('yellow')('\t✅ ' .. v) + print() + end end -function cli:meta(arg) - return function(data) - self[arg](data) - end -end +function cli:meta(arg) return function(data) self[arg](data) end end return cli diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index bf48423..17efb96 100644 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -85,4 +85,20 @@ nmap({ }) -- ToggleTerm -tmap({"", '', opts(noremap, silent)}) +tmap({'', '', opts(noremap, silent)}) + +-- lspsage +nmap({ + {'gh', cmd('Lspsaga tyd+ref+imp+def'), opts(noremap, silent)}, + {'gi', cmd('Lspsaga incoming_calls'), opts(noremap, silent)}, + {'go', cmd('Lspsaga outgoing_calls'), opts(noremap, silent)}, + {'gd', cmd('Lspsaga peek_type_definition'), opts(noremap, silent)}, + {'gk', cmd('Lspsaga hover_doc'), opts(noremap, silent)}, + {'gr', cmd('Lspsaga rename'), opts(noremap, silent)}, + {'gg', cmd('Lspsaga outline'), opts(noremap, silent)}, + {'gn', cmd('Lspsaga finder imp'), opts(noremap, silent)}, + {'ga', cmd('Lspsaga code_action'), opts(noremap, silent)} +}) + +-- lint and fmt +nmap({'v', cmd('GuardFmt'), opts(noremap, silent)}) diff --git a/lua/modules/completion/config.lua b/lua/modules/completion/config.lua index 1ea1a91..b2d3a33 100644 --- a/lua/modules/completion/config.lua +++ b/lua/modules/completion/config.lua @@ -2,7 +2,7 @@ local config = {} -- config server in this function function config.nvim_lsp() - local lspconfig = require("lspconfig") + local lspconfig = require('lspconfig') local on_attach = function(client, bufnr) local function buf_set_keymap(...) @@ -16,7 +16,7 @@ function config.nvim_lsp() end -- setup python lspconfig - lspconfig.pyright.setup { + lspconfig.pyright.setup({ on_attach = on_attach, settings = { python = { @@ -26,9 +26,9 @@ function config.nvim_lsp() } } } - } + }) -- setup go lspconfig - lspconfig.gopls.setup {} + lspconfig.gopls.setup({}) -- setup lua lspconfig lspconfig.lua_ls.setup({ settings = { @@ -50,10 +50,9 @@ function config.nvim_lsp() } }) -- config clangd - lspconfig.clangd.setup {} + lspconfig.clangd.setup({}) -- config rust - lspconfig.rust_analyzer.setup {} - + lspconfig.rust_analyzer.setup({}) end function config.nvim_cmp() @@ -63,7 +62,7 @@ function config.nvim_cmp() snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + vim.fn['vsnip#anonymous'](args.body) -- For `vsnip` users. -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. -- require('snippy').expand_snippet(args.body) -- For `snippy` users. -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. @@ -112,7 +111,7 @@ function config.nvim_cmp() lsp['capabilities'] = capabilities end - require("copilot_cmp").setup() + require('copilot_cmp').setup() end function config.lua_snip() @@ -138,8 +137,8 @@ end function config.lspsaga() require('lspsaga').setup({}) end function config.copilot_nvim() - require("copilot").setup({ - cmp = {enabled = true, method = "getCompletionsCycling"}, + require('copilot').setup({ + cmp = {enabled = true, method = 'getCompletionsCycling'}, panel = {enabled = false}, suggestion = {enabled = true} }) diff --git a/lua/modules/completion/package.lua b/lua/modules/completion/package.lua index 0cd6a66..6801a72 100644 --- a/lua/modules/completion/package.lua +++ b/lua/modules/completion/package.lua @@ -5,7 +5,7 @@ package({ 'neovim/nvim-lspconfig', -- used filetype to lazyload lsp -- config your language filetype in here - ft = {'lua', 'python', 'go', 'rust', 'c', 'cpp', 'proto'}, + ft = {'lua', 'python', 'go', 'rust', 'c', 'cpp'}, config = conf.nvim_lsp }) @@ -15,9 +15,9 @@ package({ cmd = 'Lspsaga term_toggle', config = conf.lspsaga, dependencies = { - {"nvim-tree/nvim-web-devicons"}, + {'nvim-tree/nvim-web-devicons'}, -- Please make sure you install markdown and markdown_inline parser - {"nvim-treesitter/nvim-treesitter"} + {'nvim-treesitter/nvim-treesitter'} } }) diff --git a/lua/modules/editor/config.lua b/lua/modules/editor/config.lua index 9fb9ed9..a868c80 100644 --- a/lua/modules/editor/config.lua +++ b/lua/modules/editor/config.lua @@ -25,4 +25,29 @@ function config.nvim_treesitter() }) end +function config.guard_config() + local ft = require('guard.filetype') + + -- use clang-format and clang-tidy for c/cpp files + ft('c'):fmt('clang-format'):lint('clang-tidy') + + ft('cpp'):fmt('clang-format'):lint('clang-tidy') + + -- use stylua to format lua files and no linter + ft('lua'):fmt('stylua') + + ft('rust'):fmt('rustfmt') + + -- multiple files register + ft('typescript,javascript,typescriptreact'):fmt('prettier') + + -- call setup LAST + require('guard').setup({ + -- the only options for the setup function + fmt_on_save = true, + -- Use lsp if no formatter was defined for this filetype + lsp_as_default_formatter = false + }) +end + return config diff --git a/lua/modules/editor/package.lua b/lua/modules/editor/package.lua index c1423f7..e01d6dd 100644 --- a/lua/modules/editor/package.lua +++ b/lua/modules/editor/package.lua @@ -2,11 +2,11 @@ local package = require('core.pack').package local conf = require('modules.editor.config') package({ - 'nvim-treesitter/nvim-treesitter', - event = 'BufRead', - run = ':TSUpdate', - config = conf.nvim_treesitter, - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - }, + 'nvim-treesitter/nvim-treesitter', + event = 'BufRead', + run = ':TSUpdate', + config = conf.nvim_treesitter, + dependencies = {'nvim-treesitter/nvim-treesitter-textobjects'} }) + +package({'nvimdev/guard.nvim', config = conf.guard_config}) diff --git a/lua/modules/tools/config.lua b/lua/modules/tools/config.lua index 9b6e522..a83ca14 100644 --- a/lua/modules/tools/config.lua +++ b/lua/modules/tools/config.lua @@ -25,10 +25,9 @@ function config.telescope() require('telescope').load_extension('media_files') require('telescope').load_extension('project') require('telescope').load_extension('z') - require("telescope").load_extension("git_worktree") + require('telescope').load_extension('git_worktree') require('telescope').load_extension('git_diffs') - require("telescope").load_extension("lazy") - + require('telescope').load_extension('lazy') end return config diff --git a/lua/modules/tools/package.lua b/lua/modules/tools/package.lua index 1d7a94d..743b573 100644 --- a/lua/modules/tools/package.lua +++ b/lua/modules/tools/package.lua @@ -30,7 +30,7 @@ package({ package({ 'folke/which-key.nvim', - config = function() require("which-key").setup() end + config = function() require('which-key').setup() end }) package({'sindrets/diffview.nvim'}) diff --git a/lua/modules/ui/config.lua b/lua/modules/ui/config.lua index 70bec01..b03c52f 100644 --- a/lua/modules/ui/config.lua +++ b/lua/modules/ui/config.lua @@ -87,7 +87,7 @@ function config.lualine() } } - require('lualine').setup { + local config = { options = { theme = bubbles_theme, component_separators = '|', @@ -117,27 +117,53 @@ function config.lualine() extensions = {} } + local function ins_left(component) + table.insert(config.sections.lualine_c, component) + end + + local function ins_right(component) + table.insert(config.sections.lualine_x, component) + end + ins_left({ + -- Lsp server name . + function() + local msg = 'No Active Lsp' + local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype') + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then return msg end + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + return client.name + end + end + return msg + end, + icon = ' LSP:', + color = {fg = '#ffffff', gui = 'bold'} + }) + require('lualine').setup(config) end function config.nvim_tree() - require("nvim-tree").setup({ - sort_by = "case_sensitive", + require('nvim-tree').setup({ + sort_by = 'case_sensitive', renderer = {group_empty = true}, filters = {dotfiles = true} }) end function config.lsp_colors() - require("lsp-colors").setup({ - Error = "#db4b4b", - Warning = "#e0af68", - Information = "#0db9d7", - Hint = "#10B981" + require('lsp-colors').setup({ + Error = '#db4b4b', + Warning = '#e0af68', + Information = '#0db9d7', + Hint = '#10B981' }) end function config.toggleterm() - require("toggleterm").setup { + require('toggleterm').setup({ open_mapping = [[]], winbar = { enabled = true, @@ -145,9 +171,9 @@ function config.toggleterm() return term.name end } - } + }) end -function config.trobule() require("trouble").setup() end +function config.trobule() require('trouble').setup() end return config