grace/dots
dotfiles/nix configs
git clone https://git.gae.moe/grace/dots
ddf0c79
idk
1---@brief 2--- 3--- https://github.com/microsoft/pyright 4--- 5--- `pyright`, 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 ='pyright' , 12} 13for _ , client in ipairs ( clients ) do 14if client . settings then 15client . settings . python =vim . tbl_deep_extend ( 'force' , client . settings . python , { 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 ={ 'pyright-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 ={ 38python ={ 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 ='pyright.organizeimports' , 50arguments ={ vim . uri_from_bufnr ( bufnr ) } , 51} 52 53-- Using client.request() directly because "pyright.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} ) 60vim . api . nvim_buf_create_user_command ( bufnr , 'LspPyrightSetPythonPath' , set_python_path , { 61desc ='Reconfigure pyright with the provided python path' , 62nargs =1 , 63complete ='file' , 64} ) 65end , 66}