mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +00:00
feat: Working on snippets for nvim
This commit is contained in:
@@ -1,49 +1,72 @@
|
||||
-- The language servers to setup.
|
||||
local lsp_servers = {
|
||||
"bashls",
|
||||
"clangd",
|
||||
"dockerls",
|
||||
"gopls",
|
||||
"jsonls",
|
||||
"lua_ls",
|
||||
"marksman",
|
||||
"sourcekit",
|
||||
"yamlls",
|
||||
}
|
||||
|
||||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
},
|
||||
config = function()
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup({
|
||||
opts = {
|
||||
ensure_installed = lsp_servers,
|
||||
},
|
||||
})
|
||||
local lspconfig = require("lspconfig")
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
local opts = { noremap = true, silent = true }
|
||||
local on_attach =
|
||||
function(_, bufnr)
|
||||
opts.buffer = bufnr
|
||||
local on_attach = function(_, bufnr)
|
||||
opts.buffer = bufnr
|
||||
|
||||
opts.desc = "Show line diagnostics"
|
||||
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||
opts.desc = "Show line diagnostics"
|
||||
vim.keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||
|
||||
opts.desc = "Show diagnostics in Telescope"
|
||||
vim.keymaps.set("n", "<leader><leader>d", "<CMD>Telescope diagnostics bufnr=0<CR>", opts)
|
||||
opts.desc = "Show diagnostics in Telescope"
|
||||
vim.keymap.set("n", "<leader><leader>d", "<CMD>Telescope diagnostics bufnr=0<CR>", opts)
|
||||
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.hover, opts)
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
vim.keymap.set("n", "<C-k>", vim.lsp.buf.hover, opts)
|
||||
|
||||
opts.desc = "[G]oto [D]efinition"
|
||||
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions trim_text=true<cr>", opts)
|
||||
opts.desc = "[G]oto [D]efinition"
|
||||
vim.keymap.set("n", "gd", "<cmd>Telescope lsp_definitions trim_text=true<cr>", opts)
|
||||
|
||||
opts.desc = "[G]oto [D]eclaration"
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
opts.desc = "[G]oto [D]eclaration"
|
||||
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
|
||||
opts.desc = "LSP [C]ode [A]ction"
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
opts.desc = "LSP [C]ode [A]ction"
|
||||
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
|
||||
--opts.desc = "[R]e-[N]ame"
|
||||
--vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
--opts.desc = "[R]e-[N]ame"
|
||||
--vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
|
||||
opts.desc = "[R]eload or start LSP"
|
||||
vim.keymap.set("n", "<leader>rl", ":LspRestart | :LspStart<CR>", opts)
|
||||
opts.desc = "[R]eload or start LSP"
|
||||
vim.keymap.set("n", "<leader>rl", ":LspRestart | :LspStart<CR>", opts)
|
||||
|
||||
opts.desc = "Goto previous diagnostic"
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
opts.desc = "Goto previous diagnostic"
|
||||
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
|
||||
opts.desc = "Goto next diagnostic"
|
||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||||
end, lspconfig["sourcekit"].setup({
|
||||
opts.desc = "Goto next diagnostic"
|
||||
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||||
end
|
||||
|
||||
for _, lsp in ipairs(lsp_servers) do
|
||||
lspconfig[lsp].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
on_init = function(client)
|
||||
@@ -52,6 +75,7 @@ return {
|
||||
client.offset_encoding = "utf-8"
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
-- nice icons
|
||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||
@@ -63,28 +87,3 @@ return {
|
||||
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "[R]e-[N]ame" })
|
||||
end,
|
||||
}
|
||||
|
||||
--
|
||||
-- -- Normal mode keymaps
|
||||
-- wk.add({
|
||||
-- { "<C-k>", vim.lsp.buf.hover, desc = "LSP hover info" },
|
||||
-- { "<leader>ca", vim.lsp.buf.code_action, desc = "LSP [C]ode [A]ction" },
|
||||
-- { "gi", vim.lsp.buf.implementation, desc = "[G]oto [I]mplementation" },
|
||||
-- { "gr", vim.lsp.buf.references, desc = "List [R]eferences" },
|
||||
-- { "gs", vim.lsp.buf.signature_help, desc = "[S]ignature help" },
|
||||
-- }, {
|
||||
-- mode = "n",
|
||||
-- silent = true,
|
||||
-- noremap = true,
|
||||
-- })
|
||||
--
|
||||
-- -- Visual mode keymaps
|
||||
-- wk.add({
|
||||
-- { "<leader>ca", vim.lsp.buf.code_action, desc = "LSP [C]ode [A]ction" },
|
||||
-- }, { mode = "v", silent = true })
|
||||
-- end,
|
||||
-- })
|
||||
-- end,
|
||||
-- },
|
||||
-- }
|
||||
-- }
|
||||
|
||||
45
nvim/m-housh/lua/user/plugin/luasnip.lua
Normal file
45
nvim/m-housh/lua/user/plugin/luasnip.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
return {
|
||||
"L3MON4D3/LuaSnip",
|
||||
opts = {
|
||||
history = true,
|
||||
enable_autosnippets = false, -- don't automatically expand snippets.
|
||||
updatevents = "TextChanged,TextChangedI",
|
||||
},
|
||||
config = function()
|
||||
local ls = require("luasnip")
|
||||
local types = require("luasnip.util.types")
|
||||
ls.setup({
|
||||
extra_opts = {
|
||||
[types.choiceNode] = {
|
||||
active = {
|
||||
virt_text = { { "choiceNode", "Comment" } },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
require("luasnip.loaders.from_lua").lazy_load({ paths = "~/.config/m-housh/lua/user/snippets/" })
|
||||
|
||||
-- Keymaps
|
||||
local opts = { silent = true }
|
||||
|
||||
-- Use <Ctrl>k to expand snippets.
|
||||
-- This will expand the current item or jump to the next item within the snippet.
|
||||
vim.keymap.set({ "i", "s" }, "<C-k>", function()
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
end
|
||||
end, opts)
|
||||
|
||||
-- Use <Ctrl>j to jump backwards in a snippet.
|
||||
-- This always moves to the previous item within a snippet.
|
||||
vim.keymap.set({ "i", "s" }, "<C-j>", function()
|
||||
if ls.jumpable(-1) then
|
||||
ls.jump(-1)
|
||||
end
|
||||
end, opts)
|
||||
|
||||
-- Reload snippets.
|
||||
vim.keymap.set("n", "<leader><leader>s", "<CMD>source ~/.config/m-housh/lua/user/plugin/luasnip.lua<CR>")
|
||||
end,
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
-- return {
|
||||
-- "nvim-neo-tree/neo-tree.nvim",
|
||||
-- branch = "v3.x",
|
||||
-- dependencies = {
|
||||
-- "nvim-lua/plenary.nvim",
|
||||
-- "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
|
||||
-- "MunifTanjim/nui.nvim",
|
||||
-- },
|
||||
-- opts = {
|
||||
-- close_if_last_window = false,
|
||||
-- enable_git_status = true,
|
||||
-- enable_diagnostics = true,
|
||||
-- filesystem = {
|
||||
-- always_show = {
|
||||
-- "plugins",
|
||||
-- ".zshrc",
|
||||
-- ".zshenv",
|
||||
-- "*.env"
|
||||
-- },
|
||||
-- filtered_items = {
|
||||
-- hide_dotfiles = false
|
||||
-- },
|
||||
-- use_libuv_file_watcher = true
|
||||
-- },
|
||||
-- }
|
||||
-- }
|
||||
Reference in New Issue
Block a user