Skip to content

Commit

Permalink
LSPs and keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkenney committed Jul 17, 2024
1 parent dfd4d2f commit 8d7578e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"gitsigns.nvim": { "branch": "main", "commit": "e9c4187c3774a46df2d086a66cf3a7e6bea4c432" },
"harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" },
"lazy.nvim": { "branch": "main", "commit": "b02c9eae6a250f98908c146d1dc1a891f5019f0a" },
"lazydev.nvim": { "branch": "main", "commit": "02f1055a777264d4b65896051ec28d0f322f7932" },
"lazygit.nvim": { "branch": "main", "commit": "dc56df433bfbf107fee0139e187eb9750878fa84" },
"luvit-meta": { "branch": "main", "commit": "ce76f6f6cdc9201523a5875a4471dcfe0186eb60" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" },
"mason.nvim": { "branch": "main", "commit": "f96a31855fa8aea55599cea412fe611b85a874ed" },
"mini.nvim": { "branch": "main", "commit": "27de3dd4485161470ea55004fc132f2b158d1d24" },
"neo-tree.nvim": { "branch": "main", "commit": "206241e451c12f78969ff5ae53af45616ffc9b72" },
"neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" },
"noice.nvim": { "branch": "main", "commit": "2eeb1395ad2cb7a4feb7eaaaae574ab997c5231f" },
"nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" },
"nvim-autopairs": { "branch": "master", "commit": "78a4507bb9ffc9b00f11ae0ac48243d00cb9194d" },
Expand Down
3 changes: 3 additions & 0 deletions lua/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
-- Oil.nvim
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })

vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")

----------------------------------------------------------------------------------------------------
-- Diagnostics -------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/harpoon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ return {
keys = function()
local keys = {
{
"<leader>h",
"<leader>a",
function()
require("harpoon"):list():add()
end,
Expand Down
24 changes: 24 additions & 0 deletions lua/plugins/lazydev.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
return {
{
"folke/lazydev.nvim",
ft = "lua", -- only load on lua files
opts = {
library = {
-- See the configuration section for more details
-- Load luvit types when the `vim.uv` word is found
{ path = "luvit-meta/library", words = { "vim%.uv" } },
},
},
},
{ "Bilal2453/luvit-meta", lazy = true }, -- optional `vim.uv` typings
{ -- optional completion source for require statements and module annotations
"hrsh7th/nvim-cmp",
opts = function(_, opts)
opts.sources = opts.sources or {}
table.insert(opts.sources, {
name = "lazydev",
group_index = 0, -- set group index to 0 to skip loading LuaLS completions
})
end,
},
}
40 changes: 21 additions & 19 deletions lua/plugins/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ return {
-- Useful status updates for LSP.
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
{ "j-hui/fidget.nvim", opts = {} },

-- `neodev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
{ "folke/neodev.nvim", opts = {} },
},
config = function()
vim.api.nvim_create_autocmd("LspAttach", {
Expand All @@ -25,49 +21,49 @@ return {
-- 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)
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
vim.keymap.set("n", keys, func, { buffer = event.buf, desc = 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")
map("gd", require("telescope.builtin").lsp_definitions, "Goto Definition")

-- Find references for the word under your cursor.
map("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences")
map("gr", require("telescope.builtin").lsp_references, "Goto References")

-- 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")
map("gI", require("telescope.builtin").lsp_implementations, "Goto Implementation")

-- 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")
-- map("<leader>D", require("telescope.builtin").lsp_type_definitions, "Type Definition")

-- 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")
map("<leader>ds", require("telescope.builtin").lsp_document_symbols, "Document Symbols")

-- 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")
map("<leader>ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "Workspace Symbols")

-- 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")
map("<leader>rn", vim.lsp.buf.rename, "Rename")

-- 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")
map("<leader>ca", vim.lsp.buf.code_action, "Code Action")

-- Opens a popup that displays documentation about the word under your cursor
-- See `:help K` for why this keymap.
map("K", vim.lsp.buf.hover, "Hover Documentation")

-- 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")
map("gD", vim.lsp.buf.declaration, "Goto Declaration")

-- The following two autocommands are used to highlight references of the
-- word under your cursor when your cursor rests there for a little while.
Expand Down Expand Up @@ -105,7 +101,7 @@ return {
if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
map("<leader>th", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, "[T]oggle Inlay [H]ints")
end, "Toggle Inlay Hints")
end
end,
})
Expand All @@ -127,10 +123,17 @@ return {
-- - 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 servers = {
-- clangd = {},
-- gopls = {},
jdtls = {
cmd = {
vim.fn.exepath "jdtls",
"--jvm-arg=" .. string.format("-javaagent:%s", vim.fn.expand "$MASON/share/jdtls/lombok.jar"),
},
},
clangd = {},
zls = {},
rust_analyzer = {},
gopls = {},
-- pyright = {},
-- rust_analyzer = {},
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
--
-- Some languages (like typescript) have entire language plugins that can be useful:
Expand All @@ -139,7 +142,6 @@ return {
-- But for many setups, the LSP (`tsserver`) will work just fine
-- tsserver = {},
--

lua_ls = {
-- cmd = {...},
-- filetypes = { ...},
Expand Down
4 changes: 4 additions & 0 deletions lua/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ return {
"elixir",
"bash",
"c",
"cpp",
"go",
"rust",
"zig",
"diff",
"html",
"lua",
Expand Down

0 comments on commit 8d7578e

Please sign in to comment.