mirror of
https://github.com/cap153/nvim.git
synced 2025-12-28 12:54:56 +08:00
完善treesitter相关配置
This commit is contained in:
parent
d1f5f0a2c8
commit
6a883b41e9
12 changed files with 207 additions and 182 deletions
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue