grace/dots
dotfiles/nix configs
git clone https://git.gae.moe/grace/dots
5fdb347
old_stow_config
1---@brief 2--- 3--- https://detachhead.github.io/basedpyright 4--- 5--- `basedpyright`, a static type checker and language server for python 6 7local function set_python_path ( command ) 8local path = command . args 9local clients = vim . lsp . get_clients { 10bufnr = vim . api . nvim_get_current_buf () , 11name = 'basedpyright' , 12} 13for _ , client in ipairs ( clients ) do 14if client . settings then 15client . settings . python = vim . tbl_deep_extend ( 'force' , client . settings . python or {} , { pythonPath = path }) 16else 17client . config . settings = vim . tbl_deep_extend ( 'force' , client . config . settings , { python = { pythonPath = path } }) 18end 19client : notify ( 'workspace/didChangeConfiguration' , { settings = nil }) 20end 21end 22 23---@type vim.lsp.Config 24return { 25cmd = { 'basedpyright-langserver' , '--stdio' } , 26filetypes = { 'python' } , 27root_markers = { 28'pyproject.toml' , 29'setup.py' , 30'setup.cfg' , 31'requirements.txt' , 32'Pipfile' , 33'pyrightconfig.json' , 34'.git' , 35'.jj' 36} , 37settings = { 38basedpyright = { 39analysis = { 40autoSearchPaths = true , 41useLibraryCodeForTypes = true , 42diagnosticMode = 'openFilesOnly' , 43} , 44} , 45} , 46on_attach = function ( client , bufnr ) 47vim . api . nvim_buf_create_user_command ( bufnr , 'LspPyrightOrganizeImports' , function () 48local params = { 49command = 'basedpyright.organizeimports' , 50arguments = { vim . uri_from_bufnr ( bufnr ) } , 51} 52 53-- Using client.request() directly because "basedpyright.organizeimports" is private 54-- (not advertised via capabilities), which client:exec_cmd() refuses to call. 55-- https://github.com/neovim/neovim/blob/c333d64663d3b6e0dd9aa440e433d346af4a3d81/runtime/lua/vim/lsp/client.lua#L1024-L1030 56client . request ( 'workspace/executeCommand' , params , nil , bufnr ) 57end , { 58desc = 'Organize Imports' , 59}) 60 61vim . api . nvim_buf_create_user_command ( bufnr , 'LspPyrightSetPythonPath' , set_python_path , { 62desc = 'Reconfigure basedpyright with the provided python path' , 63nargs = 1 , 64complete = 'file' , 65}) 66end , 67}