Added python lsp and massive refactor
This commit is contained in:
99
lua/plugins/lsp/lspconfig.lua
Normal file
99
lua/plugins/lsp/lspconfig.lua
Normal file
@@ -0,0 +1,99 @@
|
||||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
{ "antosha417/nvim-lsp-file-operations", config = true },
|
||||
{ "folke/neodev.nvim", opts = {} },
|
||||
},
|
||||
config = function()
|
||||
local lspconfig = require("lspconfig")
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
local cmp_nvim_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
local keymap = vim.keymap
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||
callback = function(ev)
|
||||
local opts = { buffer = ev.buf, silent = true }
|
||||
|
||||
opts.desc = "Show LSP references"
|
||||
keymap.set("n", "gR", "<cmd>Telescope lsp_references<CR>", opts)
|
||||
|
||||
opts.desc = "Go to declaration"
|
||||
keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
||||
|
||||
opts.desc = "Show LSP definitions"
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
|
||||
opts.desc = "Show LSP implementations"
|
||||
keymap.set("n", "gi", "<cmd>Telescope lsp_implementations<CR>", opts)
|
||||
|
||||
opts.desc = "Show LSP type definitions"
|
||||
keymap.set("n", "gt", "<cmd>Telescope lsp_type_definitions<CR>", opts)
|
||||
|
||||
opts.desc = "See available code actions"
|
||||
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
|
||||
opts.desc = "Smart rename"
|
||||
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
||||
|
||||
opts.desc = "Show buffer diagnostics"
|
||||
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts)
|
||||
|
||||
opts.desc = "Show line diagnostics"
|
||||
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts)
|
||||
|
||||
opts.desc = "Go to previous diagnostic"
|
||||
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
|
||||
|
||||
opts.desc = "Go to next diagnostic"
|
||||
keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
|
||||
|
||||
opts.desc = "Show documentation for what is under cursor"
|
||||
keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
|
||||
opts.desc = "Restart LSP"
|
||||
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts)
|
||||
end,
|
||||
})
|
||||
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
|
||||
for type, icon in pairs(signs) do
|
||||
local hl = "DiagnosticSign" .. type
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
|
||||
end
|
||||
|
||||
mason_lspconfig.setup_handlers({
|
||||
function(server_name)
|
||||
lspconfig[server_name].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
["basedpyright"] = function()
|
||||
lspconfig["basedpyright"].setup({
|
||||
capabilities = capabilities,
|
||||
})
|
||||
end,
|
||||
["lua_ls"] = function()
|
||||
lspconfig["lua_ls"].setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
Lua = {
|
||||
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
29
lua/plugins/lsp/mason.lua
Normal file
29
lua/plugins/lsp/mason.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
return {
|
||||
"williamboman/mason.nvim",
|
||||
dependencies = {
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
},
|
||||
config = function()
|
||||
local mason = require("mason")
|
||||
mason.setup({})
|
||||
|
||||
local mason_lspconfig = require("mason-lspconfig")
|
||||
mason_lspconfig.setup({
|
||||
ensure_installed = {
|
||||
"basedpyright",
|
||||
"lua_ls",
|
||||
},
|
||||
})
|
||||
|
||||
local mason_tool_installer = require("mason-tool-installer")
|
||||
mason_tool_installer.setup({
|
||||
ensure_installed = {
|
||||
"stylua",
|
||||
"ruff",
|
||||
"isort",
|
||||
"mypy",
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
return {
|
||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||
opts = {
|
||||
ensure_installed = require("config.mason-tools-list"),
|
||||
},
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
return {
|
||||
"williamboman/mason.nvim",
|
||||
opts = {
|
||||
ensure_installed = require("config.mason-tools-list"),
|
||||
},
|
||||
}
|
||||
55
lua/plugins/nvim-cmp.lua
Normal file
55
lua/plugins/nvim-cmp.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
{
|
||||
"L3MON4D3/LuaSnip",
|
||||
version = "v2.*",
|
||||
build = "make install_jsregexp",
|
||||
},
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"rafamadriz/friendly-snippets",
|
||||
"onsails/lspkind.nvim",
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
local lspkind = require("lspkind")
|
||||
|
||||
cmp.setup({
|
||||
completion = {
|
||||
completeopt = "menu,menuone,preview,noselect",
|
||||
},
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-S-k>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-S-j>"] = cmp.mapping.select_next_item(),
|
||||
["<C-S-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-S-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-S-Space>"] = cmp.mapping.complete(),
|
||||
["<C-S-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
||||
}),
|
||||
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
|
||||
formatting = {
|
||||
format = lspkind.cmp_format({
|
||||
maxwidth = 50,
|
||||
ellipsis_char = "...",
|
||||
}),
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
@@ -2,6 +2,7 @@ return {
|
||||
"nvim-telescope/telescope.nvim",
|
||||
tag = "0.1.8",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
lazy = false,
|
||||
config = function()
|
||||
require("telescope").setup({}) -- Define key mappings here to ensure they are set after the plugin is loaded
|
||||
vim.api.nvim_set_keymap("n", "<leader><C-f>", "<Cmd>Telescope live_grep<CR>", { noremap = true, silent = true })
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
return {
|
||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||
dependencies = { "nvim-treesitter/nvim-treesitter" },
|
||||
}
|
||||
13
lua/plugins/venv-selector.lua
Normal file
13
lua/plugins/venv-selector.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
return {
|
||||
"linux-cultist/venv-selector.nvim",
|
||||
dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim" },
|
||||
opts = {
|
||||
name = "venv",
|
||||
},
|
||||
branch = "regexp", -- This is the regexp branch, use this for the new version
|
||||
event = "VeryLazy",
|
||||
keys = {
|
||||
{ "<leader>vs", "<cmd>VenvSelect<cr>" },
|
||||
{ "<leader>vc", "<cmd>VenvSelectCached<cr>" },
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user