mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 06:21:13 +01:00
Update: Restructured plugin folders
This commit is contained in:
172
lua/plugins/custom/filetree.lua
Normal file
172
lua/plugins/custom/filetree.lua
Normal file
@@ -0,0 +1,172 @@
|
||||
-- Unless you are still migrating, remove the deprecated commands from v1.x
|
||||
vim.cmd [[ let g:neo_tree_remove_legacy_commands = 1 ]]
|
||||
|
||||
return {
|
||||
'nvim-neo-tree/neo-tree.nvim',
|
||||
version = '*',
|
||||
dependencies = {
|
||||
'nvim-lua/plenary.nvim',
|
||||
'nvim-tree/nvim-web-devicons',
|
||||
'MunifTanjim/nui.nvim',
|
||||
},
|
||||
config = function()
|
||||
local function smart_open(state)
|
||||
local node = state.tree:get_node()
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
local path = node:get_id()
|
||||
-- If the node is a directory, just toggle expand/collapse
|
||||
if node.type == 'directory' then
|
||||
state.commands.toggle_node(state, node)
|
||||
return
|
||||
end
|
||||
-- --- File handling starts here ---
|
||||
-- Reuse already open buffer in any tab safely
|
||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||
if vim.api.nvim_tabpage_is_valid(tab) then
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then
|
||||
vim.api.nvim_set_current_tabpage(tab)
|
||||
vim.api.nvim_set_current_win(win)
|
||||
-- close Neo-tree if open
|
||||
for _, w in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_is_valid(w) then
|
||||
local b = vim.api.nvim_win_get_buf(w)
|
||||
if vim.api.nvim_buf_is_valid(b) and vim.api.nvim_buf_get_option(b, 'filetype') == 'neo-tree' then
|
||||
vim.api.nvim_win_close(w, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Reuse empty buffer in current tab
|
||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||
local empty_buf = nil
|
||||
for _, win in ipairs(wins) do
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_is_valid(buf) then
|
||||
local bufname = vim.api.nvim_buf_get_name(buf)
|
||||
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
|
||||
local modified = vim.api.nvim_buf_get_option(buf, 'modified')
|
||||
if bufname == '' and buftype == '' and not modified then
|
||||
empty_buf = buf
|
||||
vim.api.nvim_set_current_win(win)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if empty_buf then
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||
else
|
||||
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
||||
end
|
||||
-- Always close Neo-tree window if open
|
||||
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
||||
if vim.api.nvim_win_is_valid(win) then
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_option(buf, 'filetype') == 'neo-tree' then
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Smart_open_split for split windows
|
||||
local function smart_open_split(state, direction)
|
||||
local node = state.tree:get_node()
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
local path = node:get_id()
|
||||
|
||||
if node.type == 'directory' then
|
||||
state.commands.toggle_node(state, node)
|
||||
return
|
||||
end
|
||||
-- Check if file is open in another tab
|
||||
local open_tab, open_win
|
||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then
|
||||
open_tab = tab
|
||||
open_win = win
|
||||
break
|
||||
end
|
||||
end
|
||||
if open_tab then
|
||||
break
|
||||
end
|
||||
end
|
||||
if open_tab then
|
||||
local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2)
|
||||
if choice ~= 1 then
|
||||
-- User chose No → jump to the tab where file is open
|
||||
vim.api.nvim_set_current_tabpage(open_tab)
|
||||
vim.api.nvim_set_current_win(open_win)
|
||||
return
|
||||
end
|
||||
-- Else user chose Yes → continue to open split in current tab
|
||||
end
|
||||
-- Open split in current tab
|
||||
if direction == 'v' then
|
||||
state.commands.open_vsplit(state)
|
||||
vim.schedule(function()
|
||||
vim.cmd 'wincmd L'
|
||||
end)
|
||||
else
|
||||
state.commands.open_split(state)
|
||||
vim.schedule(function()
|
||||
vim.cmd 'wincmd J'
|
||||
end)
|
||||
end
|
||||
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||
end
|
||||
require('neo-tree').setup {
|
||||
close_if_last_window = true,
|
||||
popup_border_style = 'rounded',
|
||||
enable_git_status = true,
|
||||
enable_diagnostics = true,
|
||||
default_component_configs = {
|
||||
indent = { padding = 1, indent_size = 2 },
|
||||
icon = { folder_closed = '', folder_open = '', folder_empty = 'ﰊ' },
|
||||
},
|
||||
window = {
|
||||
position = 'float',
|
||||
width = 40,
|
||||
mapping_options = { noremap = true, nowait = true },
|
||||
mappings = {
|
||||
['<cr>'] = smart_open,
|
||||
['v'] = function(state)
|
||||
smart_open_split(state, 'h')
|
||||
end,
|
||||
['h'] = function(state)
|
||||
smart_open_split(state, 'v')
|
||||
end,
|
||||
['t'] = 'noop',
|
||||
},
|
||||
},
|
||||
filesystem = {
|
||||
follow_current_file = {
|
||||
enabled = true, -- updated to table format
|
||||
},
|
||||
use_libuv_file_watcher = true,
|
||||
hijack_netrw_behavior = 'open_default',
|
||||
filtered_items = {
|
||||
visible = true,
|
||||
hide_dotfiles = false,
|
||||
hide_gitignored = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
end,
|
||||
}
|
||||
281
lua/plugins/custom/telescope.lua
Normal file
281
lua/plugins/custom/telescope.lua
Normal file
@@ -0,0 +1,281 @@
|
||||
return {
|
||||
-- Fuzzy Finder (files, lsp, etc)
|
||||
'nvim-telescope/telescope.nvim',
|
||||
branch = '0.1.x',
|
||||
dependencies = {
|
||||
'nvim-lua/plenary.nvim',
|
||||
-- Fuzzy Finder Algorithm which requires local dependencies to be built.
|
||||
-- Only load if `make` is available. Make sure you have the system
|
||||
-- requirements installed.
|
||||
{
|
||||
'nvim-telescope/telescope-fzf-native.nvim',
|
||||
-- NOTE: If you are having trouble with this installation,
|
||||
-- refer to the README for telescope-fzf-native for more instructions.
|
||||
build = 'make',
|
||||
cond = function()
|
||||
return vim.fn.executable 'make' == 1
|
||||
end,
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
-- [[ Configure Telescope ]]
|
||||
-- See `:help telescope` and `:help telescope.setup()`
|
||||
require('telescope').setup {
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
['<C-u>'] = false,
|
||||
['<C-d>'] = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
-- Enable telescope fzf native, if installed
|
||||
pcall(require('telescope').load_extension, 'fzf')
|
||||
|
||||
-- smart_open function for Telescope to check if the current tab has an empty "No Name" buffer. If it has, it replaces the empty buffer and open a file in the same tab
|
||||
local actions = require 'telescope.actions'
|
||||
local action_state = require 'telescope.actions.state'
|
||||
local function smart_open(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry()
|
||||
if not entry then
|
||||
return
|
||||
end
|
||||
local path = entry.path or entry.filename
|
||||
if not path then
|
||||
return
|
||||
end
|
||||
if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then
|
||||
pcall(actions.close, prompt_bufnr)
|
||||
end
|
||||
-- 1. If file is already open → jump to it
|
||||
local tabpages = vim.api.nvim_list_tabpages()
|
||||
for _, tab in ipairs(tabpages) do
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_get_name(buf) == path then
|
||||
vim.api.nvim_set_current_tabpage(tab) -- jump to tab
|
||||
vim.api.nvim_set_current_win(win) -- jump to window
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
-- 2. If current tab has an empty "No Name" buffer → reuse it
|
||||
local wins = vim.api.nvim_tabpage_list_wins(0)
|
||||
for _, win in ipairs(wins) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
local name = vim.api.nvim_buf_get_name(buf)
|
||||
local buftype = vim.api.nvim_buf_get_option(buf, 'buftype')
|
||||
local modified = vim.api.nvim_buf_get_option(buf, 'modified')
|
||||
if name == '' and buftype == '' and not modified then
|
||||
vim.api.nvim_set_current_win(win)
|
||||
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||
return
|
||||
end
|
||||
end
|
||||
-- 3. Otherwise → open in a new tab
|
||||
vim.cmd('tabnew ' .. vim.fn.fnameescape(path))
|
||||
end
|
||||
-- Split option in Telescope file picker with smart_open
|
||||
local actions = require 'telescope.actions'
|
||||
local action_state = require 'telescope.actions.state'
|
||||
local function smart_open_split(prompt_bufnr, split_type)
|
||||
local entry = action_state.get_selected_entry()
|
||||
if not entry then
|
||||
return
|
||||
end
|
||||
local path = entry.path or entry.filename
|
||||
if not path then
|
||||
return
|
||||
end
|
||||
if prompt_bufnr and vim.api.nvim_buf_is_valid(prompt_bufnr) then
|
||||
pcall(actions.close, prompt_bufnr)
|
||||
end
|
||||
-- Check if file is already open
|
||||
local open_tab, open_win
|
||||
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
if vim.api.nvim_buf_get_name(buf) == path then
|
||||
open_tab = tab
|
||||
open_win = win
|
||||
break
|
||||
end
|
||||
end
|
||||
if open_tab then
|
||||
break
|
||||
end
|
||||
end
|
||||
if open_tab then
|
||||
local choice = vim.fn.confirm('File is already open in a tab. Open split here anyway?', '&Yes\n&No', 2)
|
||||
if choice ~= 1 then
|
||||
-- User chose No → jump to the tab where file is open
|
||||
vim.api.nvim_set_current_tabpage(open_tab)
|
||||
vim.api.nvim_set_current_win(open_win)
|
||||
return
|
||||
end
|
||||
-- Else user chose Yes → continue to open split in current tab
|
||||
end
|
||||
-- Open in split
|
||||
if split_type == 'v' then
|
||||
-- horizontal → always below
|
||||
vim.cmd('belowright split ' .. vim.fn.fnameescape(path))
|
||||
elseif split_type == 'h' then
|
||||
-- vertical → always right
|
||||
vim.cmd('vertical rightbelow split ' .. vim.fn.fnameescape(path))
|
||||
end
|
||||
end
|
||||
-- Telescope keymaps for using Smart Open
|
||||
-- <leader>sf for find files
|
||||
vim.keymap.set('n', '<leader>sf', function()
|
||||
require('telescope.builtin').find_files {
|
||||
attach_mappings = function(_, map)
|
||||
map('n', 'q', actions.close)
|
||||
map('i', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
map('n', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
-- Horizontal split with 'h'
|
||||
map('n', 'h', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'h')
|
||||
end)
|
||||
-- Vertical split with 'v'
|
||||
map('n', 'v', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'v')
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end, { desc = '[S]earch [F]iles' })
|
||||
-- <leader>? for old files
|
||||
vim.keymap.set('n', '<leader>?', function()
|
||||
require('telescope.builtin').oldfiles {
|
||||
attach_mappings = function(_, map)
|
||||
map('n', 'q', actions.close)
|
||||
map('i', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
map('n', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
-- Horizontal split with 'h'
|
||||
map('n', 'h', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'h')
|
||||
end)
|
||||
-- Vertical split with 'v'
|
||||
map('n', 'v', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'v')
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end, { desc = '[?] Find recently opened files' })
|
||||
-- Current buffers for Telescope (switch to already open buffer)
|
||||
vim.keymap.set('n', '<leader><leader>', function()
|
||||
require('telescope.builtin').buffers {
|
||||
attach_mappings = function(_, map)
|
||||
map('n', 'q', actions.close)
|
||||
map('i', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
map('n', '<CR>', function(prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end)
|
||||
map('n', 'h', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'h')
|
||||
end)
|
||||
map('n', 'v', function(prompt_bufnr)
|
||||
smart_open_split(prompt_bufnr, 'v')
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end, { desc = 'Switch to Open Buffers' })
|
||||
-- Telescope live_grep in git root
|
||||
-- Function to find the git root directory based on the current buffer's path
|
||||
local function find_git_root()
|
||||
-- Use the current buffer's path as the starting point for the git search
|
||||
local current_file = vim.api.nvim_buf_get_name(0)
|
||||
local current_dir
|
||||
local cwd = vim.fn.getcwd()
|
||||
-- If the buffer is not associated with a file, return nil
|
||||
if current_file == '' then
|
||||
current_dir = cwd
|
||||
else
|
||||
-- Extract the directory from the current file's path
|
||||
current_dir = vim.fn.fnamemodify(current_file, ':h')
|
||||
end
|
||||
-- Find the Git root directory from the current file's path
|
||||
local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1]
|
||||
if vim.v.shell_error ~= 0 then
|
||||
print 'Not a git repository. Searching on current working directory'
|
||||
return cwd
|
||||
end
|
||||
return git_root
|
||||
end
|
||||
-- Custom live_grep function to search in git root
|
||||
local function live_grep_git_root()
|
||||
local git_root = find_git_root()
|
||||
if git_root then
|
||||
require('telescope.builtin').live_grep {
|
||||
search_dirs = { git_root },
|
||||
}
|
||||
end
|
||||
end
|
||||
vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {})
|
||||
-- See `:help telescope.builtin`
|
||||
vim.keymap.set('n', '<leader>/', function()
|
||||
-- You can pass additional configuration to telescope to change theme, layout, etc.
|
||||
require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
|
||||
winblend = 10,
|
||||
previewer = false,
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
map('n', 'q', actions.close)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
end, { desc = '[/] Fuzzily search in current buffer' })
|
||||
local function telescope_live_grep_open_files()
|
||||
require('telescope.builtin').live_grep {
|
||||
grep_open_files = true,
|
||||
prompt_title = 'Live Grep in Open Files',
|
||||
}
|
||||
end
|
||||
vim.keymap.set('n', '<leader>s/', telescope_live_grep_open_files, { desc = '[S]earch [/] in Open Files' })
|
||||
vim.keymap.set('n', '<leader>ss', require('telescope.builtin').builtin, { desc = '[S]earch [S]elect Telescope' })
|
||||
vim.keymap.set('n', '<leader>gf', function()
|
||||
local is_git_dir = vim.fn.system('git rev-parse --is-inside-work-tree'):gsub('%s+', '') == 'true'
|
||||
if not is_git_dir then
|
||||
vim.notify('Not a git repository', vim.log.levels.WARN, { title = 'Telescope Git Files' })
|
||||
return
|
||||
end
|
||||
require('telescope.builtin').git_files {
|
||||
attach_mappings = function(_, map)
|
||||
map('n', 'q', actions.close)
|
||||
local actions = require 'telescope.actions'
|
||||
local action_state = require 'telescope.actions.state'
|
||||
|
||||
local function open_smart(prompt_bufnr)
|
||||
local entry = action_state.get_selected_entry()
|
||||
if not entry then
|
||||
return
|
||||
end
|
||||
pcall(actions.close, prompt_bufnr)
|
||||
smart_open(prompt_bufnr)
|
||||
end
|
||||
map('i', '<CR>', open_smart)
|
||||
map('n', '<CR>', open_smart)
|
||||
return true
|
||||
end,
|
||||
}
|
||||
end, { desc = 'Search [G]it [F]iles' })
|
||||
vim.keymap.set('n', '<leader>si', require('telescope.builtin').help_tags, { desc = '[S]earch [I]nfo' })
|
||||
vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
|
||||
vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
|
||||
vim.keymap.set('n', '<leader>sG', ':LiveGrepGitRoot<cr>', { desc = '[S]earch by [G]rep on Git Root' })
|
||||
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
|
||||
vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' })
|
||||
end,
|
||||
}
|
||||
14
lua/plugins/custom/undotree.lua
Normal file
14
lua/plugins/custom/undotree.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
-- lua/custom/plugins/undotree.lua
|
||||
return {
|
||||
'mbbill/undotree',
|
||||
keys = {
|
||||
{ '<leader>u', vim.cmd.UndotreeToggle, desc = 'Toggle UndoTree' },
|
||||
},
|
||||
config = function()
|
||||
-- Optional settings
|
||||
vim.g.undotree_WindowLayout = 2 -- vertical split
|
||||
vim.g.undotree_SplitWidth = 30 -- width of undo tree window
|
||||
vim.g.undotree_SetFocusWhenToggle = 1
|
||||
vim.g.undotree_EnableDiff = 1
|
||||
end,
|
||||
}
|
||||
79
lua/plugins/kickstart/autoformat.lua
Normal file
79
lua/plugins/kickstart/autoformat.lua
Normal file
@@ -0,0 +1,79 @@
|
||||
-- autoformat.lua
|
||||
--
|
||||
-- Use your language server to automatically format your code on save.
|
||||
-- Adds additional commands as well to manage the behavior
|
||||
|
||||
return {
|
||||
'neovim/nvim-lspconfig',
|
||||
config = function()
|
||||
-- Skip setting up LSP autoformatting if conform.nvim is being used
|
||||
if package.loaded['conform'] then
|
||||
return
|
||||
end
|
||||
|
||||
-- Switch for controlling whether you want autoformatting.
|
||||
-- Use :KickstartFormatToggle to toggle autoformatting on or off
|
||||
local format_is_enabled = true
|
||||
vim.api.nvim_create_user_command('KickstartFormatToggle', function()
|
||||
format_is_enabled = not format_is_enabled
|
||||
print('Setting autoformatting to: ' .. tostring(format_is_enabled))
|
||||
end, {})
|
||||
|
||||
-- Create an augroup that is used for managing our formatting autocmds.
|
||||
-- We need one augroup per client to make sure that multiple clients
|
||||
-- can attach to the same buffer without interfering with each other.
|
||||
local _augroups = {}
|
||||
local get_augroup = function(client)
|
||||
if not _augroups[client.id] then
|
||||
local group_name = 'kickstart-lsp-format-' .. client.name
|
||||
local id = vim.api.nvim_create_augroup(group_name, { clear = true })
|
||||
_augroups[client.id] = id
|
||||
end
|
||||
|
||||
return _augroups[client.id]
|
||||
end
|
||||
|
||||
-- Whenever an LSP attaches to a buffer, we will run this function.
|
||||
--
|
||||
-- See `:help LspAttach` for more information about this autocmd event.
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-format', { clear = true }),
|
||||
-- This is where we attach the autoformatting for reasonable clients
|
||||
callback = function(args)
|
||||
local client_id = args.data.client_id
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
local bufnr = args.buf
|
||||
|
||||
-- Only attach to clients that support document formatting
|
||||
if not client.server_capabilities.documentFormattingProvider then
|
||||
return
|
||||
end
|
||||
|
||||
-- Tsserver usually works poorly. Sorry you work with bad languages
|
||||
-- You can remove this line if you know what you're doing :)
|
||||
if client.name == 'tsserver' then
|
||||
return
|
||||
end
|
||||
|
||||
-- Create an autocmd that will run *before* we save the buffer.
|
||||
-- Run the formatting command for the LSP that has just attached.
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
group = get_augroup(client),
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
if not format_is_enabled then
|
||||
return
|
||||
end
|
||||
|
||||
vim.lsp.buf.format {
|
||||
async = false,
|
||||
filter = function(c)
|
||||
return c.id == client.id
|
||||
end,
|
||||
}
|
||||
end,
|
||||
})
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
87
lua/plugins/kickstart/debug.lua
Normal file
87
lua/plugins/kickstart/debug.lua
Normal file
@@ -0,0 +1,87 @@
|
||||
-- debug.lua
|
||||
--
|
||||
-- Shows how to use the DAP plugin to debug your code.
|
||||
--
|
||||
-- Primarily focused on configuring the debugger for Go, but can
|
||||
-- be extended to other languages as well. That's why it's called
|
||||
-- kickstart.nvim and not kitchen-sink.nvim ;)
|
||||
|
||||
return {
|
||||
-- NOTE: Yes, you can install new plugins here!
|
||||
'mfussenegger/nvim-dap',
|
||||
-- NOTE: And you can specify dependencies as well
|
||||
dependencies = {
|
||||
-- Creates a beautiful debugger UI
|
||||
'rcarriga/nvim-dap-ui',
|
||||
|
||||
-- Installs the debug adapters for you
|
||||
'williamboman/mason.nvim',
|
||||
'jay-babu/mason-nvim-dap.nvim',
|
||||
|
||||
-- Add your own debuggers here
|
||||
'leoluz/nvim-dap-go',
|
||||
},
|
||||
config = function()
|
||||
local dap = require 'dap'
|
||||
local dapui = require 'dapui'
|
||||
|
||||
require('mason-nvim-dap').setup {
|
||||
-- Makes a best effort to setup the various debuggers with
|
||||
-- reasonable debug configurations
|
||||
automatic_setup = true,
|
||||
|
||||
-- You can provide additional configuration to the handlers,
|
||||
-- see mason-nvim-dap README for more information
|
||||
handlers = {},
|
||||
|
||||
-- You'll need to check that you have the required things installed
|
||||
-- online, please don't ask me how to install them :)
|
||||
ensure_installed = {
|
||||
-- Update this to ensure that you have the debuggers for the langs you want
|
||||
'delve',
|
||||
},
|
||||
}
|
||||
|
||||
-- Basic debugging keymaps, feel free to change to your liking!
|
||||
vim.keymap.set('n', '<F5>', dap.continue, { desc = 'Debug: Start/Continue' })
|
||||
vim.keymap.set('n', '<F1>', dap.step_into, { desc = 'Debug: Step Into' })
|
||||
vim.keymap.set('n', '<F2>', dap.step_over, { desc = 'Debug: Step Over' })
|
||||
vim.keymap.set('n', '<F3>', dap.step_out, { desc = 'Debug: Step Out' })
|
||||
vim.keymap.set('n', '<leader>b', dap.toggle_breakpoint, { desc = 'Debug: Toggle Breakpoint' })
|
||||
vim.keymap.set('n', '<leader>B', function()
|
||||
dap.set_breakpoint(vim.fn.input 'Breakpoint condition: ')
|
||||
end, { desc = 'Debug: Set Breakpoint' })
|
||||
|
||||
-- Dap UI setup
|
||||
-- For more information, see |:help nvim-dap-ui|
|
||||
dapui.setup {
|
||||
-- Set icons to characters that are more likely to work in every terminal.
|
||||
-- Feel free to remove or use ones that you like more! :)
|
||||
-- Don't feel like these are good choices.
|
||||
icons = { expanded = '▾', collapsed = '▸', current_frame = '*' },
|
||||
controls = {
|
||||
icons = {
|
||||
pause = '⏸',
|
||||
play = '▶',
|
||||
step_into = '⏎',
|
||||
step_over = '⏭',
|
||||
step_out = '⏮',
|
||||
step_back = 'b',
|
||||
run_last = '▶▶',
|
||||
terminate = '⏹',
|
||||
disconnect = '⏏',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception.
|
||||
vim.keymap.set('n', '<F7>', dapui.toggle, { desc = 'Debug: See last session result.' })
|
||||
|
||||
dap.listeners.after.event_initialized['dapui_config'] = dapui.open
|
||||
dap.listeners.before.event_terminated['dapui_config'] = dapui.close
|
||||
dap.listeners.before.event_exited['dapui_config'] = dapui.close
|
||||
|
||||
-- Install golang specific config
|
||||
require('dap-go').setup()
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user