setup LSP, autocomplete for python
This commit is contained in:
15
lua/plugins/barbar.lua
Normal file
15
lua/plugins/barbar.lua
Normal file
@@ -0,0 +1,15 @@
|
||||
return {
|
||||
{'romgrk/barbar.nvim',
|
||||
dependencies = {
|
||||
'lewis6991/gitsigns.nvim', -- OPTIONAL: for git status
|
||||
'nvim-tree/nvim-web-devicons', -- OPTIONAL: for file icons
|
||||
},
|
||||
init = function() vim.g.barbar_auto_setup = false end,
|
||||
opts = {
|
||||
-- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:
|
||||
-- animation = true,
|
||||
-- insert_at_start = true,
|
||||
-- …etc.
|
||||
},
|
||||
version = '^1.0.0', -- optional: only update when a new 1.x version is released
|
||||
}}
|
||||
65
lua/plugins/completion.lua
Normal file
65
lua/plugins/completion.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
return {
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"L3MON4D3/LuaSnip",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
"rafamadriz/friendly-snippets",
|
||||
},
|
||||
config = function()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
|
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-Space>"] = cmp.mapping.complete(),
|
||||
["<C-e>"] = cmp.mapping.abort(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Confirm suggestion
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.locally_jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
{ name = "path" },
|
||||
}),
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
127
lua/plugins/lsp.lua
Normal file
127
lua/plugins/lsp.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
return {
|
||||
-- Mason for managing external tooling (LSPs, linters, formatters)
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
build = ":MasonUpdate",
|
||||
config = function()
|
||||
require("mason").setup({
|
||||
ui = {
|
||||
border = "rounded",
|
||||
icons = {
|
||||
package_installed = "✓",
|
||||
package_pending = "➜",
|
||||
package_uninstalled = "✗",
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
-- Bridge between mason and lspconfig
|
||||
{
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
},
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"pyright",
|
||||
"ruff",
|
||||
},
|
||||
automatic_installation = true,
|
||||
},
|
||||
},
|
||||
|
||||
-- LSP Config
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
local cmp_lsp = require("cmp_nvim_lsp")
|
||||
|
||||
-- Capabilities for auto-completion
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities = vim.tbl_deep_extend("force", capabilities, cmp_lsp.default_capabilities())
|
||||
|
||||
-- Diagnostic customization
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
signs = true,
|
||||
update_in_insert = false,
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
focusable = false,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
header = "",
|
||||
prefix = "",
|
||||
},
|
||||
})
|
||||
|
||||
-- Keybindings and setup for buffers with an active LSP client
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(args)
|
||||
local bufnr = args.buf
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
|
||||
-- Configure specific client overrides
|
||||
if client and client.name == "ruff" then
|
||||
-- Disable hover in favor of Pyright hover to avoid duplicate boxes
|
||||
client.server_capabilities.hoverProvider = false
|
||||
end
|
||||
|
||||
-- LSP Keymaps
|
||||
vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, { buffer = bufnr, desc = "Go to definition" })
|
||||
vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, { buffer = bufnr, desc = "LSP Hover info" })
|
||||
vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, { buffer = bufnr, desc = "Workspace symbol" })
|
||||
vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, { buffer = bufnr, desc = "Open diagnostics float" })
|
||||
vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, { buffer = bufnr, desc = "Next diagnostic" })
|
||||
vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, { buffer = bufnr, desc = "Previous diagnostic" })
|
||||
vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, { buffer = bufnr, desc = "Code action" })
|
||||
vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, { buffer = bufnr, desc = "References" })
|
||||
vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, { buffer = bufnr, desc = "Rename symbol" })
|
||||
vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, { buffer = bufnr, desc = "Signature help" })
|
||||
end,
|
||||
})
|
||||
|
||||
-- Configure Pyright (Python LSP) using native Neovim 0.11+ API
|
||||
vim.lsp.config("pyright", {
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = "workspace",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
vim.lsp.enable("pyright")
|
||||
|
||||
-- Configure Ruff (Python Linter/Formatter LSP) using native Neovim 0.11+ API
|
||||
vim.lsp.config("ruff", {
|
||||
capabilities = capabilities,
|
||||
})
|
||||
vim.lsp.enable("ruff")
|
||||
|
||||
-- Auto-format on save for Python using ruff
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*.py",
|
||||
callback = function(args)
|
||||
local clients = vim.lsp.get_clients({ bufnr = args.buf, name = "ruff" })
|
||||
if #clients > 0 then
|
||||
vim.lsp.buf.format({ bufnr = args.buf, id = clients[1].id, async = false })
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
||||
9
lua/plugins/markdown-render.lua
Normal file
9
lua/plugins/markdown-render.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
return {
|
||||
'MeanderingProgrammer/render-markdown.nvim',
|
||||
dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-mini/mini.nvim' }, -- if you use the mini.nvim suite
|
||||
-- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-mini/mini.icons' }, -- if you use standalone mini plugins
|
||||
-- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons
|
||||
---@module 'render-markdown'
|
||||
---@type render.md.UserConfig
|
||||
opts = {},
|
||||
}
|
||||
@@ -8,6 +8,9 @@ return {
|
||||
config = function()
|
||||
-- vim.cmd([[hi NvimTreeNormal guibg=NONE ctermbd=NONE]])
|
||||
require("nvim-tree").setup {
|
||||
git = {
|
||||
ignore = false,
|
||||
},
|
||||
filters= {
|
||||
dotfiles = false,
|
||||
},
|
||||
|
||||
@@ -4,5 +4,26 @@ return {
|
||||
'nvim-lua/plenary.nvim',
|
||||
-- optional but recommended
|
||||
{ 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' },
|
||||
}
|
||||
},
|
||||
config = function()
|
||||
require('telescope').setup({
|
||||
defaults = {
|
||||
vimgrep_arguments = {
|
||||
"rg",
|
||||
"--color=never",
|
||||
"--no-heading",
|
||||
"--with-filename",
|
||||
"--line-number",
|
||||
"--column",
|
||||
"--smart-case",
|
||||
"--no-ignore",
|
||||
},
|
||||
},
|
||||
pickers = {
|
||||
find_files = {
|
||||
no_ignore = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user