From ed7b42efbce495beb7fa260c303501be4ac61e8b Mon Sep 17 00:00:00 2001 From: Young Xu Date: Sun, 2 Apr 2023 18:47:14 +0800 Subject: [PATCH] feat: support java fix: nvim tree filter .gitignore support: rust language --- README.md | 2 +- ftplugin/java.lua | 121 +++++++ ftplugin/javascript.vim | 1 - ftplugin/markdown.vim | 51 --- ftplugin/mysql.vim | 1 - ftplugin/python.vim | 1 - ftplugin/sql.vim | 1 - ftplugin/typescript.vim | 1 - ftplugin/vue.vim | 4 - init.lua | 4 +- intellij-java-google-style.xml | 598 +++++++++++++++++++++++++++++++++ lua/core/keymapping.lua | 10 +- lua/core/option.lua | 4 +- lua/lsp/init.lua | 3 +- lua/lsp/lua.lua | 47 +-- lua/plugins/file-tree.lua | 69 +++- lua/plugins/gitsigns.lua | 170 +++++----- lua/plugins/golang.lua | 2 +- lua/plugins/java.lua | 51 +++ lua/plugins/lspsaga.lua | 13 + lua/plugins/mason.lua | 82 +++-- lua/plugins/notify.lua | 4 + lua/plugins/null-ls.lua | 2 + lua/plugins/rust.lua | 12 + lua/setup.lua | 5 + 25 files changed, 1060 insertions(+), 199 deletions(-) create mode 100644 ftplugin/java.lua delete mode 100644 ftplugin/javascript.vim delete mode 100644 ftplugin/markdown.vim delete mode 100644 ftplugin/mysql.vim delete mode 100644 ftplugin/python.vim delete mode 100644 ftplugin/sql.vim delete mode 100644 ftplugin/typescript.vim delete mode 100644 ftplugin/vue.vim create mode 100644 intellij-java-google-style.xml create mode 100644 lua/plugins/java.lua create mode 100644 lua/plugins/rust.lua diff --git a/README.md b/README.md index 4547c33..6a9f777 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ git clone --depth 1 https://github.com/wbthomason/packer.nvim\ 安装依赖 ```bash -sudo dnf install fd-find ripgrep ShellCheck -y +sudo dnf install fd-find ripgrep ShellCheck luarocks -y go install github.com/jesseduffield/lazygit@latest sudo npm install eslint --global sudo npm install -g typescript typescript-language-server diff --git a/ftplugin/java.lua b/ftplugin/java.lua new file mode 100644 index 0000000..efb5370 --- /dev/null +++ b/ftplugin/java.lua @@ -0,0 +1,121 @@ +function IsDirectoryExist(dirname) + return os.rename(dirname, dirname) and true or false +end + +local jdtls = require("jdtls") +local root_markers = { ".git", "mvnw", "gradlew", "pom.xml", "build.gradle" } +local root_dir = require("jdtls.setup").find_root(root_markers) +if root_dir == "" then + return +end +local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") +local home = os.getenv("HOME") +local jdtls_home = home .. "/.jdtls" +local plugins_home = jdtls_home .. "/plugins" +local workspace = jdtls_home .. "/workspace/" .. project_name + +-- create when workspace not exist +if not IsDirectoryExist(workspace) then + os.execute("mkdir " .. workspace) +end + +local launcher = plugins_home .. "/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar" +local configuration = jdtls_home .. "/config_linux" +if vim.loop.os_uname().sysname == "Windows" then + configuration = jdtls_home .. "\\config_win" +end + +local config = { + flags = { + debounce_text_changes = 80, + }, + on_attach = common_lsp_on_attach, + cmd = { + "java", + "-Declipse.application=org.eclipse.jdt.ls.core.id1", + "-Dosgi.bundles.defaultStartLevel=4", + "-Declipse.product=org.eclipse.jdt.ls.core.product", + "-Dlog.protocol=true", + "-Dlog.level=ALL", + "-Xmx1g", + "--add-modules=ALL-SYSTEM", + "--add-opens", + "java.base/java.util=ALL-UNNAMED", + "--add-opens", + "java.base/java.lang=ALL-UNNAMED", + "-javaagent:" .. jdtls_home .. "/bin/lombok.jar", + "-jar", + launcher, + "-configuration", + configuration, + "-data", + workspace, + }, + root_dir = root_dir, + settings = { + java = { + maven = { + downloadSources = true, + }, + eclipse = { + downloadSources = true, + }, + implementationsCodeLens = { + enabled = true, + }, + referencesCodeLens = { + enabled = true, + }, + references = { + includeDecompiledSources = true, + }, + format = { + enabled = true, + settings = { + url = vim.fn.stdpath("config") .. "intellij-java-google-style.xml", + profile = "GoogleStyle", + }, + }, + signatureHelp = { enabled = true }, + contentProvider = { preferred = "fernflower" }, -- Use fernflower to decompile library code + completion = { + favoriteStaticMembers = { + "org.hamcrest.MatcherAssert.assertThat", + "org.hamcrest.Matchers.*", + "org.hamcrest.CoreMatchers.*", + "org.junit.jupiter.api.Assertions.*", + "java.util.Objects.requireNonNull", + "java.util.Objects.requireNonNullElse", + "org.mockito.Mockito.*", + }, + filteredTypes = { + "com.sun.*", + "io.micrometer.shaded.*", + "java.awt.*", + "jdk.*", + "sun.*", + }, + }, + sources = { + organizeImports = { + starThreshold = 9999, + staticStarThreshold = 9999, + }, + }, + codeGeneration = { + toString = { + template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}", + }, + hashCodeEquals = { + useJava7Objects = true, + }, + useBlocks = true, + }, + }, + }, + + init_options = { + bundles = {}, + }, +} +jdtls.start_or_attach(config) diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim deleted file mode 100644 index f9ef053..0000000 --- a/ftplugin/javascript.vim +++ /dev/null @@ -1 +0,0 @@ -vnoremap D :call SurroundVaddPairs("/** ", " */") diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim deleted file mode 100644 index c1d00ec..0000000 --- a/ftplugin/markdown.vim +++ /dev/null @@ -1,51 +0,0 @@ -hi MDTask ctermfg=1 -hi MDDoneText ctermfg=37 cterm=italic,strikethrough -hi MDTodoText cterm=NONE -hi MDDoneDate cterm=strikethrough ctermfg=71 -hi MDTodoDate ctermfg=71 -hi Deadline ctermfg=162 cterm=bold,underline -hi NearDeadline ctermfg=178 cterm=bold -au FileType markdown syn match markdownError "\w\@<=\w\@=" -au FileType markdown syn match MDDoneDate /[SD]:\d\{4\}\([\/-]\d\d\)\{2\}/ contained -au FileType markdown syn match MDTodoDate /[SD]:\d\{4\}\([\/-]\d\d\)\{2\}/ contained -au FileType markdown syn match MDDoneText /- \[x\] \zs.*/ contains=MDDoneDate contained -au FileType markdown syn match MDTodoText /- \[ \] \zs.*/ contains=MDTodoDate contained -au FileType markdown syn match MDTask /- \[\(x\| \)\] .*/ contains=MDDoneText,MDTodoText -au FileType markdown call matchadd('Deadline', 'D:'.strftime("%Y-%m-%d")) -au FileType markdown call matchadd('NearDeadline', 'D:'.strftime("%Y-%m-%d", localtime() + 3600 * 24)) -au FileType markdown call matchadd('NearDeadline', 'D:'.strftime("%Y-%m-%d", localtime() + 3600 * 48)) - -let b:md_block = '```' -setlocal shiftwidth=2 -setlocal softtabstop=2 -setlocal tabstop=2 -nnoremap :call toggleTodoStatus() -nnoremap <2-LeftMouse> :call toggleTodoStatus():w<2-LeftMouse> -vnoremap B :call SurroundVaddPairs("**", "**") -vnoremap I :call SurroundVaddPairs("*", "*") -vnoremap T :call SurroundVaddPairs("- [ ] ", "") -vnoremap ` :call SurroundVaddPairs("`", "`") -vnoremap C :call SurroundVaddPairs("```plaintext", "```") - -fun! s:toggleTodoStatus() - let line = getline('.') - if line =~ glob2regpat('*- \[ \]*') - call setline('.', substitute(line, '\[ \]', '[x]', '')) - elseif line =~ glob2regpat('*- \[x\]*') - call setline('.', substitute(line, '\[x\]', '[ ]', '')) - endif -endf - -nnoremap :call toggleMPTheme() -inoremap :call toggleMPTheme() -fun! s:toggleMPTheme() - if g:mkdp_theme == 'dark' - let g:mkdp_theme = 'light' - else - let g:mkdp_theme = 'dark' - endif - - exec 'MarkdownPreviewStop' - sleep 1 - exec 'MarkdownPreview' -endf diff --git a/ftplugin/mysql.vim b/ftplugin/mysql.vim deleted file mode 100644 index e37eb4b..0000000 --- a/ftplugin/mysql.vim +++ /dev/null @@ -1 +0,0 @@ -let g:omni_sql_no_default_maps = 1 diff --git a/ftplugin/python.vim b/ftplugin/python.vim deleted file mode 100644 index f9ef053..0000000 --- a/ftplugin/python.vim +++ /dev/null @@ -1 +0,0 @@ -vnoremap D :call SurroundVaddPairs("/** ", " */") diff --git a/ftplugin/sql.vim b/ftplugin/sql.vim deleted file mode 100644 index e37eb4b..0000000 --- a/ftplugin/sql.vim +++ /dev/null @@ -1 +0,0 @@ -let g:omni_sql_no_default_maps = 1 diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim deleted file mode 100644 index f9ef053..0000000 --- a/ftplugin/typescript.vim +++ /dev/null @@ -1 +0,0 @@ -vnoremap D :call SurroundVaddPairs("/** ", " */") diff --git a/ftplugin/vue.vim b/ftplugin/vue.vim deleted file mode 100644 index 6be9c07..0000000 --- a/ftplugin/vue.vim +++ /dev/null @@ -1,4 +0,0 @@ -augroup vue - au! - autocmd BufWritePre *.vue :call CocAction('format') -augroup END diff --git a/init.lua b/init.lua index 645af1a..47edcf5 100644 --- a/init.lua +++ b/init.lua @@ -45,11 +45,13 @@ require("lsp.lua") require("lsp.protocol") require("lsp.volar") require("lsp.clang") +require("plugins.java") -- lspsaga require("plugins.lspsaga") -- golang lsp require("plugins.golang") - +-- rust ide +require("plugins.rust") -- 载入主题 require("core.theme") -- 载入按键 diff --git a/intellij-java-google-style.xml b/intellij-java-google-style.xml new file mode 100644 index 0000000..f3a6743 --- /dev/null +++ b/intellij-java-google-style.xml @@ -0,0 +1,598 @@ + + + + + + diff --git a/lua/core/keymapping.lua b/lua/core/keymapping.lua index 64976e4..521228d 100644 --- a/lua/core/keymapping.lua +++ b/lua/core/keymapping.lua @@ -4,6 +4,8 @@ vim.g.maplocalleader = " " local map = vim.keymap local noreopt = { noremap = true, silent = true } +-- 重启lsp +map.set("n", "lr", "LspRestart", noreopt) -- save map.set({ "n", "i" }, "", "w", noreopt) -- format @@ -27,6 +29,10 @@ map.set("n", "", "h", noreopt) map.set("n", "", "j", noreopt) map.set("n", "", "k", noreopt) map.set("n", "", "l", noreopt) +-- 折叠配置 +map.set({"n", "v"}, "z+", "zM", noreopt) +map.set({"n", "v"}, "z-", "zR", noreopt) +map.set({"n", "v"}, "zz", "za", noreopt) -- 分屏 map.set("n", "sv", ":vsp", noreopt) map.set("n", "sh", ":sp", noreopt) @@ -50,8 +56,8 @@ map.set("n", "qn", ":q!", noreopt) map.set("n", "qq", ":qa!", noreopt) map.set("i", "jk", "", noreopt) -- 文件页切换 -map.set("n", "bl", ":BufferLineCyclePrev", noreopt) -map.set("n", "br", ":BufferLineCycleNext", noreopt) +map.set("n", "ll", ":BufferLineCyclePrev", noreopt) +map.set("n", "hh", ":BufferLineCycleNext", noreopt) map.set("n", "bpi", ":BufferLineTogglePin", noreopt) map.set("n", "bcl", ":BufferLineCloseLeft", noreopt) map.set("n", "bcr", ":BufferLineCloseRight", noreopt) diff --git a/lua/core/option.lua b/lua/core/option.lua index e99b1bf..c8c9d73 100644 --- a/lua/core/option.lua +++ b/lua/core/option.lua @@ -40,10 +40,10 @@ vim.o.hidden = true -- 鼠标支持 vim.o.mouse = "a" -- smaller updatetime -vim.o.updatetime = 300 +vim.o.updatetime = 3000 -- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置 -- 遇到问题详见:https://github.com/nshen/learn-neovim-lua/issues/1 -vim.o.timeoutlen = 500 +vim.o.timeoutlen = 1000 -- split window 从下边和右边出现 vim.o.splitbelow = true vim.o.splitright = true diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 4c8b447..44d29c7 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -10,6 +10,5 @@ common_lsp_on_attach = function(client, bufnr) end common_lsp_flags = { - -- This is the default in Nvim 0.7+ - debounce_text_changes = 150, + debounce_text_changes = 500, } diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua index 87f55b6..ffe0098 100644 --- a/lua/lsp/lua.lua +++ b/lua/lsp/lua.lua @@ -1,22 +1,29 @@ +-- setting up lua +local runtime_path = vim.split(package.path, ";") +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + require("lspconfig").lua_ls.setup({ - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, }) diff --git a/lua/plugins/file-tree.lua b/lua/plugins/file-tree.lua index 63c5551..7a8ea24 100644 --- a/lua/plugins/file-tree.lua +++ b/lua/plugins/file-tree.lua @@ -15,9 +15,29 @@ require("nvim-tree").setup({ enable = true, update_root = true, }, - filters = { custom = { ".git" } }, + filters = { + custom = {}, + dotfiles = true, + exclude = { ".golangci*", ".protolint*", ".gitignore" }, + }, + filesystem_watchers = { + enable = true, + debounce_delay = 10, + }, + git = { + enable = true, + ignore = true, + show_on_dirs = true, + show_on_open_dirs = true, + timeout = 400, + }, + modified = { + enable = false, + show_on_dirs = true, + show_on_open_dirs = true, + }, view = { - width = 30, + width = 48, mappings = { list = { { key = "u", action = "dir_up" }, @@ -25,7 +45,52 @@ require("nvim-tree").setup({ }, }, renderer = { + full_name = true, group_empty = true, + indent_markers = { + enable = true, + }, + icons = { + git_placement = "signcolumn", + show = { + file = true, + folder = true, + folder_arrow = true, + git = true, + }, + }, + }, + diagnostics = { + enable = true, + show_on_dirs = true, + }, + actions = { + change_dir = { + enable = false, + restrict_above_cwd = true, + }, + open_file = { + resize_window = true, + window_picker = { + chars = "aoeui", + }, + }, + remove_file = { + close_window = false, + }, + }, + log = { + enable = false, + truncate = true, + types = { + all = false, + config = false, + copy_paste = false, + diagnostics = false, + git = false, + profile = false, + watcher = false, + }, }, }) diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua index 625601a..3dcaba3 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/gitsigns.lua @@ -1,92 +1,92 @@ require("gitsigns").setup({ - signs = { - add = { text = "│" }, - change = { text = "│" }, - delete = { text = "_" }, - topdelete = { text = "‾" }, - changedelete = { text = "~" }, - untracked = { text = "┆" }, - }, - signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` - numhl = false, -- Toggle with `:Gitsigns toggle_numhl` - linehl = false, -- Toggle with `:Gitsigns toggle_linehl` - word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` - watch_gitdir = { - interval = 1000, - follow_files = true, - }, - attach_to_untracked = true, - current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` - current_line_blame_opts = { - virt_text = true, - virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' - delay = 1000, - ignore_whitespace = false, - }, - current_line_blame_formatter = ", - ", - sign_priority = 6, - update_debounce = 100, - status_formatter = nil, -- Use default - max_file_length = 40000, -- Disable if file is longer than this (in lines) - preview_config = { - -- Options passed to nvim_open_win - border = "single", - style = "minimal", - relative = "cursor", - row = 0, - col = 1, - }, - yadm = { - enable = false, - }, - on_attach = function(bufnr) - local gs = package.loaded.gitsigns + signs = { + add = { text = "│" }, + change = { text = "│" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + untracked = { text = "┆" }, + }, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter = ", - ", + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = "single", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { + enable = false, + }, + on_attach = function(bufnr) + local gs = package.loaded.gitsigns - local function map(mode, l, r, opts) - opts = opts or {} - opts.buffer = bufnr - vim.keymap.set(mode, l, r, opts) - end + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end - -- Navigation - map("n", "]c", function() - if vim.wo.diff then - return "]c" - end - vim.schedule(function() - gs.next_hunk() - end) - return "" - end, { expr = true }) + -- Navigation + map("n", "]c", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + gs.next_hunk() + end) + return "" + end, { expr = true }) - map("n", "[c", function() - if vim.wo.diff then - return "[c" - end - vim.schedule(function() - gs.prev_hunk() - end) - return "" - end, { expr = true }) + map("n", "[c", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + gs.prev_hunk() + end) + return "" + end, { expr = true }) - -- Actions - map({ "n", "v" }, "hs", ":Gitsigns stage_hunk") - map({ "n", "v" }, "hr", ":Gitsigns reset_hunk") - map("n", "hS", gs.stage_buffer) - map("n", "hu", gs.undo_stage_hunk) - map("n", "hR", gs.reset_buffer) - map("n", "hp", gs.preview_hunk) - map("n", "hb", function() - gs.blame_line({ full = true }) - end) - map("n", "tb", gs.toggle_current_line_blame) - map("n", "hd", gs.diffthis) - map("n", "hD", function() - gs.diffthis("~") - end) - map("n", "td", gs.toggle_deleted) + -- Actions + map({ "n", "v" }, "hs", ":Gitsigns stage_hunk") + map({ "n", "v" }, "hr", ":Gitsigns reset_hunk") + map("n", "hS", gs.stage_buffer) + map("n", "hu", gs.undo_stage_hunk) + map("n", "hR", gs.reset_buffer) + map("n", "hp", gs.preview_hunk) + map("n", "hb", function() + gs.blame_line({ full = true }) + end) + map("n", "tb", gs.toggle_current_line_blame) + map("n", "hd", gs.diffthis) + map("n", "hD", function() + gs.diffthis("~") + end) + map("n", "td", gs.toggle_deleted) - -- Text object - map({ "o", "x" }, "ih", ":Gitsigns select_hunk") - end, + -- Text object + map({ "o", "x" }, "ih", ":Gitsigns select_hunk") + end, }) diff --git a/lua/plugins/golang.lua b/lua/plugins/golang.lua index 55d30be..5ce0e4b 100644 --- a/lua/plugins/golang.lua +++ b/lua/plugins/golang.lua @@ -1,6 +1,6 @@ require("go").setup() local format_sync_grp = vim.api.nvim_create_augroup("GoImport", {}) -vim.api.nvim_create_autocmd("BufWritePre", { +vim.api.nvim_create_autocmd("InsertLeavePre", { pattern = "*.go", callback = function() require("go.format").goimport() diff --git a/lua/plugins/java.lua b/lua/plugins/java.lua new file mode 100644 index 0000000..65b6d8b --- /dev/null +++ b/lua/plugins/java.lua @@ -0,0 +1,51 @@ +function IsFileExist(filename) + local f = io.open(filename) + if f ~= nil then + io.close(f) + return true + else + return false + end +end + +function IsDirectoryExist(dirname) + return os.rename(dirname, dirname) and true or false +end + +local jdtlspath = os.getenv("HOME") .. "/.jdtls" +if vim.loop.os_uname().sysname == "Windows" then + jdtlspath = os.getenv("HOME") .. "\\.jdtls" +end + +-- 创建目录 +if not IsFileExist(jdtlspath) then + os.execute("mkdir " .. jdtlspath) +end + +-- 检测文件存在否 +if not IsDirectoryExist(jdtlspath .. "/bin/jdtls") then + print("download jdtls binary") + local download_ret = os.execute( + "wget https://download.eclipse.org/jdtls/milestones/1.23.0/jdt-language-server-1.23.0-202304271346.tar.gz -P /tmp" + ) + if download_ret ~= 0 then + vim.notify("download jdtls binary failed") + return + end + vim.notify("download jdtls success") + local tar_ret = os.execute("tar xvzf /tmp/jdt-language-server-1.23.0-202304271346.tar.gz -C " .. jdtlspath) + if tar_ret ~= 0 then + vim.notify("extract jdtls file failed") + return + end +end + +local lombok_path = jdtlspath .. "/bin/lombok.jar" +-- 下载lombok +if not IsFileExist(jdtlspath .. "/bin/lombok.jar") then + vim.notify("download lombok.jar") + local download_ret = os.execute("wget https://projectlombok.org/downloads/lombok.jar -P " .. jdtlspath .. "/bin") + if download_ret ~= 0 then + vim.notify("download lombok failed") + end +end diff --git a/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua index 5f7c9fa..933dea2 100644 --- a/lua/plugins/lspsaga.lua +++ b/lua/plugins/lspsaga.lua @@ -3,6 +3,19 @@ require("lspsaga").setup({ colors = require("catppuccin.groups.integrations.lsp_saga").custom_colors(), kind = require("catppuccin.groups.integrations.lsp_saga").custom_kind(), }, + diagnostic = { + show_code_action = true, + }, + code_action = { + num_shortcut = true, + show_server_name = false, + extend_gitsigns = true, + keys = { + -- string | table type + quit = "q", + exec = "", + }, + }, }) require("lsp-colors").setup({ diff --git a/lua/plugins/mason.lua b/lua/plugins/mason.lua index 31dce0f..1225b99 100644 --- a/lua/plugins/mason.lua +++ b/lua/plugins/mason.lua @@ -9,28 +9,64 @@ require("mason").setup({ }) require("mason-lspconfig").setup({ - ensure_installed = { - "clangd", - "emmet_ls", - "cmake", - "gradle_ls", - "kotlin_language_server", - "lua_ls", - "rust_analyzer", - "gopls", - "golangci_lint_ls", - "tsserver", - "volar", - "taplo", - "yamlls", - "jsonls", - "jdtls", - "bashls", - "cssls", - "dockerls", - "docker_compose_language_service", - "eslint", - "html", - }, + ensure_installed = {}, automatic_installation = true, }) + +require("mason-tool-installer").setup({ + -- a list of all tools you want to ensure are installed upon + -- start; they should be the names Mason uses for each tool + ensure_installed = { + "bash-language-server", + "clangd", + "cmake-language-server", + "css-lsp", + "docker-compose-language-service", + "dockerfile-language-server", + "emmet-ls", + "eslint-lsp", + "goimports", + "goimports-reviser", + "golangci-lint", + "golangci-lint-langserver", + "golines", + "gopls", + "gradle-language-server", + "html-lsp", + "jdtls", + "json-lsp", + "kotlin-language-server", + "lua-language-server", + "rust-analyzer", + "rustfmt", + "stylua", + "taplo", + "typescript-language-server", + "vue-language-server", + "yaml-language-server", + "yamlfmt", + "yamllint", + }, + -- if set to true this will check each tool for updates. If updates + -- are available the tool will be updated. This setting does not + -- affect :MasonToolsUpdate or :MasonToolsInstall. + -- Default: false + auto_update = true, + -- automatically install / update on startup. If set to false nothing + -- will happen on startup. You can use :MasonToolsInstall or + -- :MasonToolsUpdate to install tools and check for updates. + -- Default: true + run_on_start = true, + -- set a delay (in ms) before the installation starts. This is only + -- effective if run_on_start is set to true. + -- e.g.: 5000 = 5 second delay, 10000 = 10 second delay, etc... + -- Default: 0 + start_delay = 15000, -- 3 second delay + -- Only attempt to install if 'debounce_hours' number of hours has + -- elapsed since the last time Neovim was started. This stores a + -- timestamp in a file named stdpath('data')/mason-tool-installer-debounce. + -- This is only relevant when you are using 'run_on_start'. It has no + -- effect when running manually via ':MasonToolsInstall' etc.... + -- Default: nil + debounce_hours = 24, -- at least 5 hours between attempts to install/update +}) diff --git a/lua/plugins/notify.lua b/lua/plugins/notify.lua index 346d575..dab38eb 100644 --- a/lua/plugins/notify.lua +++ b/lua/plugins/notify.lua @@ -1 +1,5 @@ +require("notify").setup({ + background_colour = "#000000", +}) + vim.notify = require("notify") diff --git a/lua/plugins/null-ls.lua b/lua/plugins/null-ls.lua index 114f60a..cdeb406 100644 --- a/lua/plugins/null-ls.lua +++ b/lua/plugins/null-ls.lua @@ -1,10 +1,12 @@ local null_ls = require("null-ls") null_ls.setup({ + debounce = 500, sources = { null_ls.builtins.formatting.stylua, null_ls.builtins.formatting.gofmt, null_ls.builtins.formatting.eslint_d, + null_ls.builtins.formatting.yamlfmt, null_ls.builtins.formatting.protolint, -- 诊断 null_ls.builtins.diagnostics.eslint_d, diff --git a/lua/plugins/rust.lua b/lua/plugins/rust.lua new file mode 100644 index 0000000..782b0a4 --- /dev/null +++ b/lua/plugins/rust.lua @@ -0,0 +1,12 @@ +local rt = require("rust-tools") + +rt.setup({ + server = { + on_attach = function(_, bufnr) + -- Hover actions + vim.keymap.set("n", "", rt.hover_actions.hover_actions, { buffer = bufnr }) + -- Code action groups + vim.keymap.set("n", "a", rt.code_action_group.code_action_group, { buffer = bufnr }) + end, + }, +}) diff --git a/lua/setup.lua b/lua/setup.lua index 7c55799..adeda26 100644 --- a/lua/setup.lua +++ b/lua/setup.lua @@ -44,6 +44,7 @@ return require("packer").startup(function(use) "williamboman/mason-lspconfig.nvim", "neovim/nvim-lspconfig", "jose-elias-alvarez/null-ls.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", }) -- 命令行 use({ @@ -148,11 +149,15 @@ return require("packer").startup(function(use) -- install jsregexp (optional!:). run = "make install_jsregexp", }) + -- rust ide + use({ "simrat39/rust-tools.nvim" }) -- golang ide use({ "ray-x/go.nvim", "ray-x/guihua.lua", -- recommended if need floating window support }) + -- java ide + use({ "mfussenegger/nvim-jdtls" }) -- 高亮当前关键词 use({ "RRethy/vim-illuminate" }) -- 罗列文件中的所有url