first commit

This commit is contained in:
2023-05-21 04:07:45 +08:00
commit 9c1e0c51c0
36 changed files with 3249 additions and 0 deletions

5
lua/custom/chadrc.lua Normal file
View File

@@ -0,0 +1,5 @@
local M = {}
M.ui = { theme = "onedark" }
M.plugins = "custom.plugins"
M.mappings = require "custom.mappings"
return M

View File

@@ -0,0 +1,54 @@
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
local util = require "lspconfig/util"
-- LUA LSP
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
lspconfig.lua_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
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,
},
},
},
}
-- GO LSP
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
}

View File

@@ -0,0 +1,38 @@
local null_ls = require "null-ls"
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local sources = {
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.goimports_reviser,
null_ls.builtins.formatting.gofumpt,
null_ls.builtins.formatting.golines.with {
extra_args = {
"--max-len=180",
"--base-formatter=gofumpt",
},
},
null_ls.builtins.formatting.eslint_d,
null_ls.builtins.formatting.yamlfmt,
null_ls.builtins.formatting.protolint,
-- 诊断
null_ls.builtins.diagnostics.protolint,
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.code_actions.eslint_d,
}
null_ls.setup {
debounce = 1000,
default_timeout = 5000,
sources = sources,
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
vim.api.nvim_create_autocmd("InsertLeave", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format { bufnr = bufnr }
end,
})
end
end,
}

View File

@@ -0,0 +1,14 @@
local M = {}
M.indent_blackline = {
show_current_context = true,
show_current_context_start = true,
show_end_of_line = true,
space_char_blankline = " ",
}
M.nvimtree = {
filters = {
dotfiles = true,
exclude = { ".golangci*", ".protolint*", ".gitignore", ".eslintrc*" },
},
}
return M

View File

@@ -0,0 +1,61 @@
return {
-- A list of parser names, or "all" (the four listed parsers should always be installed)
ensure_installed = {
"bash",
"c",
"css",
"dart",
"diff",
"dockerfile",
"git_rebase",
"gitattributes",
"gitcommit",
"gitignore",
"go",
"gomod",
"gosum",
"gowork",
"html",
"java",
"javascript",
"json",
"lua",
"markdown",
"rust",
"toml",
"typescript",
"vim",
"vue",
"yaml",
"proto",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = true,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = {},
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
node_decremental = "<BS>",
scope_incremental = "<TAB>",
},
},
indent = {
enable = true,
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
autotag = {
enable = true,
},
}

71
lua/custom/init.lua Normal file
View File

@@ -0,0 +1,71 @@
-- 文件编码
vim.g.encoding = "UTF-8"
vim.o.fileencoding = "utf-8"
-- 高亮所在行
vim.wo.cursorline = true
-- 显示左侧图标指示列
vim.wo.signcolumn = "yes"
-- 右侧参考线,超过表示代码太长了,考虑换行
vim.wo.colorcolumn = "120"
-- 缩进2个空格等于一个Tab
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.autoindent = true
-- 新行对齐当前行
vim.o.autoindent = true
vim.bo.autoindent = true
vim.o.smartindent = true
-- 搜索大小写不敏感,除非包含大写
vim.o.ignorecase = true
vim.o.smartcase = true
-- 搜索不要高亮
vim.o.hlsearch = false
-- 边输入边搜索
vim.o.incsearch = true
-- 命令行高为2提供足够的显示空间
vim.o.cmdheight = 1
-- 当文件被外部程序修改时,自动加载
vim.o.autoread = true
vim.bo.autoread = true
-- 禁止折行
vim.wo.wrap = true
-- 光标在行首尾时<Left><Right>可以跳到下一行
vim.o.whichwrap = "<,>,[,]"
-- 允许隐藏被修改过的buffer
vim.o.hidden = true
-- 鼠标支持
vim.o.mouse = "a"
-- smaller updatetime
vim.o.updatetime = 3000
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒可根据需要设置
-- 遇到问题详见https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 1000
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
-- 自动补全不自动选中
vim.g.completeopt = "menu,menuone,noselect,noinsert"
-- 是否显示不可见字符
vim.o.list = false
-- 不可见字符的显示,这里只把空格显示为一个点
vim.o.listchars = "space:·,tab:··"
-- 补全增强
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. "c"
-- 补全最多显示10行
vim.o.pumheight = 20
-- 配置剪切板
vim.opt.clipboard = "unnamedplus"
vim.opt.backup = false
vim.opt.swapfile = false
vim.opt.writebackup = false
vim.opt.undofile = true
-- 换行符号
vim.opt.list = true
vim.opt.listchars:append "space:⋅"
vim.opt.listchars:append "eol:↴"
-- 文件树配置
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

87
lua/custom/mappings.lua Normal file
View File

@@ -0,0 +1,87 @@
local M = {}
M.format = {
n = {
["="] = { "<cmd>lua vim.lsp.buf.format()<cr>", "general format" },
},
}
M.dap = {
n = {
["<leader>db"] = {
"<cmd> DapToggleBreakpoint <CR>",
"Add breakpoint at line",
},
["<leader>dus"] = {
function()
local widgets = require "dap.ui.widgets"
local sidebar = widgets.sidebar(widgets.scopes)
sidebar.open()
end,
"Open debugging sidebar",
},
},
}
M.dap_go = {
n = {
["<leader>dgt"] = {
function()
require("dap-go").debug_test()
end,
"Debug go test",
},
["<leader>dgl"] = {
function()
require("dap-go").debug_last()
end,
"Debug last go test",
},
},
}
M.beacon = {
n = {
["n"] = { "n:Beacon<CR>", "" },
["N"] = { "N:Beacon<CR>", "" },
["*"] = { "*:Beacon<CR>", "" },
["#"] = { "#:Beacon<CR>", "" },
},
}
M.trouble = {
n = {
["<leader>xx"] = { "<cmd>TroubleToggle document_diagnostics<cr>", desc = "Document Diagnostics (Trouble)" },
["<leader>xX"] = { "<cmd>TroubleToggle workspace_diagnostics<cr>", desc = "Workspace Diagnostics (Trouble)" },
["<leader>xL"] = { "<cmd>TroubleToggle loclist<cr>", desc = "Location List (Trouble)" },
["<leader>xQ"] = { "<cmd>TroubleToggle quickfix<cr>", desc = "Quickfix List (Trouble)" },
["[q"] = {
function()
if require("trouble").is_open() then
require("trouble").previous { skip_groups = true, jump = true }
else
vim.cmd.cprev()
end
end,
desc = "Previous trouble/quickfix item",
},
["]q"] = {
function()
if require("trouble").is_open() then
require("trouble").next { skip_groups = true, jump = true }
else
vim.cmd.cnext()
end
end,
desc = "Next trouble/quickfix item",
},
},
}
M.fine_cmdline = {
n = {
[":"] = { "<cmd>FineCmdline<CR>", "cmd" },
},
}
return M

219
lua/custom/plugins.lua Normal file
View File

@@ -0,0 +1,219 @@
local plugins = {
{
"williamboman/mason.nvim",
build = ":MasonUpdate", -- :MasonUpdate updates registry contents
opts = {
ensure_installed = {
"bash-language-server",
"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",
"json-lsp",
"lua-language-server",
"rust-analyzer",
"rustfmt",
"stylua",
"taplo",
"typescript-language-server",
"vue-language-server",
"yaml-language-server",
"yamlfmt",
"yamllint",
},
},
},
{
"jose-elias-alvarez/null-ls.nvim",
config = function()
require "custom.configs.null-ls"
end,
},
{
"neovim/nvim-lspconfig",
dependencies = {
"jose-elias-alvarez/null-ls.nvim",
config = function()
require "custom.configs.null-ls"
end,
},
config = function()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end,
},
{
"ray-x/go.nvim",
dependencies = { -- optional packages
"ray-x/guihua.lua",
"neovim/nvim-lspconfig",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("go").setup()
end,
event = { "CmdlineEnter" },
ft = { "go", "gomod" },
build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries
},
{
"mfussenegger/nvim-dap",
init = function()
require("core.utils").load_mappings "dap"
end,
},
{
"leoluz/nvim-dap-go",
ft = "go",
dependencies = {
"mfussenegger/nvim-dap",
},
config = function(_, opts)
require("dap-go").setup(opts)
end,
},
{
"rcarriga/nvim-notify",
keys = {
{
"<leader>un",
function()
require("notify").dismiss { silent = true, pending = true }
end,
desc = "Dismiss all Notifications",
},
},
opts = {
timeout = 3000,
max_height = function()
return math.floor(vim.o.lines * 0.75)
end,
max_width = function()
return math.floor(vim.o.columns * 0.75)
end,
},
init = function()
-- when noice is not enabled, install notify on VeryLazy
vim.notify = require "notify"
end,
},
{
"lukas-reineke/indent-blankline.nvim",
opts = function()
return require("custom.configs.others").indent_blackline
end,
},
{
"nvim-treesitter/nvim-treesitter",
opts = function()
return require "custom.configs.treesitter"
end,
},
{
"nvim-tree/nvim-tree.lua",
config = true,
opts = require("custom.configs.others").nvimtree,
},
{
"danilamihailov/beacon.nvim",
cmd = { "Beacon" },
},
{
"folke/trouble.nvim",
cmd = { "TroubleToggle", "Trouble" },
opts = { use_diagnostic_signs = true },
},
{
"RRethy/vim-illuminate",
event = { "BufReadPost", "BufNewFile" },
opts = { delay = 200 },
config = function(_, opts)
require("illuminate").configure(opts)
local function map(key, dir, buffer)
vim.keymap.set("n", key, function()
require("illuminate")["goto_" .. dir .. "_reference"](false)
end, { desc = dir:sub(1, 1):upper() .. dir:sub(2) .. " Reference", buffer = buffer })
end
map("]]", "next")
map("[[", "prev")
-- also set it after loading ftplugins, since a lot overwrite [[ and ]]
vim.api.nvim_create_autocmd("FileType", {
callback = function()
local buffer = vim.api.nvim_get_current_buf()
map("]]", "next", buffer)
map("[[", "prev", buffer)
end,
})
end,
keys = {
{ "]]", desc = "Next Reference" },
{ "[[", desc = "Prev Reference" },
},
},
{
"ggandor/flit.nvim",
keys = function()
---@type LazyKeys[]
local ret = {}
for _, key in ipairs { "f", "F", "t", "T" } do
ret[#ret + 1] = { key, mode = { "n", "x", "o" }, desc = key }
end
return ret
end,
opts = { labeled_modes = "nx" },
event = { "CmdlineEnter" },
},
{
"ggandor/leap.nvim",
-- stylua: ignore
keys = {
{ "s", mode = { "n", "x", "o" }, desc = "Leap forward to" },
{ "S", mode = { "n", "x", "o" }, desc = "Leap backward to" },
{ "gs", mode = { "n", "x", "o" }, desc = "Leap from windows" },
},
event = { "CmdlineEnter" },
config = function(_, opts)
local leap = require "leap"
for k, v in pairs(opts) do
leap.opts[k] = v
end
leap.add_default_mappings(true)
vim.keymap.del({ "x", "o" }, "x")
vim.keymap.del({ "x", "o" }, "X")
end,
},
{
"Pocco81/auto-save.nvim",
lazy = false,
opts = {
trigger_events = { "InsertLeave", "BufLeave", "BufWinLeave" },
},
},
{
"VonHeikemen/fine-cmdline.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
},
cmd = { "FineCmdline" },
},
{
"j-hui/fidget.nvim",
config = true,
event = { "BufWinEnter" },
},
}
return plugins