From e80b00ecb78ab7e8418ad90778bb0e9c6fbcf2d4 Mon Sep 17 00:00:00 2001 From: Ben Shiller Date: Thu, 26 Sep 2024 21:56:42 -0500 Subject: [PATCH] Add whichkey and lsp configs for python --- init.lua | 1 + lazy-lock.json | 5 ++-- lua/plugins/whichkey.lua | 53 ++++++++++++++++++++++++++++++++++++++++ lua/shillerben/lsp.lua | 38 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 lua/plugins/whichkey.lua create mode 100644 lua/shillerben/lsp.lua diff --git a/init.lua b/init.lua index 11b6db3..2a673cb 100644 --- a/init.lua +++ b/init.lua @@ -83,3 +83,4 @@ vim.api.nvim_create_autocmd('TextYankPost', { -- OTHER THINGS -- require("shillerben.lazy") +require("shillerben.lsp") diff --git a/lazy-lock.json b/lazy-lock.json index 9aed3ea..4735cb6 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,10 +1,11 @@ { "lazy.nvim": { "branch": "main", "commit": "460e1cd8f24e364d54543a4b0e83f6f4ec1f65fb" }, - "nvim-treesitter": { "branch": "master", "commit": "0c8a582e474e248f2a4406188e0c653f92a064cf" }, + "nvim-treesitter": { "branch": "master", "commit": "679883ad31f1752cac92a4ca182cee8b2751d4f1" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "tokyonight.nvim": { "branch": "main", "commit": "817bb6ffff1b9ce72cdd45d9fcfa8c9cd1ad3839" }, - "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" } + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "which-key.nvim": { "branch": "main", "commit": "fb070344402cfc662299d9914f5546d840a22126" } } diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..4f5573d --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,53 @@ +return { -- Useful plugin to show you pending keybinds. + 'folke/which-key.nvim', + event = 'VimEnter', -- Sets the loading event to 'VimEnter' + opts = { + icons = { + -- set icon mappings to true if you have a Nerd Font + mappings = vim.g.have_nerd_font, + -- If you are using a Nerd Font: set icons.keys to an empty table which will use the + -- default whick-key.nvim defined Nerd Font icons, otherwise define a string table + keys = vim.g.have_nerd_font and {} or { + Up = ' ', + Down = ' ', + Left = ' ', + Right = ' ', + C = ' ', + M = ' ', + D = ' ', + S = ' ', + CR = ' ', + Esc = ' ', + ScrollWheelDown = ' ', + ScrollWheelUp = ' ', + NL = ' ', + BS = ' ', + Space = ' ', + Tab = ' ', + F1 = '', + F2 = '', + F3 = '', + F4 = '', + F5 = '', + F6 = '', + F7 = '', + F8 = '', + F9 = '', + F10 = '', + F11 = '', + F12 = '', + }, + }, + + -- Document existing key chains + spec = { + { 'c', group = '[C]ode', mode = { 'n', 'x' } }, + { 'd', group = '[D]ocument' }, + { 'r', group = '[R]ename' }, + { 's', group = '[S]earch' }, + { 'w', group = '[W]orkspace' }, + { 't', group = '[T]oggle' }, + { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + }, + }, +} diff --git a/lua/shillerben/lsp.lua b/lua/shillerben/lsp.lua new file mode 100644 index 0000000..288ea49 --- /dev/null +++ b/lua/shillerben/lsp.lua @@ -0,0 +1,38 @@ +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }), + callback = function(args) + local opts = { buffer = args.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', '', vim.lsp.buf.format, opts) + end, +}) + + +-- Python config + +vim.api.nvim_create_autocmd('FileType', { + pattern = 'python', + group = vim.api.nvim_create_augroup('lsp-python', { clear = true }), + callback = function(args) + vim.lsp.start({ + name = 'pyright', + cmd = {'pyright-langserver', '--stdio'}, + -- uncomment after upgrading neovim > 0.10 + --root_dir = vim.fs.root(args.buf, {'setup.py', 'pyproject.toml'}), + root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]), + }) + vim.lsp.start({ + name = 'ruff', + cmd = {'ruff', 'server'}, + -- uncomment after upgrading neovim > 0.10 + --root_dir = vim.fs.root(args.buf, {'setup.py', 'pyproject.toml'}), + root_dir = vim.fs.dirname(vim.fs.find({'setup.py', 'pyproject.toml'}, { upward = true })[1]), + }) + end, +})