Thanks for reaching out!
Retry restarting the Language Server in Visual Studio Extension up to 5 times
- Unregister the language server on failure, when the LSP process crashes/exits, call:
await LanguageClientBroker.StopAsync();
This clears the previous registration so it can restart again.
- Add retry logic, use a loop to retry loading the server:
int maxRetries = 5;
int retryCount = 0;
while (retryCount < maxRetries)
{
try
{
await LanguageClientBroker.LoadAsync();
break; // exit loop if success
}
catch
{
retryCount++;
await Task.Delay(2000); // wait 2 seconds before retry
}
}
- Ensure ActivateAsync gets triggered every restart and before each retry, reset the client:
LanguageClientBroker.Dispose();
- Restart Visual Studio services if still failing
Tools and next Command Palette and select "Developer: Reload Window"
- If server still doesn't load after 5 retries
- Close Visual Studio,
- Delete .vs folder in the project
- Reopen Visual Studio
This removes cached LSP state.