@@ -61,7 +61,10 @@ PythonLSP.python_lsp_servers = {
6161 },
6262 ty = {
6363 callback = function (venv_path , client )
64- local new_settings = vim .tbl_deep_extend (" force" , client .settings , {
64+ if venv_path == nil then
65+ return
66+ end
67+ PythonLSP .restart_and_update_settings (client , {
6568 pythonExtension = {
6669 activeEnvironment = {
6770 version = {
@@ -82,7 +85,6 @@ PythonLSP.python_lsp_servers = {
8285 },
8386 },
8487 })
85- call_did_change_configuration (client , new_settings )
8688 end ,
8789 },
8890 -- For my homies in devops
@@ -116,4 +118,19 @@ function PythonLSP.notify_workspace_did_change()
116118 end
117119end
118120
121+ --- Stop, merge settings and restart an lsp client
122+ --- @param client vim.lsp.Client
123+ --- @param settings table
124+ function PythonLSP .restart_and_update_settings (client , settings )
125+ local new_settings = vim .tbl_deep_extend (" force" , client .settings , { settings = settings })
126+ local lsp_name = client .name
127+ vim .notify ((" Restarting and updating settings of: %s" ):format (lsp_name ), vim .log .levels .WARN )
128+ client :stop (true )
129+ vim .lsp .config (lsp_name , new_settings )
130+ local timer = assert (vim .uv .new_timer ())
131+ timer :start (500 , 0 , function ()
132+ vim .lsp .enable (lsp_name )
133+ end )
134+ end
135+
119136return PythonLSP
0 commit comments