xonecas.io
56101
Df

dotfiles / commit 8784ce0

feat: adds python stuff and new keybind to close buffer

xonecas2026-06-14 8784ce01520cab29ca9ec74cab619b272a546beb parent abd27ae

1 file changed

nvim/init.lua+69−1
@@ -168,7 +168,68 @@ require("lazy").setup({
168168 },
169169
170170 -- LSP/etc with Mason
171- "neovim/nvim-lspconfig",
171+ {
172+ "neovim/nvim-lspconfig",
173+ config = function()
174+ local function executable(path)
175+ return path and vim.fn.executable(path) == 1
176+ end
177+
178+ local function join(...)
179+ return table.concat({ ... }, "/")
180+ end
181+
182+ local function project_python(root_dir)
183+ if root_dir then
184+ for _, venv_name in ipairs({ ".venv", "venv" }) do
185+ local python = join(root_dir, venv_name, "bin", "python")
186+ if executable(python) then
187+ return python
188+ end
189+ end
190+ end
191+
192+ if vim.env.VIRTUAL_ENV then
193+ local python = join(vim.env.VIRTUAL_ENV, "bin", "python")
194+ if executable(python) then
195+ return python
196+ end
197+ end
198+
199+ local python3 = vim.fn.exepath("python3")
200+ if python3 ~= "" then
201+ return python3
202+ end
203+
204+ local python = vim.fn.exepath("python")
205+ if python ~= "" then
206+ return python
207+ end
208+ end
209+
210+ vim.lsp.config("pyright", {
211+ before_init = function(_, config)
212+ local python = project_python(config.root_dir)
213+ if not python then
214+ return
215+ end
216+
217+ config.settings = config.settings or {}
218+ config.settings.python = config.settings.python or {}
219+ config.settings.python.pythonPath = python
220+
221+ config.settings.python.analysis = config.settings.python.analysis or {}
222+ config.settings.python.analysis.autoSearchPaths = true
223+ config.settings.python.analysis.useLibraryCodeForTypes = true
224+
225+ local src_path = config.root_dir and join(config.root_dir, "src") or nil
226+ if src_path and vim.fn.isdirectory(src_path) == 1 then
227+ config.settings.python.analysis.extraPaths = { src_path }
228+ end
229+ end,
230+ })
231+ end,
232+ },
172233 {
173234 "mason-org/mason.nvim",
174235 config = function()
@@ -212,6 +273,13 @@ local opts = { noremap = true, silent = true }
212273 -- My keybindings
213274 keymap('n', '<leader>h', ':nohlsearch<CR>', opts)
214275 keymap('n', '<leader>q', ':qall<CR>', { noremap = true, silent = true, desc = 'Quit all' })
276+keymap('n', '<leader>Q', function()
277+ if vim.fn.winnr('$') > 1 then
278+ vim.cmd.close()
279+ else
280+ vim.cmd.bdelete()
281+ end
282+end, { noremap = true, silent = true, desc = 'Close focused buffer/split' })
215283 keymap('n', '<leader>s', ':write<CR>', { noremap = true, silent = true, desc = 'Save buffer' })
216284 keymap('n', '<leader>S', ':wall<CR>', { noremap = true, silent = true, desc = 'Save all buffers' })
217285 keymap('n', '<leader>d', function()