feat(migrate): update to v2.5

This commit is contained in:
DefectingCat
2024-03-12 08:49:15 +08:00
parent 9d47133ba1
commit 0c6347c470
19 changed files with 1868 additions and 9 deletions

View File

@ -37,3 +37,4 @@ require "nvchad.autocmds"
vim.schedule(function()
require "mappings"
end)
require 'myinit'

65
lazy-lock.json Normal file
View File

@ -0,0 +1,65 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" },
"NvChad": { "branch": "v2.5", "commit": "cf1db9821a9bfe4e03eaa036fd791e55eae53117" },
"base46": { "branch": "v2.5", "commit": "9d677af06153a8a68e52cdb10e6eec5db4bcaa6a" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"conform.nvim": { "branch": "master", "commit": "db2c697fe8302f0328b50b480204be1b577a1e2f" },
"crates.nvim": { "branch": "main", "commit": "535773ed3b321d68ddd6ef8cd5a1e07b345026a6" },
"diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" },
"error-lens.nvim": { "branch": "main", "commit": "e13b966dfd42517a92df1eb5d73fd14905e483a6" },
"friendly-snippets": { "branch": "main", "commit": "dcd4a586439a1c81357d5b9d26319ae218cc9479" },
"gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" },
"gopher.nvim": { "branch": "main", "commit": "ac27f4b6794c872140fb205313d79ab166892fe9" },
"hop.nvim": { "branch": "v2", "commit": "90db1b2c61b820e230599a04fedcd2679e64bd07" },
"hydra.nvim": { "branch": "master", "commit": "55de54543d673824435930ecf533256eea2e565b" },
"indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" },
"lazy.nvim": { "branch": "main", "commit": "83493db50a434a4c5c648faf41e2ead80f96e478" },
"lazygit.nvim": { "branch": "main", "commit": "774dcecbd0b9b57be6c150adacb60ced79b11b23" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "55716a879568a498fa236593c8119789054a3b8e" },
"mason-null-ls.nvim": { "branch": "main", "commit": "e270134d83ba59425edc53356c6fd337b61bb8dd" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "67210c0e775adec55de9826b038e8b62de554afc" },
"mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" },
"multicursors.nvim": { "branch": "main", "commit": "8b3e14682eed06a532b155c7eae33e174846b3fd" },
"noice.nvim": { "branch": "main", "commit": "bf67d70bd7265d075191e7812d8eb42b9791f737" },
"none-ls.nvim": { "branch": "main", "commit": "ff3819c52ca04232fb70fbd6c1639de9abcbe122" },
"nui.nvim": { "branch": "main", "commit": "756c59f46057cd2d43619cd3a6d4e01b2aa60295" },
"nvcommunity": { "branch": "main", "commit": "1d96504675c7514a9e89c6bdb14921cc8f7d10ca" },
"nvim-autopairs": { "branch": "master", "commit": "c6139ca0d5ad7af129ea6c89cb4c56093f2c034a" },
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
"nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" },
"nvim-dap": { "branch": "master", "commit": "fc880e82059eb21c0fa896be60146e5f17680648" },
"nvim-dap-go": { "branch": "main", "commit": "605911fa0899882b05a8e4369ab12739620494af" },
"nvim-dap-ui": { "branch": "master", "commit": "9720eb5fa2f41988e8770f973cd11b76dd568a5d" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "baa5b0dc6663284cce32e0d00ac1f2511b13496f" },
"nvim-lspconfig": { "branch": "master", "commit": "1917b562a02f20885900b1da0f0ea25028ccedab" },
"nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" },
"nvim-spectre": { "branch": "master", "commit": "3712ff0cdf4f9f877d9ca708d835a877d9a0abaf" },
"nvim-surround": { "branch": "main", "commit": "d47001f8ddf9646c24f16d2732d4d0255acd2121" },
"nvim-tree.lua": { "branch": "master", "commit": "041dbd18f440207ad161503a384e7c82d575db66" },
"nvim-treesitter": { "branch": "master", "commit": "9d39f00a9559cf3505d73b486c0b8055a6db4215" },
"nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "7ab799a9792f7cf3883cf28c6a00ad431f3d382a" },
"nvim-web-devicons": { "branch": "master", "commit": "75df79feb02d5e0ec114e447453775d4d291ea03" },
"nvterm": { "branch": "main", "commit": "9d7ba3b6e368243175d38e1ec956e0476fd86ed9" },
"plenary.nvim": { "branch": "master", "commit": "f7adfc4b3f4f91aab6caebf42b3682945fbc35be" },
"pretty_hover": { "branch": "master", "commit": "392f6f71c6526955fcf510d48930bce7864b6915" },
"rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" },
"rustaceanvim": { "branch": "master", "commit": "5dc35a075ad7c9d2f6493065e1e5970e4ad61504" },
"schemastore.nvim": { "branch": "main", "commit": "b788bde023f9fbc2eb86e89d32c0bf98a60ae406" },
"tailwindcss-colorizer-cmp.nvim": { "branch": "main", "commit": "bc25c56083939f274edcfe395c6ff7de23b67c50" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "master", "commit": "7472420f8734c710bd7009081cef9b97f08a3821" },
"todo-comments.nvim": { "branch": "main", "commit": "833d8dd8b07eeda37a09e99460f72a02616935cb" },
"trouble.nvim": { "branch": "main", "commit": "f1168feada93c0154ede4d1fe9183bf69bac54ea" },
"ui": { "branch": "v2.5", "commit": "95e6495d3cfe58de41025e8b0f3f3077719ec591" },
"vim-illuminate": { "branch": "master", "commit": "305bf07b919ac526deb5193280379e2f8b599926" },
"vim-mdx-js": { "branch": "master", "commit": "17179d7f2a73172af5f9a8d65b01a3acf12ddd50" },
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }
}

View File

@ -1,7 +1,99 @@
---@type ChadrcConfig
local M = {}
M.ui = {
theme = "onedark",
lsp_semantic_tokens = false,
transparency = false,
theme = "catppuccin",
statusline = {
theme = "default", -- default/vscode/vscode_colored/minimal
-- default/round/block/arrow (separators work only for "default" statusline theme;
-- round and block will work for the minimal theme only)
separator_style = "round",
overriden_modules = nil,
},
tabufline = {
lazyload = true,
overriden_modules = nil,
},
nvdash = {
load_on_startup = true,
header = {
"⣇⣿⠘⣿⣿⣿⡿⡿⣟⣟⢟⢟⢝⠵⡝⣿⡿⢂⣼⣿⣷⣌⠩⡫⡻⣝⠹⢿⣿⣷",
"⡆⣿⣆⠱⣝⡵⣝⢅⠙⣿⢕⢕⢕⢕⢝⣥⢒⠅⣿⣿⣿⡿⣳⣌⠪⡪⣡⢑⢝⣇",
"⡆⣿⣿⣦⠹⣳⣳⣕⢅⠈⢗⢕⢕⢕⢕⢕⢈⢆⠟⠋⠉⠁⠉⠉⠁⠈⠼⢐⢕⢽",
"⡗⢰⣶⣶⣦⣝⢝⢕⢕⠅⡆⢕⢕⢕⢕⢕⣴⠏⣠⡶⠛⡉⡉⡛⢶⣦⡀⠐⣕⢕",
"⡝⡄⢻⢟⣿⣿⣷⣕⣕⣅⣿⣔⣕⣵⣵⣿⣿⢠⣿⢠⣮⡈⣌⠨⠅⠹⣷⡀⢱⢕",
"⡝⡵⠟⠈⢀⣀⣀⡀⠉⢿⣿⣿⣿⣿⣿⣿⣿⣼⣿⢈⡋⠴⢿⡟⣡⡇⣿⡇⡀⢕",
"⡝⠁⣠⣾⠟⡉⡉⡉⠻⣦⣻⣿⣿⣿⣿⣿⣿⣿⣿⣧⠸⣿⣦⣥⣿⡇⡿⣰⢗⢄",
"⠁⢰⣿⡏⣴⣌⠈⣌⠡⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣬⣉⣉⣁⣄⢖⢕⢕⢕",
"⡀⢻⣿⡇⢙⠁⠴⢿⡟⣡⡆⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣵⣵⣿",
"⡻⣄⣻⣿⣌⠘⢿⣷⣥⣿⠇⣿⣿⣿⣿⣿⣿⠛⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿",
"⣷⢄⠻⣿⣟⠿⠦⠍⠉⣡⣾⣿⣿⣿⣿⣿⣿⢸⣿⣦⠙⣿⣿⣿⣿⣿⣿⣿⣿⠟",
"⡕⡑⣑⣈⣻⢗⢟⢞⢝⣻⣿⣿⣿⣿⣿⣿⣿⠸⣿⠿⠃⣿⣿⣿⣿⣿⣿⡿⠁⣠",
"⡝⡵⡈⢟⢕⢕⢕⢕⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣿⣿⣿⣿⣿⠿⠋⣀⣈⠙",
"⡝⡵⡕⡀⠑⠳⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢉⡠⡲⡫⡪⡪⡣",
},
extended_integrations = {
"dap",
"hop",
"rainbowdelimiters",
"codeactionmenu",
"todo",
"trouble",
"notify",
},
buttons = {
{ " Find File", "Spc f f", "Telescope find_files" },
{ "󰈚 Recent Files", "Spc f o", "Telescope oldfiles" },
{ "󰈭 Find Word", "Spc f w", "Telescope live_grep" },
{ " Bookmarks", "Spc m a", "Telescope marks" },
{ " Themes", "Spc t h", "Telescope themes" },
{ " Mappings", "Spc c h", "NvCheatsheet" },
},
},
---@type Base46HLGroupsList
hl_override = {
NvDashAscii = { bg = "NONE", fg = "#85c0dc" },
NvDashButtons = { bg = "NONE", fg = "#b4befe" },
CursorLine = {
bg = "#313244",
},
Search = {
--[[ bg = "#89dceb", ]]
bg = "#f5c2e7",
},
},
-- cmp themeing
cmp = {
icons = true,
lspkind_text = true,
style = "atom", -- default/flat_light/flat_dark/atom/atom_colored
border_color = "grey_fg", -- only applicable for "default" style, use color names from base30 variables
selected_item_bg = "colored", -- colored / simple
},
}
--[[ M.gitsigns = {
signs = {
add = { text = " " },
change = { text = " " },
delete = { text = " " },
topdelete = { text = " " },
changedelete = { text = " " },
untracked = { text = " " },
},
} ]]
-- M.plugins = "custom.plugins"
-- M.mappings = require "custom.mappings"
return M

23
lua/configs/dap.lua Normal file
View File

@ -0,0 +1,23 @@
local dap = require("dap")
dap.adapters["pwa-node"] = {
type = "server",
host = "127.0.0.1",
port = 8123,
executable = {
command = "js-debug-adapter",
},
}
for _, language in ipairs({ "typescript", "javascript" }) do
dap.configurations[language] = {
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = "${workspaceFolder}",
runtimeExecutable = "node",
},
}
end

152
lua/configs/lspconfig.lua Normal file
View File

@ -0,0 +1,152 @@
local on_attach = require("nvchad.configs.lspconfig").on_attach
local capabilities = require("nvchad.configs.lspconfig").capabilities
local lspconfig = require("lspconfig")
local util = require("lspconfig/util")
local function organize_imports()
local params = {
command = "_typescript.organizeImports",
arguments = { vim.api.nvim_buf_get_name(0) },
}
vim.lsp.buf.execute_command(params)
end
require("mason-lspconfig").setup_handlers({
function(server)
if server == "rust_analyzer" then
return nil
end
lspconfig[server].setup({
on_attach = on_attach,
capabilities = capabilities,
})
end,
})
--[[ lspconfig.rust_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
standalone = true,
files = {
excludeDirs = {
".flatpak-builder",
"_build",
".dart_tool",
".flatpak-builder",
".git",
".gitlab",
".gitlab-ci",
".gradle",
".idea",
".next",
".project",
".scannerwork",
".settings",
".venv",
"archetype-resources",
"bin",
"hooks",
"node_modules",
"po",
"screenshots",
"target",
"out",
"../out",
"../node_modules",
"../.next",
},
},
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
},
}) ]]
lspconfig.tsserver.setup({
on_attach = on_attach,
capabilities = capabilities,
init_options = {
preferences = {
disableSuggestions = true,
},
},
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports",
},
},
})
lspconfig.pylsp.setup({
on_attach = on_attach,
capabilities = capabilities,
filetypes = { "python" },
settings = {
pylsp = {
plugins = {
pycodestyle = {
ignore = { "W391" },
maxLineLength = 100,
},
},
},
},
})
lspconfig.gopls.setup({
on_attach = on_attach,
capabilities = capabilities,
cmd = { "gopls" },
cmd_env = {
GOFLAGS = "-tags=test,e2e_test,integration_test,acceptance_test",
},
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
})
lspconfig.jsonls.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
},
},
})
lspconfig.yamlls.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
yaml = {
schemaStore = {
-- You must disable built-in schemaStore support if you want to use
-- this plugin and its advanced options like `ignore`.
enable = false,
-- Avoid TypeError: Cannot read properties of undefined (reading 'length')
url = "",
},
schemas = require("schemastore").yaml.schemas(),
},
},
})

66
lua/configs/null-ls.lua Normal file
View File

@ -0,0 +1,66 @@
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local null_ls = require("null-ls")
local formatting = null_ls.builtins.formatting -- to setup formatters
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
local code_actions = null_ls.builtins.code_actions
local eslint_condition = function(utils)
return utils.root_has_file({
".eslintcache",
".eslintrc",
".eslintrc.js",
".eslintrc.cjs",
".eslintrc.yaml",
".eslintrc.yml",
".eslintrc.json",
})
end
local opts = {
sources = {
-- Golang
formatting.gofmt,
formatting.goimports_reviser,
formatting.golines,
-- JavaScript
formatting.prettierd.with({
prefer_local = "node_modules/.bin",
}),
-- Lua
formatting.stylua,
-- XML and SVG
--[[ formatting.xmlformat.with({
filetypes = {
"xml",
"svg",
},
}), ]]
-- Bash
formatting.shfmt,
-- sql
diagnostics.sqlfluff.with({
extra_args = { "--dialect", "postgres" }, -- change to your dialect
}),
formatting.sqlfluff.with({
extra_args = { "--dialect", "postgres" }, -- change to your dialect
}),
},
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("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,
}
return opts

21
lua/configs/overrides.lua Normal file
View File

@ -0,0 +1,21 @@
local M = {}
-- git support in nvimtree
M.nvimtree = {
git = {
enable = true,
ignore = false,
timeout = 500,
},
renderer = {
highlight_git = true,
icons = {
show = {
git = true,
},
},
},
}
return M

View File

@ -0,0 +1,80 @@
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local mason_registry = require "mason-registry"
local codelldb = mason_registry.get_package "codelldb"
local extension_path = codelldb:get_install_path() .. "/extension/"
local codelldb_path = extension_path .. "adapter/codelldb"
local liblldb_path = ""
if vim.loop.os_uname().sysname:find "Windows" then
liblldb_path = extension_path .. "lldb\\bin\\liblldb.dll"
elseif vim.fn.has "mac" == 1 then
liblldb_path = extension_path .. "lldb/lib/liblldb.dylib"
else
liblldb_path = extension_path .. "lldb/lib/liblldb.so"
end
local options = {
server = {
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
standalone = true,
cargo = {
allFeatures = true,
loadOutDirsFromCheck = true,
runBuildScripts = true,
},
checkOnSave = {
allFeatures = true,
command = "clippy",
extraArgs = { "--no-deps" },
},
files = {
excludeDirs = {
".flatpak-builder",
"_build",
".dart_tool",
".flatpak-builder",
".git",
".gitlab",
".gitlab-ci",
".gradle",
".idea",
".next",
".project",
".scannerwork",
".settings",
".venv",
"archetype-resources",
"bin",
"hooks",
"node_modules",
"po",
"screenshots",
"target",
},
},
},
check = {
command = "clippy",
features = "all",
extraArgs = { "--no-deps" },
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
},
},
dap = {
adapter = require("rust-tools.dap").get_codelldb_adapter(codelldb_path, liblldb_path),
},
}
return options

76
lua/configs/rust.lua Normal file
View File

@ -0,0 +1,76 @@
vim.g.rustaceanvim = function()
local mason_registry = require("mason-registry")
local codelldb = mason_registry.get_package("codelldb")
local extension_path = codelldb:get_install_path() .. "/extension/"
local codelldb_path = extension_path .. "adapter/codelldb"
local liblldb_path = ""
if vim.loop.os_uname().sysname:find("Windows") then
liblldb_path = extension_path .. "lldb\\bin\\liblldb.dll"
elseif vim.fn.has("mac") == 1 then
liblldb_path = extension_path .. "lldb/lib/liblldb.dylib"
else
liblldb_path = extension_path .. "lldb/lib/liblldb.so"
end
-- keymap
local bufnr = vim.api.nvim_get_current_buf()
vim.keymap.set("n", "<leader>ca", function()
--[[ vim.cmd.RustLsp("codeAction") -- supports rust-analyzer's grouping ]]
vim.lsp.buf.code_action()
end, { silent = true, buffer = bufnr })
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { silent = true, buffer = bufnr })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { silent = true, buffer = bufnr })
local cfg = require("rustaceanvim.config")
return {
tools = {},
server = {
settings = {
["rust-analyzer"] = {
standalone = true,
files = {
excludeDirs = {
".flatpak-builder",
"_build",
".dart_tool",
".flatpak-builder",
".git",
".gitlab",
".gitlab-ci",
".gradle",
".idea",
".next",
".project",
".scannerwork",
".settings",
".venv",
"archetype-resources",
"bin",
"hooks",
"node_modules",
"po",
"screenshots",
"target",
"out",
"../out",
"../node_modules",
"../.next",
},
},
},
procMacro = {
enable = true,
ignored = {
["async-trait"] = { "async_trait" },
["napi-derive"] = { "napi" },
["async-recursion"] = { "async_recursion" },
},
},
},
},
dap = {
adapter = cfg.get_codelldb_adapter(codelldb_path, liblldb_path),
},
}
end

16
lua/configs/telescope.lua Normal file
View File

@ -0,0 +1,16 @@
local options = {
extensions = {
["ui-select"] = {
require("telescope.themes").get_dropdown {
-- even more opts
},
},
},
}
local telescope = require "telescope"
telescope.load_extension "ui-select"
telescope.load_extension "notify"
telescope.load_extension "fzf"
return options

View File

@ -1,13 +1,435 @@
require "nvchad.mappings"
local M = {}
-- add yours here
M.disabled = {
n = {
["<leader>wa"] = "",
["<leader>wr"] = "",
["<leader>wl"] = "",
["<leader>wK"] = "",
["<leader>wk"] = "",
["<leader>cm"] = "",
},
}
local map = vim.keymap.set
M.crates = {
plugin = true,
n = {
["<leader>rcu"] = {
function()
require("crates").upgrade_all_crates()
end,
"update crates",
},
},
}
map("n", ";", ":", { desc = "CMD enter command mode" })
M.dap = {
plugin = true,
n = {
["<leader>db"] = { "<cmd> DapToggleBreakpoint <CR>" },
["<leader>dr"] = {
"<cmd> DapContinue <CR>",
"Run or continue the debugger",
},
["<leader>dus"] = {
function()
local widgets = require("dap.ui.widgets")
local sidebar = widgets.sidebar(widgets.scopes)
sidebar.open()
end,
"Open debugging sidebar",
},
["<leader>drr"] = {
"<cmd> RustLsp debuggables <CR>",
"Run rust debug on current file",
},
},
}
map("n", "<leader>fm", function()
require("conform").format()
end, { desc = "File Format with conform" })
M.dap_go = {
plugin = true,
n = {
["<leader>dgr"] = {
function()
require("dap-go").debug_test()
end,
"Debug go test",
},
["<leader>dgl"] = {
function()
require("dap-go").debug_last()
end,
"Debug last go test",
},
},
}
map("i", "jk", "<ESC>", { desc = "Escape insert mode" })
M.gopher = {
plugin = true,
n = {
["<leader>gsj"] = {
"<cmd> GoTagAdd json <CR>",
"Add json struct tags",
},
["<leader>gsy"] = {
"<cmd> GoTagAdd yaml <CR>",
"Add yaml struct tags",
},
},
}
M.lspsaga = {
n = {
["<C-.>"] = {
function()
vim.lsp.buf.code_action()
end,
"󰅱 Code Action",
},
--[[ ["gf"] = {
function()
vim.cmd "Lspsaga lsp_finder"
end,
" Go to definition",
},
["gt"] = {
"<CMD>Lspsaga goto_definition<CR>",
" Go to definition",
},
["<leader>lp"] = {
"<CMD>Lspsaga peek_definition<CR>",
" Peek definition",
}, ]]
["gh"] = {
function()
--[[ vim.lsp.buf.hover() ]]
require("pretty_hover").hover()
end,
"󱙼 Hover lsp",
},
["gr"] = { "<CMD>Telescope lsp_references<CR>", " Lsp references" },
["gd"] = { "<CMD>Telescope lsp_definitions <CR>", " Lsp definitions" },
},
}
M.rua = {
n = {
["<tab>"] = {
"<CMD> tabNext <CR>",
"Goto next tab",
},
["<S-tab>"] = {
"<CMD> tabprevious <CR>",
"Goto prev tab",
},
["<S-l>"] = {
function()
require("nvchad.tabufline").tabuflineNext()
end,
"Goto next buffer",
},
["<S-h>"] = {
function()
require("nvchad.tabufline").tabuflinePrev()
end,
"Goto prev buffer",
},
["<leader>pa"] = {
"<CMD> %bd|e#|bd# <CR>",
"Close all other buffers",
},
["<C-a>"] = { "gg<S-v>G" },
-- $ 跳到行尾不带空格
["$"] = { "g_" },
-- motion
["f"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = false })
end,
"Hop motion search in current line after cursor",
},
["F"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = false })
end,
"Hop motion search in current line before cursor",
},
["<leader>w"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_words({ direction = directions.AFTER_CURSOR, current_line_only = false })
end,
"Hop motion search words after cursor",
},
["<leader>b"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_words({ direction = directions.BEFORE_CURSOR, current_line_only = false })
end,
"Hop motion search words before cursor",
},
-- term
["<A-o>"] = {
function()
require("nvterm.terminal").toggle("horizontal")
end,
"Toggle horizontal term",
},
["<D-o>"] = {
function()
require("nvterm.terminal").toggle("horizontal")
end,
"Toggle horizontal term",
},
["<D-i>"] = {
function()
require("nvterm.terminal").toggle("float")
end,
"Toggle floating term",
},
["<A-u>"] = {
function()
require("nvterm.terminal").toggle("vertical")
end,
"Toggle vertical term",
},
["<D-u>"] = {
function()
require("nvterm.terminal").toggle("vertical")
end,
"Toggle vertical term",
},
-- arrange buffer
["<leader>pl"] = {
function()
require("nvchad.tabufline").move_buf(1)
end,
"Move buffer right",
},
["<leader>ph"] = {
function()
require("nvchad.tabufline").move_buf(-1)
end,
"Move buffer left",
},
-- notify
["<leader>un"] = {
function()
require("notify").dismiss({ silent = true, pending = true })
end,
"Dismiss all Notifications",
},
-- markdown preview
["<leader>pm"] = {
"<cmd> MarkdownPreview <CR>",
"Preview Markdown file",
},
-- window split
["<leader>|"] = {
"<cmd> vs <CR>",
"Split window vertically",
},
["<leader>_"] = {
"<cmd> sp <CR>",
"Split window horizontally",
},
-- spectre search
["<leader>ss"] = {
'<cmd>lua require("spectre").toggle()<CR>',
"Toggle Spectre",
},
["<leader>sw"] = {
'<cmd>lua require("spectre").open_visual({select_word=true})<CR>',
"Spectre search current word",
},
["<leader>sp"] = {
'<cmd>lua require("spectre").open_file_search({select_word=true})<CR>',
"Spectre search on current file",
},
},
v = {
["$"] = { "g_" },
-- motion
["f"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = false })
end,
"Hop motion search in current line after cursor",
},
["F"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = false })
end,
"Hop motion search in current line before cursor",
},
["<leader>w"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_words({ direction = directions.AFTER_CURSOR, current_line_only = false })
end,
"Hop motion search words after cursor",
},
["<leader>b"] = {
function()
local hop = require("hop")
local directions = require("hop.hint").HintDirection
hop.hint_words({ direction = directions.BEFORE_CURSOR, current_line_only = false })
end,
"Hop motion search words before cursor",
},
-- spectre search
["<leader>sw"] = {
'<esc><cmd>lua require("spectre").open_visual()<CR>',
"Spectre search current word",
},
},
-- term
t = {
["<A-o>"] = {
function()
require("nvterm.terminal").toggle("horizontal")
end,
"Toggle horizontal term",
},
["<D-o>"] = {
function()
require("nvterm.terminal").toggle("horizontal")
end,
"Toggle horizontal term",
},
["<D-i>"] = {
function()
require("nvterm.terminal").toggle("float")
end,
"Toggle floating term",
},
["<A-u>"] = {
function()
require("nvterm.terminal").toggle("vertical")
end,
"Toggle vertical term",
},
["<D-u>"] = {
function()
require("nvterm.terminal").toggle("vertical")
end,
"Toggle vertical term",
},
--[[ ["<Esc>"] = { vim.api.nvim_replace_termcodes("<C-\\><C-N>", true, true, true), "Escape terminal mode" }, ]]
},
}
M.trouble = {
n = {
["<leader>tx"] = { "<cmd>TroubleToggle<CR>" },
["<leader>tw"] = { "<cmd>TroubleToggle workspace_diagnostics<CR>" },
["<leader>td"] = { "<cmd>TroubleToggle document_diagnostics<CR>" },
["<leader>tq"] = { "<cmd>TroubleToggle quickfix<CR>" },
["<leader>tl"] = { "<cmd>TroubleToggle loclist<CR>" },
["gR"] = { "<cmd>TroubleToggle lsp_references<CR>" },
},
}
M.telescope = {
plugin = true,
n = {
["<leader>gm"] = { "<cmd> Telescope git_commits <CR>", "Git commits" },
["<leader>gd"] = { "<cmd> DiffviewOpen <CR>", "Open diff view" },
["<leader>gg"] = { "<cmd> LazyGit <CR>", "Open LazyGit" },
["<leader>gf"] = { "<cmd> LazyGitFilterCurrentFile <CR>", "Open LazyGit fitler current file" },
["<leader>gh"] = { "<cmd> DiffviewFileHistory % <CR>", "Open current file history" },
["<leader>gc"] = { "<cmd> DiffviewClose <CR>", "Close Diffview" },
["<leader>fc"] = {
function()
require("telescope.builtin").command_history()
end,
"Search command history",
},
["<leader>fr"] = {
function()
require("telescope.builtin").resume()
end,
"Resume last search",
},
["<leader>ft"] = {
function()
require("telescope.builtin").filetypes()
end,
"Set current filetype",
},
["<leader>fd"] = {
function()
require("telescope.builtin").diagnostics()
end,
"Find Diagnostics",
},
["<leader>fn"] = {
function()
require("telescope").extensions.notify.notify()
end,
"View notify history",
},
},
}
M.whichkey = {
plugin = true,
n = {
["<leader>K"] = {
function()
vim.cmd("WhichKey")
end,
"Which-key all keymaps",
},
["<leader>k"] = {
function()
local input = vim.fn.input("WhichKey: ")
vim.cmd("WhichKey " .. input)
end,
"Which-key query lookup",
},
},
}
M.lspconfig = {
plugin = true,
--[[ n = {
["<leader>ca"] = {
function()
vim.ui.select(vim.lsp.buf.code_action)
end,
"LSP code action",
},
}, ]]
n = {
["<leader>co"] = {
"<cmd> OrganizeImports <CR>",
"Organize imports",
},
},
}
return M

12
lua/myinit.lua Normal file
View File

@ -0,0 +1,12 @@
vim.fn.sign_define("DapBreakpoint", { text = "", numhl = "DapBreakpoint", texthl = "DapBreakpoint" })
vim.fn.sign_define("DagLogPoint", { text = "", numhl = "DapLogPoint", texthl = "DapLogPoint" })
vim.fn.sign_define("DapStopped", { text = "", numhl = "DapStopped", texthl = "DapStopped" })
vim.fn.sign_define(
"DapBreakpointRejected",
{ text = "", numhl = "DapBreakpointRejected", texthl = "DapBreakpointRejected" }
)
require "utils.autocmd"
require "utils.usercmd"
require "utils.options"
require "utils.neovide"

View File

@ -2,7 +2,7 @@ return {
{
"stevearc/conform.nvim",
config = function()
require "configs.conform"
require("configs.conform")
end,
},

479
lua/plugins/myplugins.lua Normal file
View File

@ -0,0 +1,479 @@
local cmp = require("cmp")
local overrides = require("configs.overrides")
local plugins = {
{
"NvChad/nvcommunity",
{ import = "nvcommunity.git.diffview" },
{ import = "nvcommunity.git.lazygit" },
{ import = "nvcommunity.lsp.prettyhover" },
},
-- LSP, formatter, linter
{
"neovim/nvim-lspconfig",
config = function()
require("configs.lspconfig")
require("nvchad.configs.lspconfig").defaults()
end,
},
{
"jay-babu/mason-nvim-dap.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("mason-nvim-dap").setup({
ensure_installed = {
"codelldb",
},
automatic_installation = true,
})
end,
},
{
"jay-babu/mason-null-ls.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("mason-null-ls").setup({
ensure_installed = {
"stylua",
"prettierd",
"ymlfmt",
"shellharden",
"shfmt",
"goimports",
"goimports-reviser",
"golines",
"gopls",
},
automatic_installation = true,
})
end,
},
{
"williamboman/mason-lspconfig.nvim",
opts = {
ensure_installed = {
"lua_ls",
"rust_analyzer",
"html",
"volar",
"tsserver",
"tailwindcss",
"eslint",
"cssls",
"cssmodules_ls",
"jsonls",
"yamlls",
"docker_compose_language_service",
"dockerls",
"bashls",
"clangd",
"lemminx",
},
automatic_installation = true,
},
config = function(_, opts)
require("mason-lspconfig").setup(opts)
end,
},
{
"williamboman/mason.nvim",
},
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
-- defaults
"vim",
"vimdoc",
"lua",
-- web dev
"html",
"css",
"javascript",
"typescript",
"tsx",
"json",
"vue",
"markdown",
"markdown_inline",
"jsdoc",
"scss",
-- low level
"rust",
"toml",
"go",
"gomod",
},
autotag = {
enable = true,
},
highlight = {
disable = function(_, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
},
},
},
{
"nvimtools/none-ls.nvim",
event = "VeryLazy",
opts = function()
return require("configs.null-ls")
end,
},
{
"hrsh7th/nvim-cmp",
dependencies = {
{ "roobert/tailwindcss-colorizer-cmp.nvim", config = true },
},
opts = function()
---@diagnostic disable-next-line: different-requires
local M = require("nvchad.configs.cmp")
M.completion.completeopt = "menu,menuone,noselect"
M.mapping["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
})
table.insert(M.sources, { name = "crates" })
-- original LazyVim kind icon formatter
local format_kinds = M.formatting.format
M.formatting.format = function(entry, item)
format_kinds(entry, item) -- add icons
return require("tailwindcss-colorizer-cmp").formatter(entry, item)
end
return M
end,
},
-- rust
{
"mrcjkb/rustaceanvim",
version = "^4", -- Recommended
ft = "rust",
config = function()
require("configs.rust")
end,
},
{
"saecki/crates.nvim",
ft = { "toml" },
config = function(_, opts)
local crates = require("crates")
crates.setup(opts)
require("cmp").setup.buffer({
sources = { { name = "crates" } },
})
crates.show()
require("core.utils").load_mappings("crates")
end,
},
{
"rust-lang/rust.vim",
ft = "rust",
init = function()
vim.g.rustfmt_autosave = 1
end,
},
-- golang
{
"olexsmir/gopher.nvim",
ft = "go",
config = function(_, opts)
require("gopher").setup(opts)
end,
build = function()
vim.cmd([[silent! GoInstallDeps]])
end,
},
{
"dreamsofcode-io/nvim-dap-go",
ft = "go",
dependencies = "mfussenegger/nvim-dap",
config = function(_, opts)
require("dap-go").setup(opts)
end,
},
{
"b0o/schemastore.nvim",
},
-- debug
{
"rcarriga/nvim-dap-ui",
event = "VeryLazy",
dependencies = "mfussenegger/nvim-dap",
config = function()
local dap = require("dap")
local dapui = require("dapui")
require("dapui").setup()
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
end,
},
{
"mfussenegger/nvim-dap",
config = function()
require("configs.dap")
--[[ require("nvchad.utils").load_mappings("dap") ]]
end,
},
{
"theHamsta/nvim-dap-virtual-text",
lazy = false,
config = function(_, opts)
require("nvim-dap-virtual-text").setup(opts)
end,
},
-- telescope, code action ui
{
"nvim-telescope/telescope.nvim",
opts = function()
require("configs.telescope")
end,
},
{
"nvim-telescope/telescope-ui-select.nvim",
},
{
"nvim-telescope/telescope-fzf-native.nvim",
build = "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build",
},
{
"nvim-pack/nvim-spectre",
event = "BufRead",
},
-- motion, UI and others
{
"phaazon/hop.nvim",
branch = "v2", -- optional but strongly recommended
config = function()
-- you can configure Hop the way you like here; see :h hop-config
local hop = require("hop")
hop.setup({ keys = "etovxqpdygfblzhckisuran" })
end,
},
{
"smoka7/multicursors.nvim",
event = "VeryLazy",
dependencies = {
"smoka7/hydra.nvim",
},
opts = {
hint_config = false,
},
cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" },
keys = {
{
mode = { "v", "n" },
"<Leader>m",
--[[ "<C-n>", ]]
"<cmd>MCstart<cr>",
desc = "Create a selection for selected text or word under the cursor",
},
},
},
{
"jxnblk/vim-mdx-js",
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = {},
},
{
"windwp/nvim-ts-autotag",
dependencies = "nvim-treesitter/nvim-treesitter",
config = function()
require("nvim-ts-autotag").setup({})
end,
lazy = true,
event = "VeryLazy",
},
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "VeryLazy",
config = function()
require("nvim-surround").setup({})
end,
},
-- comment string
{
"JoosepAlviste/nvim-ts-context-commentstring",
},
{
"numToStr/Comment.nvim",
opts = {
pre_hook = function(ctx)
local U = require("Comment.utils")
local location = nil
if ctx.ctype == U.ctype.block then
location = require("ts_context_commentstring.utils").get_cursor_location()
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
location = require("ts_context_commentstring.utils").get_visual_start_location()
end
return require("ts_context_commentstring.internal").calculate_commentstring({
key = ctx.ctype == U.ctype.line and "__default" or "__multiline",
location = location,
})
end,
},
},
-- term
{
"NvChad/nvterm",
config = function()
require("nvterm").setup({
terminals = {
type_opts = {
float = {
relative = "editor",
row = 0.1,
col = 0.1,
width = 0.8,
height = 0.8,
border = "rounded",
},
},
},
})
end,
},
-- ui
{
"rcarriga/nvim-notify",
opts = {
fps = 120,
render = "wrapped-compact",
stages = "slide",
top_down = false,
},
},
{
"folke/noice.nvim",
event = "VeryLazy",
dependencies = {
"MunifTanjim/nui.nvim",
"rcarriga/nvim-notify",
},
opts = {
lsp = {
message = {
enabled = true,
},
progress = {
enabled = false,
},
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
hover = {
enabled = false,
},
signature = {
enabled = false,
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = true, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = true, -- add a border to hover docs and signature help
},
},
},
{
"folke/trouble.nvim",
cmd = { "TroubleToggle", "Trouble", "TroubleRefresh" },
dependencies = { "nvim-tree/nvim-web-devicons" },
opts = {},
},
{
"NvChad/nvim-colorizer.lua",
opts = {
user_default_options = {
tailwind = true,
},
},
},
{
"folke/todo-comments.nvim",
event = "BufReadPost",
opts = {},
},
{
"chikko80/error-lens.nvim",
event = "BufRead",
dependencies = {
"nvim-telescope/telescope.nvim",
},
opts = {},
},
{
"RRethy/vim-illuminate",
event = "BufRead",
},
{
"iamcco/markdown-preview.nvim",
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" },
build = function()
vim.fn["mkdp#util#install"]()
end,
},
-- git
{
"sindrets/diffview.nvim",
opts = {
enhanced_diff_hl = true,
view = {
merge_tool = {
layout = "diff3_mixed",
disable_diagnostics = true,
},
},
keymaps = {
view = {
["<tab>"] = false,
},
file_panel = {
["<tab>"] = false,
},
file_history_panel = {
["<tab>"] = false,
},
option_panel = {
["<tab>"] = false,
},
},
},
},
--[[ overrides ]]
{
"nvim-tree/nvim-tree.lua",
opts = overrides.nvimtree,
},
}
return plugins

100
lua/utils/autocmd.lua Normal file
View File

@ -0,0 +1,100 @@
local autocmd = vim.api.nvim_create_autocmd
-- set markdown highlight for mdx file
autocmd({ "BufNewFile", "BufRead" }, {
pattern = { "*.mdx" },
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
end,
})
-- Disbale diagnostic for files in node_modules
autocmd({ "BufNewFile", "BufRead" }, {
pattern = { "**/node_modules/**", "node_modules", "/node_modules/*" },
callback = function()
vim.diagnostic.disable(0)
end,
})
autocmd("FileType", {
desc = "Close NvimTree before quit nvim",
pattern = { "NvimTree" },
callback = function(args)
autocmd("VimLeavePre", {
callback = function()
vim.api.nvim_buf_delete(args.buf, { force = true })
return true
end,
})
end,
})
autocmd("BufEnter", {
desc = "Close nvim if NvimTree is only running buffer",
command = [[if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif]],
})
-- Automatically update changed file in Vim
-- Triger `autoread` when files changes on disk
-- https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044
-- https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode
-- autocmd({ "FocusGained", "BufEnter", "CursorHold", "CursorHoldI" }, {
-- command = [[silent! if mode() != 'c' && !bufexists("[Command Line]") | checktime | endif]],
-- })
-- Notification after file change
-- https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread
autocmd("FileChangedShellPost", {
command = [[echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None]],
})
---- 用o换行不要延续注释
local myAutoGroup = vim.api.nvim_create_augroup("myAutoGroup", {
clear = true,
})
autocmd("BufEnter", {
group = myAutoGroup,
pattern = "*",
callback = function()
vim.opt.formatoptions = vim.opt.formatoptions
- "o" -- O and o, don't continue comments
+ "r" -- But do continue when pressing enter.
end,
})
-- Highlight on yank
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true })
autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = "*",
})
-- Remove all trailing whitespace on save
-- autocmd("BufWritePre", {
-- command = [[:%s/\s\+$//e]],
-- group = augroup("TrimWhiteSpaceGrp", { clear = true }),
--})
-- conform.nvim auto save
-- vim.api.nvim_create_autocmd("BufWritePre", {
-- pattern = "*",
-- callback = function(args)
-- require("conform").format { bufnr = args.buf }
-- end,
-- })
-- nvim-lint
-- require('lint').linters_by_ft = {
-- javascript = {"eslint"},
-- typescript = {"eslint"},
-- }
--
-- vim.api.nvim_create_autocmd({ "BufWritePost" }, {
-- callback = function()
-- require("lint").try_lint()
-- end,
-- })

42
lua/utils/neovide.lua Normal file
View File

@ -0,0 +1,42 @@
local opt = vim.opt
-- Helper function for transparency formatting
local alpha = function()
return string.format("%x", math.floor(255 * (vim.g.transparency or 0.8)))
end
if vim.g.neovide then
local function set_ime(args)
if args.event:match "Enter$" then
vim.g.neovide_input_ime = true
else
vim.g.neovide_input_ime = false
end
end
local ime_input = vim.api.nvim_create_augroup("ime_input", { clear = true })
vim.api.nvim_create_autocmd({ "InsertEnter", "InsertLeave" }, {
group = ime_input,
pattern = "*",
callback = set_ime,
})
vim.api.nvim_create_autocmd({ "CmdlineEnter", "CmdlineLeave" }, {
group = ime_input,
pattern = "[/\\?]",
callback = set_ime,
})
opt.guifont = "JetBrainsMono Nerd Font:h16"
-- g:neovide_transparency should be 0 if you want to unify transparency of content and title bar.
--[[ vim.g.neovide_transparency = 0 ]]
--[[ vim.g.transparency = 0.91 ]]
--[[ vim.g.neovide_background_color = "#0f1117" .. alpha() ]]
vim.g.neovide_floating_blur_amount_x = 2.0
vim.g.neovide_floating_blur_amount_y = 2.0
vim.g.neovide_hide_mouse_when_typing = true
vim.g.neovide_refresh_rate = 120
vim.g.neovide_confirm_quit = true
vim.g.neovide_input_macos_alt_is_meta = true
end

15
lua/utils/options.lua Normal file
View File

@ -0,0 +1,15 @@
local opt = vim.opt
vim.g.dap_virtual_text = true
vim.wo.relativenumber = true
vim.wo.wrap = false
-- opt.iskeyword:append("-")
opt.foldmethod = "expr"
opt.foldexpr = "nvim_treesitter#foldexpr()"
opt.foldlevel = 20
opt.ignorecase = true
opt.wildignore:append { "*/node_modules/*" }
opt.clipboard:append { "unnamedplus" }
opt.iskeyword:append "-"
opt.termguicolors = true -- True color support
opt.autoindent = true --- Good auto indent

184
lua/utils/styled.lua Normal file
View File

@ -0,0 +1,184 @@
local M = {}
local tbl = {}
function tbl.contains(_tbl, value)
for _, current in pairs(_tbl) do
if current == value then
return true
end
end
return false
end
function M.directives()
local function is_one_line(range)
return range[1] == range[3]
end
local function is_range_empty_or_invalid(range)
if range[3] < range[1] or (is_one_line(range) and range[4] <= range[2]) then
return true
end
return false
end
local function make_subranges_between_children_like(node, predicate)
local content = { { node:range() } }
for child in node:iter_children() do
if predicate(child) then
local child_range = { child:range() }
local last_content_range = content[#content]
local first_part = {
last_content_range[1],
last_content_range[2],
child_range[1],
child_range[2],
}
local second_part = {
child_range[3],
child_range[4],
last_content_range[3],
last_content_range[4],
}
if is_range_empty_or_invalid(first_part) then
if not is_range_empty_or_invalid(second_part) then
content[#content] = second_part
end
elseif is_range_empty_or_invalid(second_part) then
content[#content] = first_part
else
content[#content] = first_part
content[#content + 1] = second_part
end
end
end
return content
end
local directives = vim.treesitter.query.list_directives()
if not tbl.contains(directives, "inject_without_named_children!") then
vim.treesitter.query.add_directive("inject_without_named_children!", function(
match,
_, --[[ pattern ]]
_, --[[ bufnr ]]
predicate,
metadata
)
local node = match[predicate[2]]
metadata.content = make_subranges_between_children_like(node, function(child)
return child:named()
end)
end)
end
if not tbl.contains(directives, "inject_without_children!") then
vim.treesitter.query.add_directive("inject_without_children!", function(
match,
_, --[[ pattern ]]
_, --[[ bufnr ]]
predicate,
metadata
)
local node = match[predicate[2]]
metadata.content = make_subranges_between_children_like(node, function(_)
return true
end)
end)
end
end
M.ecma_injections = [[
(comment) @jsdoc
(comment) @comment
(regex_pattern) @regex
; =============================================================================
; languages
; {lang}`<{lang}>`
(call_expression
function: ((identifier) @language)
arguments: ((template_string) @content
(#offset! @content 0 1 0 -1)
(#inject_without_children! @content)))
; gql`<graphql>`
(call_expression
function: ((identifier) @_name
(#eq? @_name "gql"))
arguments: ((template_string) @graphql
(#offset! @graphql 0 1 0 -1)
(#inject_without_children! @graphql)))
; hbs`<glimmer>`
(call_expression
function: ((identifier) @_name
(#eq? @_name "hbs"))
arguments: ((template_string) @glimmer
(#offset! @glimmer 0 1 0 -1)
(#inject_without_children! @glimmer)))
; =============================================================================
; styled-components
; styled.div`<css>`
(call_expression
function: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))
arguments: ((template_string) @css
(#offset! @css 0 1 0 -1)
(#inject_without_children! @css)))
; styled(Component)`<css>`
(call_expression
function: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))
arguments: ((template_string) @css
(#offset! @css 0 1 0 -1)
(#inject_without_children! @css)))
; styled.div.attrs({ prop: "foo" })`<css>`
(call_expression
function: (call_expression
function: (member_expression
object: (member_expression
object: (identifier) @_name
(#eq? @_name "styled"))))
arguments: ((template_string) @css
(#offset! @css 0 1 0 -1)
(#inject_without_children! @css)))
; styled(Component).attrs({ prop: "foo" })`<css>`
(call_expression
function: (call_expression
function: (member_expression
object: (call_expression
function: (identifier) @_name
(#eq? @_name "styled"))))
arguments: ((template_string) @css
(#offset! @css 0 1 0 -1)
(#inject_without_children! @css)))
; createGlobalStyle`<css>`
(call_expression
function: (identifier) @_name
(#eq? @_name "createGlobalStyle")
arguments: ((template_string) @css
(#offset! @css 0 1 0 -1)
(#inject_without_children! @css)))
]]
function M.queries()
vim.treesitter.query.set("javascript", "injections", M.ecma_injections)
vim.treesitter.query.set("typescript", "injections", M.ecma_injections)
vim.treesitter.query.set("tsx", "injections", M.ecma_injections)
end
return M

13
lua/utils/usercmd.lua Normal file
View File

@ -0,0 +1,13 @@
local user_command = vim.api.nvim_create_user_command
-- Copy file path
user_command("Cppath", function()
local path = vim.fn.expand "%:p"
vim.fn.setreg("+", path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})
user_command("CpRelPath", function()
local path = vim.fn.expand "%"
vim.fn.setreg("+", path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})