Add whichkey and lsp configs for python

This commit is contained in:
Ben Shiller 2024-09-26 21:56:42 -05:00
parent 28098d293d
commit e80b00ecb7
Signed by: shillerben
GPG Key ID: 959472A099996921
4 changed files with 95 additions and 2 deletions

View File

@ -83,3 +83,4 @@ vim.api.nvim_create_autocmd('TextYankPost', {
-- OTHER THINGS --
require("shillerben.lazy")
require("shillerben.lsp")

View File

@ -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" }
}

53
lua/plugins/whichkey.lua Normal file
View File

@ -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 = '<Up> ',
Down = '<Down> ',
Left = '<Left> ',
Right = '<Right> ',
C = '<C-…> ',
M = '<M-…> ',
D = '<D-…> ',
S = '<S-…> ',
CR = '<CR> ',
Esc = '<Esc> ',
ScrollWheelDown = '<ScrollWheelDown> ',
ScrollWheelUp = '<ScrollWheelUp> ',
NL = '<NL> ',
BS = '<BS> ',
Space = '<Space> ',
Tab = '<Tab> ',
F1 = '<F1>',
F2 = '<F2>',
F3 = '<F3>',
F4 = '<F4>',
F5 = '<F5>',
F6 = '<F6>',
F7 = '<F7>',
F8 = '<F8>',
F9 = '<F9>',
F10 = '<F10>',
F11 = '<F11>',
F12 = '<F12>',
},
},
-- Document existing key chains
spec = {
{ '<leader>c', group = '[C]ode', mode = { 'n', 'x' } },
{ '<leader>d', group = '[D]ocument' },
{ '<leader>r', group = '[R]ename' },
{ '<leader>s', group = '[S]earch' },
{ '<leader>w', group = '[W]orkspace' },
{ '<leader>t', group = '[T]oggle' },
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
},
},
}

38
lua/shillerben/lsp.lua Normal file
View File

@ -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', '<C-i>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<C-k>', 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,
})