summaryrefslogtreecommitdiff
path: root/lua/aotrix
diff options
context:
space:
mode:
Diffstat (limited to 'lua/aotrix')
-rw-r--r--lua/aotrix/plugins/nvim_dap.lua13
-rw-r--r--lua/aotrix/plugins/telescope.lua106
-rw-r--r--lua/aotrix/remap.lua22
3 files changed, 118 insertions, 23 deletions
diff --git a/lua/aotrix/plugins/nvim_dap.lua b/lua/aotrix/plugins/nvim_dap.lua
index 19ab17e..cf99de4 100644
--- a/lua/aotrix/plugins/nvim_dap.lua
+++ b/lua/aotrix/plugins/nvim_dap.lua
@@ -46,6 +46,19 @@ return {
ui.close()
end
+ vim.keymap.set("n", "<leader>b", function() require("dap").toggle_breakpoint() end)
+ vim.keymap.set("n", "<leader>gb", function() require("dap").run_to_cursor() end)
+ -- Eval var under cursor
+ vim.keymap.set("n", "<leader>?", function()
+ require("dapui").eval(nil, { enter = true })
+ end)
+ vim.keymap.set("n", "<F1>", function() require("dap").continue() end)
+ vim.keymap.set("n", "<F2>", function() require("dap").step_into() end)
+ vim.keymap.set("n", "<F3>", function() require("dap").step_over() end)
+ vim.keymap.set("n", "<F4>", function() require("dap").step_out() end)
+ vim.keymap.set("n", "<F5>", function() require("dap").step_back() end)
+ vim.keymap.set("n", "<F13>", function() require("dap").restart() end)
+
end,
}
diff --git a/lua/aotrix/plugins/telescope.lua b/lua/aotrix/plugins/telescope.lua
index 5abb62c..27edfd0 100644
--- a/lua/aotrix/plugins/telescope.lua
+++ b/lua/aotrix/plugins/telescope.lua
@@ -37,8 +37,112 @@ return {
vim.keymap.set("n", "<leader>pv", function() require("telescope").extensions.file_browser.file_browser() end)
vim.keymap.set("n", "<leader>pf", function() require("telescope.builtin").find_files() end)
- vim.keymap.set("n", "gd", function() require("telescope.builtin").lsp_definitions() end)
require('aotrix.multigrep').setup()
+
+ vim.api.nvim_create_autocmd('LspAttach', {
+ group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }),
+ callback = function(event)
+ -- NOTE: Remember that Lua is a real programming language, and as such it is possible
+ -- to define small helper and utility functions so you don't have to repeat yourself.
+ --
+ -- In this case, we create a function that lets us more easily define mappings specific
+ -- for LSP related items. It sets the mode, buffer and description for us each time.
+ local map = function(keys, func, desc, mode)
+ mode = mode or 'n'
+ vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
+ end
+
+ -- 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 <C-t>.
+ map('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition')
+
+ -- Find references for the word under your cursor.
+ map('gr', 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('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation')
+
+ -- 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('<leader>D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition')
+
+ -- Fuzzy find all the symbols in your current document.
+ -- Symbols are things like variables, functions, types, etc.
+ map('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
+
+ -- Fuzzy find all the symbols in your current workspace.
+ -- Similar to document symbols, except searches over your entire project.
+ map('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
+
+ -- Rename the variable under your cursor.
+ -- Most Language Servers support renaming across files, etc.
+ map('<leader>rn', 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('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
+
+ -- WARN: This is not Goto Definition, this is Goto Declaration.
+ -- For example, in C this would take you to the header.
+ map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
+
+ -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
+ ---@param client vim.lsp.Client
+ ---@param method vim.lsp.protocol.Method
+ ---@param bufnr? integer some lsp support methods only in specific files
+ ---@return boolean
+ local function client_supports_method(client, method, bufnr)
+ if vim.fn.has 'nvim-0.11' == 1 then
+ return client:supports_method(method, bufnr)
+ else
+ return client.supports_method(method, { bufnr = bufnr })
+ end
+ end
+
+ -- The following two autocommands are used to highlight references of the
+ -- word under your cursor when your cursor rests there for a little while.
+ -- See `:help CursorHold` for information about when this is executed
+ --
+ -- When you move your cursor, the highlights will be cleared (the second autocommand).
+ local client = vim.lsp.get_client_by_id(event.data.client_id)
+ if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
+ local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false })
+ vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
+ buffer = event.buf,
+ group = highlight_augroup,
+ callback = vim.lsp.buf.document_highlight,
+ })
+
+ vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
+ buffer = event.buf,
+ group = highlight_augroup,
+ callback = vim.lsp.buf.clear_references,
+ })
+
+ vim.api.nvim_create_autocmd('LspDetach', {
+ group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }),
+ callback = function(event2)
+ vim.lsp.buf.clear_references()
+ vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf }
+ end,
+ })
+ end
+
+ -- The following code creates a keymap to toggle inlay hints in your
+ -- code, if the language server you are using supports them
+ --
+ -- This may be unwanted, since they displace some of your code
+ if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
+ map('<leader>th', function()
+ vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
+ end, '[T]oggle Inlay [H]ints')
+ end
+ end,
+ })
+
end
}
diff --git a/lua/aotrix/remap.lua b/lua/aotrix/remap.lua
index cb70a7b..72a854b 100644
--- a/lua/aotrix/remap.lua
+++ b/lua/aotrix/remap.lua
@@ -14,27 +14,5 @@ vim.keymap.set("x", "<leader>p", [["_dP]])
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]])
vim.keymap.set("n", "<leader>Y", [["+Y]])
--- GoTo code navigation
--- vim.keymap.set("n", "gD", "<Plug>(coc-declaration)", {silent = true})
--- vim.keymap.set("n", "gd", "<Plug>(coc-definition)", {silent = true})
--- vim.keymap.set("n", "gr", "<CMD>Telescope coc references<CR>", {silent = true})
--- vim.keymap.set("n", "gy", "<Plug>(coc-type-definition)", {silent = true})
--- vim.keymap.set("n", "gi", "<Plug>(coc-implementation)", {silent = true})
--- vim.keymap.set("n", "K", '<CMD>lua _G.show_docs()<CR>', {silent = true})
-
-- Remove <C-c> because it is not fast enough
vim.keymap.set({'n', 'i', 'v'}, '<C-c>', '<nop>')
-
--- nvim-dap
-vim.keymap.set("n", "<leader>b", function() require("dap").toggle_breakpoint() end)
-vim.keymap.set("n", "<leader>gb", function() require("dap").run_to_cursor() end)
--- Eval var under cursor
-vim.keymap.set("n", "<leader>?", function()
- require("dapui").eval(nil, { enter = true })
-end)
-vim.keymap.set("n", "<F1>", function() require("dap").continue() end)
-vim.keymap.set("n", "<F2>", function() require("dap").step_into() end)
-vim.keymap.set("n", "<F3>", function() require("dap").step_over() end)
-vim.keymap.set("n", "<F4>", function() require("dap").step_out() end)
-vim.keymap.set("n", "<F5>", function() require("dap").step_back() end)
-vim.keymap.set("n", "<F13>", function() require("dap").restart() end)