完善treesitter相关配置

This commit is contained in:
a770 2025-06-08 19:08:27 +08:00
parent d1f5f0a2c8
commit 6a883b41e9
12 changed files with 207 additions and 182 deletions

View file

@ -91,11 +91,11 @@ require("lazy").setup({
require("lazy.plugins.kittyscroll"),
-- 像cursor一样使用neovim
require("lazy.plugins.avante"),
-- 在浏览器中查看markdown preview
require("lazy.plugins.markdownpreview"),
-- mcp server插件
-- require("lazy.plugins.mcphub"),
-- 用于改进在 Neovim 中查看 Markdown 文件的插件
-- require("lazy.plugins.markview"),
-- require("lazy.plugins.render-markdown"),
-- 在浏览器中查看markdown preview
require("lazy.plugins.markdownpreview"),
})

View file

@ -13,51 +13,28 @@ return {
},
},
},
{ "williamboman/mason.nvim" },
{ "jay-babu/mason-nvim-dap.nvim" },
},
config = function()
vim.keymap.set("n", "<F5>", function()
require("dap").continue()
end)
vim.keymap.set("n", "<F10>", function()
require("dap").step_over()
end)
vim.keymap.set("n", "<F11>", function()
require("dap").step_into()
end)
vim.keymap.set("n", "<F12>", function()
require("dap").step_out()
end)
vim.keymap.set("n", "<Leader>b", function()
require("dap").toggle_breakpoint()
end)
vim.keymap.set("n", "<Leader>B", function()
require("dap").set_breakpoint()
end)
vim.keymap.set("n", "<Leader>lp", function()
local dap, dv = require("dap"), require("dap-view")
-- Keymappings for DAP
vim.keymap.set("n", "<leader>db", dap.toggle_breakpoint, { desc = "DAP: Toggle Breakpoint" })
vim.keymap.set("n", "<leader>dc", dap.continue, { desc = "DAP: Continue" })
vim.keymap.set("n", "<leader>do", dap.step_over, { desc = "DAP: Step Over" })
vim.keymap.set("n", "<leader>di", dap.step_into, { desc = "DAP: Step Into" })
vim.keymap.set("n", "<leader>du", dap.step_out, { desc = "DAP: Step Out" })
vim.keymap.set("n", "<leader>dr", dap.repl.open, { desc = "DAP: Open REPL" })
vim.keymap.set("n", "<leader>dt", dap.terminate, { desc = "DAP: Terminate" })
vim.keymap.set("n", "<leader>dl", function()
require("dap").run_last()
end, { desc = "DAP: Run Last" })
vim.keymap.set("n", "<Leader>dp", function()
require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: "))
end)
vim.keymap.set("n", "<Leader>dr", function()
require("dap").repl.open()
end)
vim.keymap.set("n", "<Leader>dl", function()
require("dap").run_last()
end)
vim.keymap.set({ "n", "v" }, "<Leader>dh", function()
require("dap.ui.widgets").hover()
end)
vim.keymap.set({ "n", "v" }, "<Leader>dp", function()
require("dap.ui.widgets").preview()
end)
vim.keymap.set("n", "<Leader>df", function()
local widgets = require("dap.ui.widgets")
widgets.centered_float(widgets.frames)
end)
vim.keymap.set("n", "<Leader>ds", function()
local widgets = require("dap.ui.widgets")
widgets.centered_float(widgets.scopes)
end)
-- 自动切换和关闭
local dap, dv = require("dap"), require("dap-view")
dap.listeners.before.attach["dap-view-config"] = function()
dv.open()
end
@ -79,47 +56,45 @@ return {
})
-- 如果没有窗口包含缓冲区,请创建一个新选项卡
dap.defaults.fallback.switchbuf = "usevisible,usetab,newtab"
dap.adapters.gdb = {
type = "executable",
command = "gdb",
args = { "--interpreter=dap", "--eval-command", "set print pretty on" },
}
dap.configurations.c = {
dap.configurations.rust = {
{
name = "Launch",
type = "gdb",
name = "Launch Rust Program (GDB)",
type = "cppdbg", -- Use the cpptools adapter
request = "launch",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
stopAtBeginningOfMainSubprogram = false,
},
{
name = "Select and attach to process",
type = "gdb",
request = "attach",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
pid = function()
local name = vim.fn.input("Executable name (filter): ")
return require("dap.utils").pick_process({ filter = name })
end,
cwd = "${workspaceFolder}",
},
{
name = "Attach to gdbserver :1234",
type = "gdb",
request = "attach",
target = "localhost:1234",
program = function()
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
-- Ask for the executable path when launching
return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/target/debug/", "file")
end,
cwd = "${workspaceFolder}",
stopAtEntry = false,
MIMode = "gdb", -- Specify GDB
miDebuggerPath = "gdb", -- Or full path to gdb if not in PATH
-- setupCommands are executed at the beginning of the GDB session
setupCommands = {
{
text = "-enable-pretty-printing",
description = "Enable GDB pretty printing",
ignoreFailures = false,
},
-- You might need to find the exact path to rust-gdb on your system
-- It's usually in `~/.rustup/toolchains/<your-toolchain>/lib/rustlib/src/rust/etc/rust-gdb`
-- Or system-wide if rustc was installed differently.
-- Example: (ADJUST THIS PATH!)
-- {
-- text = "source ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/etc/rust-gdb",
-- description = "Load Rust GDB extensions",
-- ignoreFailures = true -- Set to true if the path might not always be valid
-- }
},
-- If you want to pass arguments to your program:
-- args = {"arg1", "arg2"},
},
-- You can add more configurations, e.g., for attaching to a running process
}
dap.configurations.cpp = dap.configurations.c
dap.configurations.rust = dap.configurations.c
require("mason-nvim-dap").setup({
ensure_installed = { "cpptools" },
handlers = {}, -- sets up dap in the predefined manner
})
end,
}

View file

@ -3,13 +3,27 @@ vim.o.foldcolumn = "0" -- '0' is not bad,其他的会有奇怪的数字
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true
-- 设置可折叠处的样式
vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
return {
"kevinhwang91/nvim-ufo",
dependencies = "kevinhwang91/promise-async",
config = function()
-- Option 2: nvim lsp as LSP client
-- Tell the server the capability of foldingRange,
-- Neovim hasn't added foldingRange to default capabilities, users must add it manually
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
}
local language_servers = vim.lsp.get_clients() -- or list servers manually like {'gopls', 'clangd'}
for _, ls in ipairs(language_servers) do
require("lspconfig")[ls].setup({
capabilities = capabilities,
-- you can add other fields for setting up lsp server in this table
})
end
require("ufo").setup()
-- Option 3: treesitter as a main provider instead
-- Only depend on `nvim-treesitter/queries/filetype/folds.scm`,
-- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()`
@ -19,9 +33,7 @@ return {
end,
})
-- 键盘映射,这里的按键会打开或折叠全部的可折叠位置
vim.keymap.set("n", "zR", require("ufo").openAllFolds)
vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds)
vim.keymap.set("n", "zm", require("ufo").closeFoldsWith) -- closeAllFolds == closeFoldsWith(0)
vim.keymap.set("n", "zr", require("ufo").openAllFolds)
vim.keymap.set("n", "zm", require("ufo").closeAllFolds)
end,
}

View file

@ -1,5 +1,6 @@
return {
"Eandrju/cellular-automaton.nvim",
event = "VeryLazy",
keys = "<leader>rr",
config = function()
vim.keymap.set("n", "<leader>rr", "<cmd>CellularAutomaton make_it_rain<CR>")

View file

@ -5,8 +5,8 @@ return {
config = function()
require("peek").setup({
port = 9000,
-- app = { "firefox-esr", "-private-window" },
app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" },
app = { "firefox-esr", "-private-window" },
-- app = { "google-chrome-stable", "--app=http://localhost:9000/?theme=dark", "--incognito" },
})
vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {})
vim.api.nvim_create_user_command("PeekClose", require("peek").close, {})

View file

@ -1,31 +1,54 @@
-- ===
-- === outlines,大纲,函数变量结构
-- ===
local map = require("core.keymap")
-- 空格+v打开大纲,N全部收起,n收起当前节点,r重命名,I展开全部节点,i展开当前节点
map:cmd('<space>v', 'SymbolsOutline')
return {
'simrat39/symbols-outline.nvim',
enabled = not vim.g.vscode,
config = function()
require("symbols-outline").setup {
"hedyhli/outline.nvim",
lazy = true,
cmd = { "Outline", "OutlineOpen" },
keys = { -- Example mapping to toggle outline
{ "<leader>v", "<cmd>Outline<CR>", desc = "Toggle outline" },
},
opts = {
outline_window = {
position = "left",
width = 20,
keymaps = { -- These keymaps can be a string or a table for multiple keys
close = {"<Esc>", "q"},
goto_location = "<Cr>",
focus_location = "o",
hover_symbol = "<C-space>",
toggle_preview = "K",
rename_symbol = "r",
code_actions = "a",
fold = "n",
unfold = "i",
fold_all = "N",
unfold_all = "I",
fold_reset = "R",
}
}
end
},
keymaps = {
show_help = "?",
close = { "<Esc>", "q" },
-- Jump to symbol under cursor.
-- It can auto close the outline window when triggered, see
-- 'auto_close' option above.
goto_location = "<Cr>",
-- Jump to symbol under cursor but keep focus on outline window.
peek_location = "o",
-- Visit location in code and close outline immediately
goto_and_close = "<S-Cr>",
-- Change cursor position of outline window to match current location in code.
-- 'Opposite' of goto/peek_location.
restore_location = "<C-g>",
-- Open LSP/provider-dependent symbol hover information
hover_symbol = "<C-space>",
-- Preview location code of the symbol under cursor
toggle_preview = "K",
rename_symbol = "r",
code_actions = "a",
-- These fold actions are collapsing tree nodes, not code folding
fold = "n",
unfold = "i",
fold_toggle = "<Tab>",
-- Toggle folds for all nodes.
-- If at least one node is folded, this action will fold all nodes.
-- If all nodes are folded, this action will unfold all nodes.
fold_toggle_all = "<S-Tab>",
fold_all = "N",
unfold_all = "I",
fold_reset = "R",
-- Move down/up by one line and peek_location immediately.
-- You can also use outline_window.auto_jump=true to do this for any
-- j/k/<down>/<up>.
down_and_jump = "<C-e>",
up_and_jump = "<C-u>",
},
},
}

View file

@ -1,24 +1,24 @@
return {
"nvim-treesitter/nvim-treesitter-context",
config = function()
-- 前往上下文开始处winbar相同快捷键更细致
-- vim.keymap.set("n", "[c", function()
-- require("treesitter-context").go_to_context(vim.v.count1)
-- end, { silent = true })
require'treesitter-context'.setup{
-- 前往上下文开始处winbar可以做到更细致
vim.keymap.set("n", "[C", function()
require("treesitter-context").go_to_context(vim.v.count1)
end, { silent = true })
require("treesitter-context").setup({
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
multiwindow = true, -- Enable multiwindow support.
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
trim_scope = "outer", -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = "cursor", -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
zindex = 20, -- The Z-index of the context window
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
}
end
})
end,
}

View file

@ -3,38 +3,48 @@
-- ===
return {
'nvim-treesitter/nvim-treesitter',
"nvim-treesitter/nvim-treesitter",
config = function()
-- 要安装高亮的语言直接加入括号即可把sync_install设置为true下次进入vim自动安装语言列表查看treesitter的github
-- 或者执行:TSInstall <language_to_install>
local language = {
"python",
"lua",
"dart",
"markdown",
"go",
"bash",
"java",
"sql",
}
require("nvim-treesitter.configs").setup {
-- A list of parser names, or "all"
ensure_installed = language,
-- Install parsers synchronously (only applied to `ensure_installed`)
require("nvim-treesitter.configs").setup({
-- 要安装高亮的语言直接加入括号即可把sync_install设置为true下次进入vim自动安装
-- 或者手动执行:TSInstall <想要安装的语言>
-- 语言列表查看https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#supported-languages
ensure_installed = {
"json",
"rust",
"python",
"lua",
"markdown",
"bash",
"java",
-- "dart",
-- "go",
-- "sql",
},
-- 设置为true后位于ensure_installed里面的语言会自动安装
sync_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = {},
-- 这里填写不想要自动安装的语言
ignore_install = {
},
highlight = {
-- 默认开启高亮
enable = true,
-- list of language that will be disabled
disable = {},
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
-- 想要禁用高亮的语言列表
-- disable = {
-- },
-- 使用function以提高灵活性禁用大型文件的高亮
disable = function(lang, 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,
-- 如果您依靠启用'语法'(例如,缩进),则将其设置为“ True”。
-- 使用此选项可能会放慢编辑器,您可能会看到一些重复的高亮。
-- 除了设置为true它也可以设置成语言列表
additional_vim_regex_highlighting = false,
},
}
end
})
end,
}

View file

@ -2,9 +2,9 @@ return {
"Bekaboo/dropbar.nvim",
config = function()
local api = require("dropbar.api")
vim.keymap.set('n', '<Leader>;', api.pick)
vim.keymap.set('n', '[c', api.goto_context_start)
vim.keymap.set('n', ']c', api.select_next_context)
vim.keymap.set("n", "<Leader>;", api.pick)
vim.keymap.set("n", "[c", api.goto_context_start)
vim.keymap.set("n", "]c", api.select_next_context)
local confirm = function()
local menu = api.get_current_dropbar_menu()
@ -18,12 +18,12 @@ return {
end
end
local quit_curr = function()
local menu = api.get_current_dropbar_menu()
if menu then
menu:close()
end
end
-- local quit_curr = function()
-- local menu = api.get_current_dropbar_menu()
-- if menu then
-- menu:close()
-- end
-- end
require("dropbar").setup({
menu = {
@ -32,7 +32,7 @@ return {
quick_navigation = true,
---@type table<string, string|function|table<string, string|function>>
keymaps = {
['<LeftMouse>'] = function()
["<LeftMouse>"] = function()
local menu = api.get_current_dropbar_menu()
if not menu then
return
@ -48,14 +48,15 @@ return {
end
return
end
menu:click_at({ mouse.line, mouse.column }, nil, 1, 'l')
menu:click_at({ mouse.line, mouse.column }, nil, 1, "l")
end,
['<CR>'] = confirm,
['i'] = confirm,
['<esc>'] = quit_curr,
['q'] = quit_curr,
['n'] = quit_curr,
['<MouseMove>'] = function()
["<CR>"] = confirm,
["i"] = confirm,
["<esc>"] = "<C-w>q",
-- ['q'] = quit_curr,
["q"] = "<C-w>q",
["n"] = "<C-w>q",
["<MouseMove>"] = function()
local menu = api.get_current_dropbar_menu()
if not menu then
return
@ -69,5 +70,5 @@ return {
},
},
})
end
end,
}