feat: support java

fix: nvim tree filter .gitignore
support: rust language
This commit is contained in:
2023-04-02 18:47:14 +08:00
parent 5ee995ebea
commit 27b6726aea
25 changed files with 1060 additions and 199 deletions

View File

@@ -4,6 +4,8 @@ vim.g.maplocalleader = " "
local map = vim.keymap
local noreopt = { noremap = true, silent = true }
-- 重启lsp
map.set("n", "<leader>lr", "<cmd>LspRestart<CR>", noreopt)
-- save
map.set({ "n", "i" }, "<C-s>", "<cmd>w<cr>", noreopt)
-- format
@@ -27,6 +29,10 @@ map.set("n", "<C-h>", "<C-w>h", noreopt)
map.set("n", "<C-j>", "<C-w>j", noreopt)
map.set("n", "<C-k>", "<C-w>k", noreopt)
map.set("n", "<C-l>", "<C-w>l", noreopt)
-- 折叠配置
map.set({"n", "v"}, "<leader>z+", "zM", noreopt)
map.set({"n", "v"}, "<leader>z-", "zR", noreopt)
map.set({"n", "v"}, "<leader>zz", "za", noreopt)
-- 分屏
map.set("n", "<leader>sv", ":vsp<CR>", noreopt)
map.set("n", "<leader>sh", ":sp<CR>", noreopt)
@@ -50,8 +56,8 @@ map.set("n", "qn", ":q!<CR>", noreopt)
map.set("n", "qq", ":qa!<CR>", noreopt)
map.set("i", "jk", "<ESC>", noreopt)
-- 文件页切换
map.set("n", "<leader>bl", ":BufferLineCyclePrev<CR>", noreopt)
map.set("n", "<leader>br", ":BufferLineCycleNext<CR>", noreopt)
map.set("n", "<leader>ll", ":BufferLineCyclePrev<CR>", noreopt)
map.set("n", "<leader>hh", ":BufferLineCycleNext<CR>", noreopt)
map.set("n", "<leader>bpi", ":BufferLineTogglePin<CR>", noreopt)
map.set("n", "<leader>bcl", ":BufferLineCloseLeft<CR>", noreopt)
map.set("n", "<leader>bcr", ":BufferLineCloseRight<CR>", noreopt)

View File

@@ -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

View File

@@ -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,
}

View File

@@ -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,
},
},
},
})

View File

@@ -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 = 40,
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,
},
},
})

View File

@@ -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 = "<author>, <author_time:%Y-%m-%d> - <summary>",
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 = "<author>, <author_time:%Y-%m-%d> - <summary>",
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 "<Ignore>"
end, { expr = true })
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
-- Actions
map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line({ full = true })
end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function()
gs.diffthis("~")
end)
map("n", "<leader>td", gs.toggle_deleted)
-- Actions
map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line({ full = true })
end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function()
gs.diffthis("~")
end)
map("n", "<leader>td", gs.toggle_deleted)
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})

View File

@@ -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()

51
lua/plugins/java.lua Normal file
View File

@@ -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

View File

@@ -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 = "<CR>",
},
},
})
require("lsp-colors").setup({

View File

@@ -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
})

View File

@@ -1 +1,5 @@
require("notify").setup({
background_colour = "#000000",
})
vim.notify = require("notify")

View File

@@ -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,

12
lua/plugins/rust.lua Normal file
View File

@@ -0,0 +1,12 @@
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
},
})

View File

@@ -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