mirror of
https://github.com/josean-dev/dev-environment-files.git
synced 2025-01-08 17:21:23 +01:00
New code for lsp configuration video
This commit is contained in:
parent
976c03191b
commit
5accc8bf38
8 changed files with 49 additions and 71 deletions
4
.config/nvim/lua/josean/plugins/dressing.lua
Normal file
4
.config/nvim/lua/josean/plugins/dressing.lua
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
return {
|
||||||
|
"stevearc/dressing.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
}
|
|
@ -4,6 +4,4 @@ return {
|
||||||
"christoomey/vim-tmux-navigator", -- tmux & split window navigation
|
"christoomey/vim-tmux-navigator", -- tmux & split window navigation
|
||||||
|
|
||||||
"inkarkat/vim-ReplaceWithRegister", -- replace with register contents using motion (gr + motion)
|
"inkarkat/vim-ReplaceWithRegister", -- replace with register contents using motion (gr + motion)
|
||||||
|
|
||||||
"github/copilot.vim",
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,8 @@ return {
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
event = { "BufReadPre", "BufNewFile" },
|
event = { "BufReadPre", "BufNewFile" },
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"jose-elias-alvarez/typescript.nvim",
|
|
||||||
"hrsh7th/cmp-nvim-lsp",
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
{
|
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||||
"smjonas/inc-rename.nvim",
|
|
||||||
config = true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- import lspconfig plugin
|
-- import lspconfig plugin
|
||||||
|
@ -16,15 +12,11 @@ return {
|
||||||
-- import cmp-nvim-lsp plugin
|
-- import cmp-nvim-lsp plugin
|
||||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||||
|
|
||||||
-- import typescript plugin
|
|
||||||
local typescript = require("typescript")
|
|
||||||
|
|
||||||
local keymap = vim.keymap -- for conciseness
|
local keymap = vim.keymap -- for conciseness
|
||||||
|
|
||||||
-- enable keybinds only for when lsp server available
|
local opts = { noremap = true, silent = true }
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
-- keybind options
|
opts.buffer = bufnr
|
||||||
local opts = { noremap = true, silent = true, buffer = bufnr }
|
|
||||||
|
|
||||||
-- set keybinds
|
-- set keybinds
|
||||||
opts.desc = "Show LSP references"
|
opts.desc = "Show LSP references"
|
||||||
|
@ -46,7 +38,7 @@ return {
|
||||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
|
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
|
||||||
|
|
||||||
opts.desc = "Smart rename"
|
opts.desc = "Smart rename"
|
||||||
keymap.set("n", "<leader>rn", ":IncRename ", opts) -- smart rename
|
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
|
||||||
|
|
||||||
opts.desc = "Show buffer diagnostics"
|
opts.desc = "Show buffer diagnostics"
|
||||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
|
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
|
||||||
|
@ -65,18 +57,6 @@ return {
|
||||||
|
|
||||||
opts.desc = "Restart LSP"
|
opts.desc = "Restart LSP"
|
||||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
|
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
|
||||||
|
|
||||||
-- typescript specific keymaps (e.g. rename file and update imports)
|
|
||||||
if client.name == "tsserver" then
|
|
||||||
opts.desc = "Rename file and update file imports"
|
|
||||||
keymap.set("n", "<leader>rf", ":TypescriptRenameFile<CR>") -- rename file and update imports
|
|
||||||
|
|
||||||
opts.desc = "Rename file and update file imports"
|
|
||||||
keymap.set("n", "<leader>oi", ":TypescriptOrganizeImports<CR>", opts) -- organize imports (not in youtube nvim video)
|
|
||||||
|
|
||||||
opts.desc = "Remove unused imports"
|
|
||||||
keymap.set("n", "<leader>ru", ":TypescriptRemoveUnused<CR>", opts) -- remove unused variables (not in youtube nvim video)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- used to enable autocompletion (assign to every lsp server config)
|
-- used to enable autocompletion (assign to every lsp server config)
|
||||||
|
@ -97,11 +77,9 @@ return {
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure typescript server with plugin
|
-- configure typescript server with plugin
|
||||||
typescript.setup({
|
lspconfig["tsserver"].setup({
|
||||||
server = {
|
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- configure css server
|
-- configure css server
|
||||||
|
@ -142,6 +120,12 @@ return {
|
||||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- configure python server
|
||||||
|
lspconfig["pyright"].setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
on_attach = on_attach,
|
||||||
|
})
|
||||||
|
|
||||||
-- configure lua server (with special settings)
|
-- configure lua server (with special settings)
|
||||||
lspconfig["lua_ls"].setup({
|
lspconfig["lua_ls"].setup({
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
|
|
|
@ -5,17 +5,25 @@ return {
|
||||||
"jayp0521/mason-null-ls.nvim",
|
"jayp0521/mason-null-ls.nvim",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- import mason plugin safely
|
-- import mason
|
||||||
local mason = require("mason")
|
local mason = require("mason")
|
||||||
|
|
||||||
-- import mason-lspconfig plugin safely
|
-- import mason-lspconfig
|
||||||
local mason_lspconfig = require("mason-lspconfig")
|
local mason_lspconfig = require("mason-lspconfig")
|
||||||
|
|
||||||
-- import mason-null-ls plugin safely
|
-- import mason-null-ls
|
||||||
local mason_null_ls = require("mason-null-ls")
|
local mason_null_ls = require("mason-null-ls")
|
||||||
|
|
||||||
-- enable mason
|
-- enable mason and configure icons
|
||||||
mason.setup()
|
mason.setup({
|
||||||
|
ui = {
|
||||||
|
icons = {
|
||||||
|
package_installed = "✓",
|
||||||
|
package_pending = "➜",
|
||||||
|
package_uninstalled = "✗"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
mason_lspconfig.setup({
|
mason_lspconfig.setup({
|
||||||
-- list of servers for mason to install
|
-- list of servers for mason to install
|
||||||
|
@ -29,6 +37,7 @@ return {
|
||||||
"graphql",
|
"graphql",
|
||||||
"emmet_ls",
|
"emmet_ls",
|
||||||
"prismals",
|
"prismals",
|
||||||
|
"pyright"
|
||||||
},
|
},
|
||||||
-- auto-install configured servers (with lspconfig)
|
-- auto-install configured servers (with lspconfig)
|
||||||
automatic_installation = true, -- not the same as ensure_installed
|
automatic_installation = true, -- not the same as ensure_installed
|
||||||
|
|
|
@ -4,10 +4,10 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"hrsh7th/cmp-buffer", -- source for text in buffer
|
"hrsh7th/cmp-buffer", -- source for text in buffer
|
||||||
"hrsh7th/cmp-path", -- source for file system paths
|
"hrsh7th/cmp-path", -- source for file system paths
|
||||||
"onsails/lspkind.nvim",
|
|
||||||
"L3MON4D3/LuaSnip", -- snippet engine
|
"L3MON4D3/LuaSnip", -- snippet engine
|
||||||
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
"saadparwaiz1/cmp_luasnip", -- for autocompletion
|
||||||
"rafamadriz/friendly-snippets", -- useful snippets
|
"rafamadriz/friendly-snippets", -- useful snippets
|
||||||
|
"onsails/lspkind.nvim", -- vs-code like pictograms
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
|
@ -16,12 +16,14 @@ return {
|
||||||
|
|
||||||
local lspkind = require("lspkind")
|
local lspkind = require("lspkind")
|
||||||
|
|
||||||
-- load vs-code like snippets from plugins (e.g. friendly-snippets)
|
-- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
|
|
||||||
vim.opt.completeopt = "menu,menuone,noselect"
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
snippet = {
|
completion = {
|
||||||
|
completeopt = "menu,menuone,preview,noselect",
|
||||||
|
},
|
||||||
|
snippet = { -- configure how nvim-cmp interacts with snippet engine
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
luasnip.lsp_expand(args.body)
|
luasnip.lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
|
@ -37,12 +39,12 @@ return {
|
||||||
}),
|
}),
|
||||||
-- sources for autocompletion
|
-- sources for autocompletion
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = "nvim_lsp" }, -- lsp
|
{ name = "nvim_lsp" },
|
||||||
{ name = "luasnip" }, -- snippets
|
{ name = "luasnip" }, -- snippets
|
||||||
{ name = "buffer" }, -- text within current buffer
|
{ name = "buffer" }, -- text within current buffer
|
||||||
{ name = "path" }, -- file system paths
|
{ name = "path" }, -- file system paths
|
||||||
}),
|
}),
|
||||||
-- configure lspkind for vs-code like icons
|
-- configure lspkind for vs-code like pictograms in completion menu
|
||||||
formatting = {
|
formatting = {
|
||||||
format = lspkind.cmp_format({
|
format = lspkind.cmp_format({
|
||||||
maxwidth = 50,
|
maxwidth = 50,
|
||||||
|
|
|
@ -14,10 +14,14 @@ return {
|
||||||
-- configure nvim-tree
|
-- configure nvim-tree
|
||||||
nvimtree.setup({
|
nvimtree.setup({
|
||||||
view = {
|
view = {
|
||||||
width = 45,
|
width = 35,
|
||||||
|
relativenumber = true,
|
||||||
},
|
},
|
||||||
-- change folder arrow icons
|
-- change folder arrow icons
|
||||||
renderer = {
|
renderer = {
|
||||||
|
indent_markers = {
|
||||||
|
enable = true
|
||||||
|
},
|
||||||
icons = {
|
icons = {
|
||||||
glyphs = {
|
glyphs = {
|
||||||
folder = {
|
folder = {
|
||||||
|
|
|
@ -4,56 +4,33 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"nvim-lua/plenary.nvim",
|
"nvim-lua/plenary.nvim",
|
||||||
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
|
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
|
||||||
"nvim-telescope/telescope-ui-select.nvim",
|
|
||||||
"nvim-tree/nvim-web-devicons",
|
"nvim-tree/nvim-web-devicons",
|
||||||
"ThePrimeagen/harpoon",
|
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- import telescope plugin safely
|
|
||||||
local telescope = require("telescope")
|
local telescope = require("telescope")
|
||||||
|
|
||||||
-- import telescope actions safely
|
|
||||||
local actions = require("telescope.actions")
|
local actions = require("telescope.actions")
|
||||||
|
|
||||||
-- import telescope-ui-select safely
|
|
||||||
local themes = require("telescope.themes")
|
|
||||||
|
|
||||||
-- configure telescope
|
|
||||||
telescope.setup({
|
telescope.setup({
|
||||||
-- configure custom mappings
|
|
||||||
defaults = {
|
defaults = {
|
||||||
path_display = { "truncate " },
|
path_display = { "truncate " },
|
||||||
mappings = {
|
mappings = {
|
||||||
i = {
|
i = {
|
||||||
["<C-k>"] = actions.move_selection_previous, -- move to prev result
|
["<C-k>"] = actions.move_selection_previous, -- move to prev result
|
||||||
["<C-j>"] = actions.move_selection_next, -- move to next result
|
["<C-j>"] = actions.move_selection_next, -- move to next result
|
||||||
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist
|
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
extensions = {
|
|
||||||
["ui-select"] = {
|
|
||||||
themes.get_dropdown({}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
telescope.load_extension("fzf")
|
telescope.load_extension("fzf")
|
||||||
telescope.load_extension("ui-select")
|
|
||||||
telescope.load_extension("harpoon")
|
|
||||||
|
|
||||||
-- set keymaps
|
-- set keymaps
|
||||||
local keymap = vim.keymap -- for conciseness
|
local keymap = vim.keymap -- for conciseness
|
||||||
|
|
||||||
keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Fuzzy find files in cwd" }) -- find files within current working directory, respects .gitignore
|
keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "Fuzzy find files in cwd" })
|
||||||
keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "Fuzzy find recent files" }) -- find previously opened files
|
keymap.set("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "Fuzzy find recent files" })
|
||||||
keymap.set("n", "<leader>fs", "<cmd>Telescope live_grep<cr>", { desc = "Find string in cwd" }) -- find string in current working directory as you type
|
keymap.set("n", "<leader>fs", "<cmd>Telescope live_grep<cr>", { desc = "Find string in cwd" })
|
||||||
keymap.set("n", "<leader>fc", "<cmd>Telescope grep_string<cr>", { desc = "Find string under cursor in cwd" }) -- find string under cursor in current working directory
|
keymap.set("n", "<leader>fc", "<cmd>Telescope grep_string<cr>", { desc = "Find string under cursor in cwd" })
|
||||||
keymap.set("n", "<leader>fb", "<cmd>Telescope buffers<cr>", { desc = "Show open buffers" }) -- list open buffers in current neovim instance
|
|
||||||
keymap.set("n", "<leader>hf", "<cmd>Telescope harpoon marks<cr>", { desc = "Show harpoon marks" }) -- show harpoon marks
|
|
||||||
keymap.set("n", "<leader>gc", "<cmd>Telescope git_commits<cr>", { desc = "Show git commits" }) -- list all git commits (use <cr> to checkout) ["gc" for git commits]
|
|
||||||
keymap.set("n", "<leader>gfc", "<cmd>Telescope git_bcommits<cr>", { desc = "Show git commits for current buffer" }) -- list git commits for current file/buffer (use <cr> to checkout) ["gfc" for git file commits]
|
|
||||||
keymap.set("n", "<leader>gb", "<cmd>Telescope git_branches<cr>", { desc = "Show git branches" }) -- list git branches (use <cr> to checkout) ["gb" for git branch]
|
|
||||||
keymap.set("n", "<leader>gs", "<cmd>Telescope git_status<cr>", { desc = "Show current git changes per file" }) -- list current changes per file with diff preview ["gs" for git status]
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue