update nvim config

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2026-05-30 05:35:11 +08:00
parent e345f703fe
commit fc3aafc2d1
3 changed files with 25 additions and 6 deletions

View File

@ -1078,6 +1078,7 @@ require('lazy').setup({
},
{ -- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
branch = 'master',
build = ':TSUpdate',
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`

View File

@ -75,9 +75,7 @@ return {
vim.api.nvim_create_autocmd('BufWritePre', {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format { async = false }
end,
callback = function() vim.lsp.buf.format { async = false } end,
})
end
end,

View File

@ -171,7 +171,23 @@ return {
request = 'launch',
program = function()
local cwd = vim.fn.getcwd()
local default_binary = cwd .. '/target/debug/' .. vim.fn.fnamemodify(cwd, ':t')
local cargo_toml = cwd .. '/Cargo.toml'
local binary_name = vim.fn.fnamemodify(cwd, ':t') -- Fallback to folder name
-- Read Cargo.toml to find the actual package name
if vim.fn.filereadable(cargo_toml) == 1 then
for _, line in ipairs(vim.fn.readfile(cargo_toml)) do
-- Look for name = "package_name" under the [package] table
local name = string.match(line, '^%s*name%s*=%s*["\']([^"\']+)["\']')
if name then
binary_name = name
break -- Stop reading once we find the name
end
end
end
local default_binary = cwd .. '/target/debug/' .. binary_name
return vim.fn.input('Path to executable: ', default_binary, 'file')
end,
cwd = '${workspaceFolder}',
@ -179,8 +195,12 @@ return {
},
}
-- Override default configurations with `launch.json`
require('dap.ext.vscode').load_launchjs('.nvim/launch.json', { lldb = { 'c', 'cpp', 'rust' } })
local vscode = require 'dap.ext.vscode'
-- 1. Define the adapter-to-filetype mappings
vscode.type_to_filetypes = {
lldb = { 'c', 'cpp', 'rust' },
}
vim.keymap.set('n', '<space>b', dap.toggle_breakpoint)
vim.keymap.set('n', '<space>gb', dap.run_to_cursor)