From 80c47b2f4740c6e7b76cf6a7a6c6a41180df065a Mon Sep 17 00:00:00 2001 From: mongia Date: Fri, 26 Apr 2024 16:18:38 +0800 Subject: [PATCH] module split --- lazy-lock.json | 1 + lua/config/keymaps.lua | 24 ++ lua/plugin_config/alpha.lua | 17 ++ lua/plugin_config/dap.lua | 26 ++ lua/plugin_config/dap/c_cpp_rust.lua | 50 ++++ lua/plugin_config/dap/go.lua | 74 ++++++ lua/plugin_config/dap/node.lua | 33 +++ lua/plugin_config/dap/python.lua | 54 ++++ lua/plugin_config/gutentags.lua | 88 +++++++ lua/plugin_config/lazyvim.lua | 7 + lua/plugin_config/leetbuddy.lua | 10 + lua/plugin_config/lspconfig.lua | 17 ++ lua/plugin_config/mason.lua | 21 ++ lua/plugin_config/neotree.lua | 12 + lua/plugin_config/null_ls.lua | 14 ++ lua/plugin_config/symbols_outline.lua | 10 + lua/plugin_config/treesitter.lua | 32 +++ lua/plugins/code.lua | 348 ++------------------------ lua/plugins/colorscheme.lua | 37 +-- lua/plugins/debug.lua | 10 + lua/plugins/editor.lua | 40 +-- lua/plugins/leetcode.lua | 18 +- lua/plugins/ui.lua | 16 +- 23 files changed, 548 insertions(+), 411 deletions(-) create mode 100644 lua/plugin_config/alpha.lua create mode 100644 lua/plugin_config/dap.lua create mode 100644 lua/plugin_config/dap/c_cpp_rust.lua create mode 100644 lua/plugin_config/dap/go.lua create mode 100644 lua/plugin_config/dap/node.lua create mode 100644 lua/plugin_config/dap/python.lua create mode 100644 lua/plugin_config/gutentags.lua create mode 100644 lua/plugin_config/lazyvim.lua create mode 100644 lua/plugin_config/leetbuddy.lua create mode 100644 lua/plugin_config/lspconfig.lua create mode 100644 lua/plugin_config/mason.lua create mode 100644 lua/plugin_config/neotree.lua create mode 100644 lua/plugin_config/null_ls.lua create mode 100644 lua/plugin_config/symbols_outline.lua create mode 100644 lua/plugin_config/treesitter.lua create mode 100644 lua/plugins/debug.lua diff --git a/lazy-lock.json b/lazy-lock.json index ec7148240..49947f633 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -38,6 +38,7 @@ "nvim-dap": { "branch": "master", "commit": "56118cee6af15cb9ddba9d080880949d8eeb0c9f" }, "nvim-dap-ui": { "branch": "master", "commit": "4ce7b97dd8f50b4f672948a34bf8f3a56214fdb8" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "ab988dbb7d20cdaebf9b3ef7554a89f6895de042" }, + "nvim-go": { "branch": "main", "commit": "b087899bed533b0bc53b4ac21dd0c9b9a76a931e" }, "nvim-lspconfig": { "branch": "master", "commit": "8dc45a5c142f0b5a5dd34e5cdba33217d5dc6a86" }, "nvim-navic": { "branch": "master", "commit": "15704c607569d6c5cfeab486d3ef9459645a70ce" }, "nvim-notify": { "branch": "master", "commit": "f3024b912073774111202f5fa6518b0cd2a74432" }, diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 2c134f7bc..5c2a0a9db 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -1,3 +1,27 @@ -- Keymaps are automatically loaded on the VeryLazy event -- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua -- Add any additional keymaps here +-- +local _M = {} + +function _M.SymbolsOutlineKeyMaps() + return { + { "S", "SymbolsOutline", desc = "SymbolsOutline" }, + } +end + +function _M.LeetBuddyKeyMaps() + return { + { "cQ", "LBQuestions", desc = "leetcode List Questions" }, + { "cL", "LBQuestion", desc = "leetcode View Question" }, + { "cR", "LBReset", desc = "leetcode Reset Code" }, + { "cT", "LBTest", desc = "leetcode Run Code" }, + { "cS", "LBSubmit", desc = "leetcode Submit Code" }, + } +end + +function _M.BasicKeyMaps() + vim.keymap.set("n", "", "echo", { desc = "hello world demo" }) +end + +return _M diff --git a/lua/plugin_config/alpha.lua b/lua/plugin_config/alpha.lua new file mode 100644 index 000000000..92a80c2df --- /dev/null +++ b/lua/plugin_config/alpha.lua @@ -0,0 +1,17 @@ +local _M = {} + +function _M.option() + local dashboard = require("alpha.themes.dashboard") + local logo = [[ +███╗ ███╗ ██████╗ ███╗ ██╗ ██████╗ ██╗ █████╗ +████╗ ████║██╔═══██╗████╗ ██║██╔════╝ ██║██╔══██╗ +██╔████╔██║██║ ██║██╔██╗ ██║██║ ███╗██║███████║ +██║╚██╔╝██║██║ ██║██║╚██╗██║██║ ██║██║██╔══██║ +██║ ╚═╝ ██║╚██████╔╝██║ ╚████║╚██████╔╝██║██║ ██║ +╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═╝ + ]] + dashboard.section.header.val = vim.split(logo, "\n") + return dashboard +end + +return _M diff --git a/lua/plugin_config/dap.lua b/lua/plugin_config/dap.lua new file mode 100644 index 000000000..3385481b2 --- /dev/null +++ b/lua/plugin_config/dap.lua @@ -0,0 +1,26 @@ +local c_cpp_rust_config = require("plugin_config.dap.c_cpp_rust") +local go_config = require("plugin_config.dap.go") +local node_config = require("plugin_config.dap.node") +local python_config = require("plugin_config.dap.python") + +local _M = {} + +function _M.config() + local Config = require("lazyvim.config") + vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" }) + + for name, sign in pairs(Config.icons.dap) do + sign = type(sign) == "table" and sign or { sign } + vim.fn.sign_define( + "Dap" .. name, + { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] } + ) + end + + c_cpp_rust_config.config() + go_config.config() + node_config.config() + python_config.config() +end + +return _M diff --git a/lua/plugin_config/dap/c_cpp_rust.lua b/lua/plugin_config/dap/c_cpp_rust.lua new file mode 100644 index 000000000..aaf21486f --- /dev/null +++ b/lua/plugin_config/dap/c_cpp_rust.lua @@ -0,0 +1,50 @@ +local _M = {} + +function _M.config() + local dap = require("dap") + dap.adapters.codelldb = { + type = "server", + port = "${port}", + executable = { + -- CHANGE THIS to your path! + command = "codelldb", + args = { "--port", "${port}" }, + + -- On windows you may have to uncomment this: + -- detached = false, + }, + } + dap.configurations.cpp = { + { + name = "Launch", + type = "codelldb", + request = "launch", + program = function() + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") + end, + cwd = "${workspaceFolder}", + stopOnEntry = false, + args = function() + local input = vim.fn.input("Input args: ") + return vim.fn.split(input, " ", true) + end, + + -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting: + -- + -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope + -- + -- Otherwise you might get the following error: + -- + -- Error on launch: Failed to attach to the target process + -- + -- But you should be aware of the implications: + -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html + runInTerminal = false, + }, + } + + dap.configurations.c = dap.configurations.cpp + dap.configurations.rust = dap.configurations.cpp +end + +return _M diff --git a/lua/plugin_config/dap/go.lua b/lua/plugin_config/dap/go.lua new file mode 100644 index 000000000..17b0a00c5 --- /dev/null +++ b/lua/plugin_config/dap/go.lua @@ -0,0 +1,74 @@ +local _M = {} + +function _M.config() + local dap = require("dap") + dap.adapters.go = function(callback) + local stdout = vim.loop.new_pipe(false) + local handle + local pid_or_err + local port = 38697 + local opts = { + stdio = { nil, stdout }, + args = { "dap", "-l", "127.0.0.1:" .. port }, + detached = true, + } + handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code) + stdout:close() + handle:close() + if code ~= 0 then + vim.notify( + string.format( + '"dlv" exited with code: %d, please check your configs for correctness.', + code + ), + vim.log.levels.WARN, + { title = "[go] DAP Warning!" } + ) + end + end) + assert(handle, "Error running dlv: " .. tostring(pid_or_err)) + stdout:read_start(function(err, chunk) + assert(not err, err) + if chunk then + vim.schedule(function() + require("dap.repl").append(chunk) + end) + end + end) + -- Wait for delve to start + + vim.defer_fn(function() + callback({ type = "server", host = "127.0.0.1", port = port }) + end, 100) + end + -- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md + dap.configurations.go = { + { type = "go", name = "Debug", request = "launch", program = "${file}" }, + { + type = "go", + name = "Debug with args", + request = "launch", + program = "${file}", + args = function() + local argument_string = vim.fn.input("Program arg(s): ") + return vim.fn.split(argument_string, " ", true) + end, + }, + { + type = "go", + name = "Debug test", -- configuration for debugging test files + request = "launch", + mode = "test", + program = "${file}", + }, -- works with go.mod packages and sub packages + { + type = "go", + name = "Debug test (go.mod)", + request = "launch", + mode = "test", + program = "./${relativeFileDirname}", + }, + } +end + +return _M diff --git a/lua/plugin_config/dap/node.lua b/lua/plugin_config/dap/node.lua new file mode 100644 index 000000000..5ae42f0b5 --- /dev/null +++ b/lua/plugin_config/dap/node.lua @@ -0,0 +1,33 @@ +local _M = {} + +function _M.config() + local dap = require("dap") + --node configurations + dap.adapters.node2 = { + type = 'executable', + command = 'node', + args = { vim.fn.stdpath("data") .. "/mason/packages/node-debug2-adapter/out/src/nodeDebug.js" }, + } + dap.configurations.javascript = { + { + name = 'Launch', + type = 'node2', + request = 'launch', + program = '${file}', + cwd = vim.fn.getcwd(), + sourceMaps = true, + protocol = 'inspector', + console = 'integratedTerminal', + }, + { + -- For this to work you need to make sure the node process is started with the `--inspect` flag. + name = 'Attach to process', + type = 'node2', + request = 'attach', + restart = true, + processId = require 'dap.utils'.pick_process, + }, + } +end + +return _M diff --git a/lua/plugin_config/dap/python.lua b/lua/plugin_config/dap/python.lua new file mode 100644 index 000000000..9f0de5432 --- /dev/null +++ b/lua/plugin_config/dap/python.lua @@ -0,0 +1,54 @@ +local _M = {} + +function _M.config() + local dap = require("dap") + local function isempty(s) + return s == nil or s == "" + end + dap.adapters.python = function(cb, config) + if config.request == "attach" then + ---@diagnostic disable-next-line: undefined-field + local port = (config.connect or config).port or 8080 + ---@diagnostic disable-next-line: undefined-field + local host = (config.connect or config).host or "127.0.0.1" + cb({ + type = "server", + port = assert(port, "`connect.port` is required for a python `attach` configuration"), + host = host, + options = { + source_filetype = "python", + }, + }) + else + cb({ + type = "executable", + command = '/usr/bin/python3', + -- command = os.getenv("VIRTUAL_ENV") .. "/bin/python", + args = { "-m", "debugpy.adapter" }, + options = { + source_filetype = "python", + }, + }) + end + end + dap.configurations.python = { + { + -- The first three options are required by nvim-dap + type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python` + request = "launch", + name = "Launch file", + -- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options + + program = "${file}", -- This configuration will launch the current file if used. + pythonPath = function() + if not isempty(vim.env.CONDA_PREFIX) then + return vim.env.CONDA_PREFIX .. "/bin/python" + else + return "/usr/bin/python3" + end + end, + }, + } +end + +return _M diff --git a/lua/plugin_config/gutentags.lua b/lua/plugin_config/gutentags.lua new file mode 100644 index 000000000..af2e9fe3e --- /dev/null +++ b/lua/plugin_config/gutentags.lua @@ -0,0 +1,88 @@ +local _M = {} + +function _M.config() + vim.g.gutentags_ctags_exclude = { + '*.git', + '*.svg', + '*.hg', + '*/tests/*', + 'build', + 'dist', + '*sites/*/files/*', + 'bin', + 'node_modules', + 'bower_components', + 'cache', + 'compiled', + 'docs', + 'example', + 'bundle', + 'vendor', + '*.md', + '*-lock.json', + '*.lock', + '*bundle*.js', + '*build*.js', + '.*rc*', + '*.json', + '*.min.*', + '*.map', + '*.bak', + '*.zip', + '*.pyc', + '*.class', + '*.sln', + '*.Master', + '*.csproj', + '*.tmp', + '*.csproj.user', + '*.cache', + '*.pdb', + 'tags*', + 'cscope.*', + -- '*.css', + -- '*.less', + -- '*.scss', + '*.exe', + '*.dll', + '*.mp3', + '.md', + '*.ogg', + '*.flac', + '*.swp', + '*.swo', + '*.bmp', + '*.gif', + '*.ico', + '*.jpg', + '*.png', + '*.rar', + '*.zip', + '*.tar', + '*.tar.gz', + '*.tar.xz', + '*.tar.bz2', + '*.pdf', + '*.doc', + '*.docx', + '*.ppt', + '*.pptx', + } + + vim.g.gutentags_add_default_project_roots = false + vim.g.gutentags_project_root = { 'package.json', '.git', '.svn', '.root', '.hg', '.vscode', '.project' } + vim.g.gutentags_ctags_tagfile = '.tags' + + vim.g.gutentags_cache_dir = vim.fn.stdpath("cache") .. '/ctags' + vim.g.gutentags_ctags_extra_args = { '--tag-relative=yes', '--fields=+ailmnS', '--extra=+q', + '--c++-kinds=+px', '--c-kinds=+px' } + + -- custom + vim.g.gutentags_modules = { 'ctags' } + + if vim.fn.isdirectory(vim.g.gutentags_cache_dir) == 0 then + os.execute("mkdir -p " .. vim.g.gutentags_cache_dir) + end +end + +return _M diff --git a/lua/plugin_config/lazyvim.lua b/lua/plugin_config/lazyvim.lua new file mode 100644 index 000000000..9a806e11b --- /dev/null +++ b/lua/plugin_config/lazyvim.lua @@ -0,0 +1,7 @@ +local _M = {} + +function _M.option() + return { + colorscheme = "catppuccin" + } +end diff --git a/lua/plugin_config/leetbuddy.lua b/lua/plugin_config/leetbuddy.lua new file mode 100644 index 000000000..bc8f637f2 --- /dev/null +++ b/lua/plugin_config/leetbuddy.lua @@ -0,0 +1,10 @@ +local _M = {} + +function _M.config() + require('leetbuddy').setup({ + domain = "cn", -- `cn` for chinese leetcode + language = "cpp", + }) +end + +return _M diff --git a/lua/plugin_config/lspconfig.lua b/lua/plugin_config/lspconfig.lua new file mode 100644 index 000000000..5f080c18b --- /dev/null +++ b/lua/plugin_config/lspconfig.lua @@ -0,0 +1,17 @@ +local _M = {} + +function _M.option() + return { + setup = { + clangd = function(_, opts) + opts.capabilities.offsetEncoding = { "utf-16" } + end + }, + } +end + +function _M.config() + +end + +return _M diff --git a/lua/plugin_config/mason.lua b/lua/plugin_config/mason.lua new file mode 100644 index 000000000..cc445336d --- /dev/null +++ b/lua/plugin_config/mason.lua @@ -0,0 +1,21 @@ +local _M = {} + +function _M.option() + return { + ensure_installed = { + "stylua", + "codelldb", + "shfmt", + "delve", + "clangd", + "debugpy", + "gopls" + }, + } +end + +function _M.config() + +end + +return _M diff --git a/lua/plugin_config/neotree.lua b/lua/plugin_config/neotree.lua new file mode 100644 index 000000000..62e5303ca --- /dev/null +++ b/lua/plugin_config/neotree.lua @@ -0,0 +1,12 @@ +local _M = {} + +function _M.option() + return { + close_if_last_window = true, + window = { + width = 30, + }, + } +end + +return _M diff --git a/lua/plugin_config/null_ls.lua b/lua/plugin_config/null_ls.lua new file mode 100644 index 000000000..59aca854f --- /dev/null +++ b/lua/plugin_config/null_ls.lua @@ -0,0 +1,14 @@ +local _M = {} + +function _M.option() + return { + sources = { + require("null-ls").builtins.formatting.clang_format.with({ + filetypes = { "c", "cpp", "hpp", "cc" }, + extra_args = { "-style={BasedOnStyle: LLVM, IndentWidth: 4}" }, + }), + }, + } +end + +return _M diff --git a/lua/plugin_config/symbols_outline.lua b/lua/plugin_config/symbols_outline.lua new file mode 100644 index 000000000..0b7366f59 --- /dev/null +++ b/lua/plugin_config/symbols_outline.lua @@ -0,0 +1,10 @@ +local _M = {} + +function _M.config() + require("symbols-outline").setup({ + relative_width = false, + width = 30, + }) +end + +return _M diff --git a/lua/plugin_config/treesitter.lua b/lua/plugin_config/treesitter.lua new file mode 100644 index 000000000..86686cf49 --- /dev/null +++ b/lua/plugin_config/treesitter.lua @@ -0,0 +1,32 @@ +local _M = {} + +function _M.option() + return { + indent = { + enable = false, + }, + ensure_installed = { + "bash", + "html", + "javascript", + "json", + "lua", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "tsx", + "typescript", + "vim", + "yaml", + "make", + "go", + "cpp", + "c", + "rust" + }, + } +end + +return _M diff --git a/lua/plugins/code.lua b/lua/plugins/code.lua index ca3888de2..cb8043389 100644 --- a/lua/plugins/code.lua +++ b/lua/plugins/code.lua @@ -1,353 +1,59 @@ +local keymaps = require("config.keymaps") +local gutentags_config = require("plugin_config.gutentags") +local mason_config = require("plugin_config.mason") +local symbols_outline_config = require("plugin_config.symbols_outline") +local lspconfig_config = require("plugin_config.lspconfig") +local null_ls_config = require("plugin_config.null_ls") + return { + -- 显示lsp的诊断信息 { "folke/trouble.nvim", enabled = true }, + -- chatgpt插件 编码使用 { "jackMort/ChatGPT.nvim", event = "VeryLazy", - config = function() - require("chatgpt").setup() - end, dependencies = { "MunifTanjim/nui.nvim", "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim" }, }, + -- 管理lsp,dap 等安装 { "williamboman/mason.nvim", - opts = { - ensure_installed = { - "stylua", - "codelldb", - "shfmt", - "delve", - "clangd", - "debugpy", - }, - }, + opts = mason_config.option() }, + -- 自动生成tag文件 { "ludovicchabant/vim-gutentags", enabled = true, - config = function() - vim.g.gutentags_ctags_exclude = { - '*.git', - '*.svg', - '*.hg', - '*/tests/*', - 'build', - 'dist', - '*sites/*/files/*', - 'bin', - 'node_modules', - 'bower_components', - 'cache', - 'compiled', - 'docs', - 'example', - 'bundle', - 'vendor', - '*.md', - '*-lock.json', - '*.lock', - '*bundle*.js', - '*build*.js', - '.*rc*', - '*.json', - '*.min.*', - '*.map', - '*.bak', - '*.zip', - '*.pyc', - '*.class', - '*.sln', - '*.Master', - '*.csproj', - '*.tmp', - '*.csproj.user', - '*.cache', - '*.pdb', - 'tags*', - 'cscope.*', - -- '*.css', - -- '*.less', - -- '*.scss', - '*.exe', - '*.dll', - '*.mp3', - '.md', - '*.ogg', - '*.flac', - '*.swp', - '*.swo', - '*.bmp', - '*.gif', - '*.ico', - '*.jpg', - '*.png', - '*.rar', - '*.zip', - '*.tar', - '*.tar.gz', - '*.tar.xz', - '*.tar.bz2', - '*.pdf', - '*.doc', - '*.docx', - '*.ppt', - '*.pptx', - } - - vim.g.gutentags_add_default_project_roots = false - vim.g.gutentags_project_root = { 'package.json', '.git', '.svn', '.root', '.hg', '.vscode', '.project' } - vim.g.gutentags_ctags_tagfile = '.tags' - - vim.g.gutentags_cache_dir = vim.fn.stdpath("data") .. '/ctags' - vim.g.gutentags_ctags_extra_args = { '--tag-relative=yes', '--fields=+ailmnS', '--extra=+q', - '--c++-kinds=+px', '--c-kinds=+px' } - - -- custom - vim.g.gutentags_modules = { 'ctags' } - - if vim.fn.isdirectory(vim.g.gutentags_cache_dir) == 0 then - os.execute("mkdir -p " .. vim.g.gutentags_cache_dir) - end - end + config = gutentags_config.config }, + -- 窗口右侧显示函数,全局变量 { - -- 窗口右侧显示函数,全局变量 "simrat39/symbols-outline.nvim", event = "VeryLazy", - config = function() - require("symbols-outline").setup({ - relative_width = false, - width = 30, - }) - end + config = symbols_outline_config.config, + keys = keymaps.SymbolsOutlineKeyMaps() }, - + -- 配置lsp的配置,不同语言单独配置 { "neovim/nvim-lspconfig", - opts = { - setup = { - clangd = function(_, opts) - opts.capabilities.offsetEncoding = { "utf-16" } - end, - }, - }, + opts = lspconfig_config.option() }, + -- 格式化代码 { "jose-elias-alvarez/null-ls.nvim", enable = true, - opts = { - sources = { - require("null-ls").builtins.formatting.clang_format.with({ - filetypes = { "c", "cpp", "hpp", "cc" }, - extra_args = { "-style={BasedOnStyle: LLVM, IndentWidth: 4}" }, - }), - }, - }, + opts = null_ls_config.option() }, + -- golang的插件,自动跳转 { - "mfussenegger/nvim-dap", - config = function() - local Config = require("lazyvim.config") - vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" }) - - for name, sign in pairs(Config.icons.dap) do - sign = type(sign) == "table" and sign or { sign } - vim.fn.sign_define( - "Dap" .. name, - { text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] } - ) - end - - local dap = require("dap") - dap.adapters.codelldb = { - type = "server", - port = "${port}", - executable = { - -- CHANGE THIS to your path! - command = "codelldb", - args = { "--port", "${port}" }, - - -- On windows you may have to uncomment this: - -- detached = false, - }, - } - dap.configurations.cpp = { - { - name = "Launch", - type = "codelldb", - request = "launch", - program = function() - return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") - end, - cwd = "${workspaceFolder}", - stopOnEntry = false, - args = function() - local input = vim.fn.input("Input args: ") - return vim.fn.split(input, " ", true) - end, - - -- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting: - -- - -- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope - -- - -- Otherwise you might get the following error: - -- - -- Error on launch: Failed to attach to the target process - -- - -- But you should be aware of the implications: - -- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html - runInTerminal = false, - }, - } - - dap.configurations.c = dap.configurations.cpp - dap.configurations.rust = dap.configurations.cpp - - dap.adapters.go = function(callback) - local stdout = vim.loop.new_pipe(false) - local handle - local pid_or_err - local port = 38697 - local opts = { - stdio = { nil, stdout }, - args = { "dap", "-l", "127.0.0.1:" .. port }, - detached = true, - } - handle, pid_or_err = vim.loop.spawn("dlv", opts, function(code) - stdout:close() - handle:close() - if code ~= 0 then - vim.notify( - string.format( - '"dlv" exited with code: %d, please check your configs for correctness.', - code - ), - vim.log.levels.WARN, - { title = "[go] DAP Warning!" } - ) - end - end) - assert(handle, "Error running dlv: " .. tostring(pid_or_err)) - stdout:read_start(function(err, chunk) - assert(not err, err) - if chunk then - vim.schedule(function() - require("dap.repl").append(chunk) - end) - end - end) - -- Wait for delve to start - - vim.defer_fn(function() - callback({ type = "server", host = "127.0.0.1", port = port }) - end, 100) - end - -- https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_dap.md - dap.configurations.go = { - { type = "go", name = "Debug", request = "launch", program = "${file}" }, - { - type = "go", - name = "Debug with args", - request = "launch", - program = "${file}", - args = function() - local argument_string = vim.fn.input("Program arg(s): ") - return vim.fn.split(argument_string, " ", true) - end, - }, - { - type = "go", - name = "Debug test", -- configuration for debugging test files - request = "launch", - mode = "test", - program = "${file}", - }, -- works with go.mod packages and sub packages - { - type = "go", - name = "Debug test (go.mod)", - request = "launch", - mode = "test", - program = "./${relativeFileDirname}", - }, - } - - local function isempty(s) - return s == nil or s == "" - end - dap.adapters.python = function(cb, config) - if config.request == "attach" then - ---@diagnostic disable-next-line: undefined-field - local port = (config.connect or config).port or 8080 - ---@diagnostic disable-next-line: undefined-field - local host = (config.connect or config).host or "127.0.0.1" - cb({ - type = "server", - port = assert(port, "`connect.port` is required for a python `attach` configuration"), - host = host, - options = { - source_filetype = "python", - }, - }) - else - cb({ - type = "executable", - command = '/usr/bin/python3', - -- command = os.getenv("VIRTUAL_ENV") .. "/bin/python", - args = { "-m", "debugpy.adapter" }, - options = { - source_filetype = "python", - }, - }) - end - end - dap.configurations.python = { - { - -- The first three options are required by nvim-dap - type = "python", -- the type here established the link to the adapter definition: `dap.adapters.python` - request = "launch", - name = "Launch file", - -- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options - - program = "${file}", -- This configuration will launch the current file if used. - pythonPath = function() - if not isempty(vim.env.CONDA_PREFIX) then - return vim.env.CONDA_PREFIX .. "/bin/python" - else - return "/usr/bin/python3" - end - end, - }, - } - - --node configurations - dap.adapters.node2 = { - type = 'executable', - command = 'node', - args = { vim.fn.stdpath("data") .. "/mason/packages/node-debug2-adapter/out/src/nodeDebug.js" }, - } - dap.configurations.javascript = { - { - name = 'Launch', - type = 'node2', - request = 'launch', - program = '${file}', - cwd = vim.fn.getcwd(), - sourceMaps = true, - protocol = 'inspector', - console = 'integratedTerminal', - }, - { - -- For this to work you need to make sure the node process is started with the `--inspect` flag. - name = 'Attach to process', - type = 'node2', - request = 'attach', - restart = true, - processId = require 'dap.utils'.pick_process, - }, - } - end + "crispgm/nvim-go", + dependencies = { + "nvim-lua/plenary.nvim", + "rcarriga/nvim-notify", + "neovim/nvim-lspconfig" + } } } diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 22fbd9e7a..5ee5e4f3a 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -1,36 +1,17 @@ +local treesitter_config = require("plugin_config.treesitter") +local lazyvim_config = require("plugin_config.lazyvim") + return { - { "tanvirtin/monokai.nvim" }, + { + "tanvirtin/monokai.nvim" + }, { "LazyVim/LazyVim", - opts = { - colorscheme = "monokai", - -- colorscheme = "catppuccin", - }, + opts = lazyvim_config.option() }, { "nvim-treesitter/nvim-treesitter", - enable = false, - opts = { - indent = { - enable = false, - }, - ensure_installed = { - "bash", - "html", - "javascript", - "json", - "lua", - "markdown", - "markdown_inline", - "python", - "query", - "regex", - "tsx", - "typescript", - "vim", - "yaml", - "make", - }, - }, + enable = true, + opts = treesitter_config.option() }, } diff --git a/lua/plugins/debug.lua b/lua/plugins/debug.lua new file mode 100644 index 000000000..5d3e7284e --- /dev/null +++ b/lua/plugins/debug.lua @@ -0,0 +1,10 @@ +local dap_config = require("plugin_config.dap") + +return { + -- 调试插件 + { + "mfussenegger/nvim-dap", + config = dap_config.config + } + +} diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index eac80df5d..76144c843 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -1,12 +1,9 @@ +local neotree_config = require("plugin_config.neotree") + return { { "nvim-neo-tree/neo-tree.nvim", - opts = { - close_if_last_window = true, - window = { - width = 30, - }, - }, + opts = neotree_config.option() }, { "nvim-lualine/lualine.nvim", @@ -14,42 +11,13 @@ return { }, { "folke/noice.nvim", - enabled = false, + enabled = true, }, { "folke/which-key.nvim", event = "VeryLazy", - opts = { - plugins = { - spelling = true, - }, - defaults = {}, - }, - config = function(_, opts) - local wk = require("which-key") - wk.setup(opts) - wk.register(opts.defaults) - end, }, { "nvim-telescope/telescope.nvim", - -- keys = { - -- add a keymap to browse plugin files - -- stylua: ignore - -- { - -- "fp", - -- function() require("telescope.builtin").find_files({ cwd = require("lazy.core.config").options.root }) end, - -- desc = "Find Plugin File", - -- }, - -- }, - -- -- change some options - -- opts = { - -- defaults = { - -- layout_strategy = "horizontal", - -- layout_config = { prompt_position = "top" }, - -- sorting_strategy = "ascending", - -- winblend = 0, - -- }, - -- }, }, } diff --git a/lua/plugins/leetcode.lua b/lua/plugins/leetcode.lua index 1f5e85e46..6a5d2c2f6 100644 --- a/lua/plugins/leetcode.lua +++ b/lua/plugins/leetcode.lua @@ -1,3 +1,6 @@ +local keymaps = require("config.keymaps") +local leetbuddy_config = require("plugin_config.leetbuddy") + return { { "Dhanus3133/LeetBuddy.nvim", @@ -6,18 +9,7 @@ return { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim", }, - config = function() - require('leetbuddy').setup({ - domain = "cn", -- `cn` for chinese leetcode - language = "cpp", - }) - end, - keys = { - { "cQ", "LBQuestions", desc = "leetcode List Questions" }, - { "cL", "LBQuestion", desc = "leetcode View Question" }, - { "cR", "LBReset", desc = "leetcode Reset Code" }, - { "cT", "LBTest", desc = "leetcode Run Code" }, - { "cS", "LBSubmit", desc = "leetcode Submit Code" }, - }, + config = leetbuddy_config.config, + keys = keymaps.LeetBuddyKeyMaps(), } } diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index 73b0df8bd..0fefc46ab 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -1,20 +1,10 @@ +local alpha_config = require("plugin_config.alpha") + return { { "goolord/alpha-nvim", event = "VimEnter", - opts = function() - local dashboard = require("alpha.themes.dashboard") - local logo = [[ -███╗ ███╗ ██████╗ ███╗ ██╗ ██████╗ ██╗ █████╗ -████╗ ████║██╔═══██╗████╗ ██║██╔════╝ ██║██╔══██╗ -██╔████╔██║██║ ██║██╔██╗ ██║██║ ███╗██║███████║ -██║╚██╔╝██║██║ ██║██║╚██╗██║██║ ██║██║██╔══██║ -██║ ╚═╝ ██║╚██████╔╝██║ ╚████║╚██████╔╝██║██║ ██║ -╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═╝ - ]] - dashboard.section.header.val = vim.split(logo, "\n") - return dashboard - end, + opts = alpha_config.option() }, { "kassio/neoterm",