diff --git a/init.lua b/init.lua index ab72f237..b1ff2b8c 100644 --- a/init.lua +++ b/init.lua @@ -540,6 +540,7 @@ require('lazy').setup({ -- -- If you're wondering about lsp vs treesitter, you can check out the wonderfully -- and elegantly composed help section, `:help lsp-vs-treesitter` + local lspconfig = require 'lspconfig' -- This function gets run when an LSP attaches to a particular buffer. -- That is to say, every time a new file is opened that is associated with @@ -693,6 +694,71 @@ require('lazy').setup({ -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ + local on_attach = function(_, bufnr) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + opts.buffer = bufnr + + -- opts.desc = 'Show line diagnostics' + -- vim.keymap.set('n', 'd', vim.diagnostic.open_float, opts) + -- + -- opts.desc = 'Show documentation for what is under cursor' + -- vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + -- + -- opts.desc = 'Show LSP definition' + -- vim.keymap.set('n', 'gd', 'Telescope lsp_definitions trim_text=true', opts) + + -- Rename the variable under your cursor. + -- Most Language Servers support renaming across files, etc. + map('grn', vim.lsp.buf.rename, '[R]e[n]ame') + + -- Execute a code action, usually your cursor needs to be on top of an error + -- or a suggestion from your LSP for this to activate. + map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) + + -- Find references for the word under your cursor. + map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + + -- Jump to the implementation of the word under your cursor. + -- Useful when your language has ways of declaring types without an actual implementation. + map('gri', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + map('grd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + + -- WARN: This is not Goto Definition, this is Goto Declaration. + -- For example, in C this would take you to the header. + map('grD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + map('gO', require('telescope.builtin').lsp_document_symbols, 'Open Document Symbols') + + -- Fuzzy find all the symbols in your current workspace. + -- Similar to document symbols, except searches over your entire project. + map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + -- the definition of its *type*, not where it was *defined*. + map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') + end + + local lspconfig = vim.lsp.config + lspconfig('sourcekit', { + capabilities = capabilities, + on_attach = on_attach, + root_dir = function(_, callback) + callback(require('lspconfig.util').root_pattern 'Package.swift'(vim.fn.getcwd()) or require('lspconfig.util').find_git_ancestor(vim.fn.getcwd())) + end, + cmd = { vim.trim(vim.fn.system 'xcrun -f sourcekit-lsp') }, + }) + + vim.lsp.enable 'sourcekit' local servers = { clangd = {}, gopls = {}, @@ -705,8 +771,6 @@ require('lazy').setup({ -- -- But for many setups, the LSP (`ts_ls`) will work just fine ts_ls = {}, - -- - lua_ls = { -- cmd = { ... }, -- filetypes = { ... }, @@ -1360,6 +1424,92 @@ require('lazy').setup({ vim.keymap.set('n', 'yc', 'MeowYarn call callees', { desc = 'Yarn: Callees' }) end, }, + { + 'folke/flash.nvim', + event = 'VeryLazy', + ---@type Flash.Config + opts = {}, + keys = { + { + 's', + mode = { 'n', 'x', 'o' }, + function() + require('flash').jump() + end, + desc = 'Flash', + }, + { + 'S', + mode = { 'n', 'x', 'o' }, + function() + require('flash').treesitter() + end, + desc = 'Flash Treesitter', + }, + { + 'r', + mode = 'o', + function() + require('flash').remote() + end, + desc = 'Remote Flash', + }, + { + 'R', + mode = { 'o', 'x' }, + function() + require('flash').treesitter_search() + end, + desc = 'Treesitter Search', + }, + { + '', + mode = { 'c' }, + function() + require('flash').toggle() + end, + desc = 'Toggle Flash Search', + }, + }, + }, + { + 'wojciech-kulik/xcodebuild.nvim', + dependencies = { + 'MunifTanjim/nui.nvim', + 'nvim-treesitter/nvim-treesitter', -- (optional) for Quick tests support (required Swift parser) + }, + config = function() + require('xcodebuild').setup { + -- put some options here or leave it empty to use default settings + } + vim.keymap.set('n', 'X', 'XcodebuildPicker', { desc = 'Show Xcodebuild Actions' }) + vim.keymap.set('n', 'xf', 'XcodebuildProjectManager', { desc = 'Show Project Manager Actions' }) + + vim.keymap.set('n', 'xb', 'XcodebuildBuild', { desc = 'Build Project' }) + vim.keymap.set('n', 'xB', 'XcodebuildBuildForTesting', { desc = 'Build For Testing' }) + vim.keymap.set('n', 'xr', 'XcodebuildBuildRun', { desc = 'Build & Run Project' }) + + vim.keymap.set('n', 'xt', 'XcodebuildTest', { desc = 'Run Tests' }) + vim.keymap.set('v', 'xt', 'XcodebuildTestSelected', { desc = 'Run Selected Tests' }) + vim.keymap.set('n', 'xT', 'XcodebuildTestClass', { desc = 'Run Current Test Class' }) + vim.keymap.set('n', 'x.', 'XcodebuildTestRepeat', { desc = 'Repeat Last Test Run' }) + + vim.keymap.set('n', 'xl', 'XcodebuildToggleLogs', { desc = 'Toggle Xcodebuild Logs' }) + vim.keymap.set('n', 'xc', 'XcodebuildToggleCodeCoverage', { desc = 'Toggle Code Coverage' }) + vim.keymap.set('n', 'xC', 'XcodebuildShowCodeCoverageReport', { desc = 'Show Code Coverage Report' }) + vim.keymap.set('n', 'xe', 'XcodebuildTestExplorerToggle', { desc = 'Toggle Test Explorer' }) + vim.keymap.set('n', 'xs', 'XcodebuildFailingSnapshots', { desc = 'Show Failing Snapshots' }) + + vim.keymap.set('n', 'xp', 'XcodebuildPreviewGenerateAndShow', { desc = 'Generate Preview' }) + vim.keymap.set('n', 'x', 'XcodebuildPreviewToggle', { desc = 'Toggle Preview' }) + + vim.keymap.set('n', 'xd', 'XcodebuildSelectDevice', { desc = 'Select Device' }) + vim.keymap.set('n', 'xq', 'Telescope quickfix', { desc = 'Show QuickFix List' }) + + vim.keymap.set('n', 'xx', 'XcodebuildQuickfixLine', { desc = 'Quickfix Line' }) + vim.keymap.set('n', 'xa', 'XcodebuildCodeActions', { desc = 'Show Code Actions' }) + end, + }, { 'NickvanDyke/opencode.nvim', dependencies = { @@ -1370,83 +1520,103 @@ require('lazy').setup({ opts = { -- Your configuration, if any — see lua/opencode/config.lua }, - keys = { - -- Recommended keymaps - { - 'oA', - function() - require('opencode').ask() - end, - desc = 'Ask opencode', - }, - { - 'oa', - function() - require('opencode').ask '@cursor: ' - end, - desc = 'Ask opencode about this', - mode = 'n', - }, - { - 'oa', - function() - require('opencode').ask '@selection: ' - end, - desc = 'Ask opencode about selection', - mode = 'v', - }, - { - 'ot', - function() - require('opencode').toggle() - end, - desc = 'Toggle embedded opencode', - }, - { - 'on', - function() - require('opencode').command 'session_new' - end, - desc = 'New session', - }, - { - 'oy', - function() - require('opencode').command 'messages_copy' - end, - desc = 'Copy last message', - }, - { - '', - function() - require('opencode').command 'messages_half_page_up' - end, - desc = 'Scroll messages up', - }, - { - '', - function() - require('opencode').command 'messages_half_page_down' - end, - desc = 'Scroll messages down', - }, - { - 'op', - function() - require('opencode').select_prompt() - end, - desc = 'Select prompt', - mode = { 'n', 'v' }, - }, - -- Example: keymap for custom prompt - { - 'oe', - function() - require('opencode').prompt 'Explain @cursor and its context' - end, - desc = 'Explain code near cursor', - }, - }, + config = function() + vim.keymap.set({ 'n', 'x' }, 'oa', function() + require('opencode').ask('@this: ', { submit = true }) + end, { desc = 'Ask opencode' }) + vim.keymap.set({ 'n', 'x' }, 'os', function() + require('opencode').select() + end, { desc = 'Execute opencode action…' }) + vim.keymap.set({ 'n', 'x' }, 'ga', function() + require('opencode').prompt '@this' + end, { desc = 'Add to opencode' }) + vim.keymap.set({ 'n', 't' }, 'ot', function() + require('opencode').toggle() + end, { desc = 'Toggle opencode' }) + vim.keymap.set('n', '', function() + require('opencode').command 'session.half.page.up' + end, { desc = 'opencode half page up' }) + vim.keymap.set('n', '', function() + require('opencode').command 'session.half.page.down' + end, { desc = 'opencode half page down' }) + end, + -- keys = { + -- -- Recommended keymaps + -- { + -- 'oA', + -- function() + -- require('opencode').ask() + -- end, + -- desc = 'Ask opencode', + -- }, + -- -- { + -- -- 'oa', + -- -- function() + -- -- require('opencode').ask('@this: ', { submit = true }) + -- -- end, + -- -- desc = 'Ask opencode about this', + -- -- mode = 'n', + -- -- }, + -- -- { + -- -- 'oa', + -- -- function() + -- -- require('opencode').ask '@selection: ' + -- -- end, + -- -- desc = 'Ask opencode about selection', + -- -- mode = 'v', + -- -- }, + -- { + -- 'ot', + -- function() + -- require('opencode').toggle() + -- end, + -- desc = 'Toggle embedded opencode', + -- }, + -- { + -- 'on', + -- function() + -- require('opencode').command 'session_new' + -- end, + -- desc = 'New session', + -- }, + -- { + -- 'oy', + -- function() + -- require('opencode').command 'messages_copy' + -- end, + -- desc = 'Copy last message', + -- }, + -- { + -- '', + -- function() + -- require('opencode').command 'messages_half_page_up' + -- end, + -- desc = 'Scroll messages up', + -- }, + -- { + -- '', + -- function() + -- require('opencode').command 'messages_half_page_down' + -- end, + -- desc = 'Scroll messages down', + -- }, + -- { + -- 'op', + -- function() + -- require('opencode').select_prompt() + -- end, + -- desc = 'Select prompt', + -- mode = { 'n', 'v' }, + -- }, + -- -- Example: keymap for custom prompt + -- { + -- 'oe', + -- function() + -- require('opencode').prompt 'Explain @cursor and its context' + -- end, + -- desc = 'Explain code near cursor', + -- }, + -- }, -- { -- 'dmtrKovalenko/fff.nvim', -- build = 'cargo build --release', diff --git a/lua/kickstart/plugins/debug.lua b/lua/kickstart/plugins/debug.lua index 8e332bf2..5dfddf39 100644 --- a/lua/kickstart/plugins/debug.lua +++ b/lua/kickstart/plugins/debug.lua @@ -23,64 +23,106 @@ return { -- Add your own debuggers here 'leoluz/nvim-dap-go', + + 'wojciech-kulik/xcodebuild.nvim', }, keys = { -- Basic debugging keymaps, feel free to change to your liking! { - '', + 'ee', function() - require('dap').continue() + require('xcodebuild.integrations.dap').build_and_debug() end, - desc = 'Debug: Start/Continue', + desc = 'Build & Debug', }, { - '', + 'dr', function() - require('dap').step_into() + require('xcodebuild.integrations.dap').debug_without_build() end, - desc = 'Debug: Step Into', + desc = 'Debug Without Building', }, { - '', + 'dt', function() - require('dap').step_over() + require('xcodebuild.integrations.dap').debug_tests() end, - desc = 'Debug: Step Over', + desc = 'Debug Tests', }, { - '', + 'dT', function() - require('dap').step_out() + require('xcodebuild.integrations.dap').debug_class_tests() end, - desc = 'Debug: Step Out', + desc = 'Debug Class Tests', }, { 'b', function() - require('dap').toggle_breakpoint() + require('xcodebuild.integrations.dap').toggle_breakpoint() end, - desc = 'Debug: Toggle Breakpoint', + desc = 'Toggle Breakpoint', }, { 'B', function() - require('dap').set_breakpoint(vim.fn.input 'Breakpoint condition: ') + require('xcodebuild.integrations.dap').toggle_message_breakpoint() end, - desc = 'Debug: Set Breakpoint', + desc = 'Toggle Message Breakpoint', }, - -- Toggle to see last session result. Without this, you can't see session output in case of unhandled exception. { - '', + 'dx', function() - require('dapui').toggle() + require('xcodebuild.integrations.dap').terminate_session() end, - desc = 'Debug: See last session result.', + desc = 'Terminate Debugger', }, }, config = function() local dap = require 'dap' local dapui = require 'dapui' + local xcodebuild = require 'xcodebuild.integrations.dap' + + xcodebuild.setup() + + local function setupListeners() + local dap = require 'dap' + local areSet = false + + dap.listeners.after['event_initialized']['me'] = function() + if not areSet then + areSet = true + vim.keymap.set('n', 'dc', dap.continue, { desc = 'Continue', noremap = true }) + vim.keymap.set('n', 'dC', dap.run_to_cursor, { desc = 'Run To Cursor' }) + vim.keymap.set('n', 'ds', dap.step_over, { desc = 'Step Over' }) + vim.keymap.set('n', 'di', dap.step_into, { desc = 'Step Into' }) + vim.keymap.set('n', 'do', dap.step_out, { desc = 'Step Out' }) + vim.keymap.set({ 'n', 'v' }, 'dh', require('dap.ui.widgets').hover, { desc = 'Hover' }) + vim.keymap.set({ 'n', 'v' }, 'de', require('dapui').eval, { desc = 'Eval' }) + end + end + + dap.listeners.after['event_terminated']['me'] = function() + if areSet then + areSet = false + vim.keymap.del('n', 'dc') + vim.keymap.del('n', 'dC') + vim.keymap.del('n', 'ds') + vim.keymap.del('n', 'di') + vim.keymap.del('n', 'do') + vim.keymap.del({ 'n', 'v' }, 'dh') + vim.keymap.del({ 'n', 'v' }, 'de') + end + end + end + setupListeners() + require('dap').defaults.fallback.switchbuf = 'usetab,uselast' + vim.keymap.set('n', 'dx', function() + xcodebuild.terminate_session() + require('dap').listeners.after['event_terminated']['me']() + end, { desc = 'Terminate debugger' }) + require('mason-nvim-dap').setup { -- Makes a best effort to setup the various debuggers with -- reasonable debug configurations