Language Server restarts only once in case of failure in Visual Studio

Sajith 66 Reputation points
2025-11-27T18:05:16.9433333+00:00

I am working on an extension that has a Language Server (LSP) implemented. I am trying to load the language server again in case of failure calling - ILanguageClientBroker.LoadAsync

This works fine once, Language Server is loaded again once.

But again if Language Server process exits and I try to load again calling ILanguageClientBroker.LoadAsync, this does not work. ILanguageClient.ActivateAsync is not getting called the second time on.

Does Visual Studio restrict retry attempts to load Langauge Server to only once ?

Is there a way to change the retry attempt to say 5 times ?

Developer technologies | Visual Studio | Extensions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Surya Amrutha Vaishnavi Lanka (INFOSYS LIMITED) 1,115 Reputation points Microsoft External Staff
    2025-11-28T11:16:33.06+00:00

    Thanks for reaching out!

    Retry restarting the Language Server in Visual Studio Extension up to 5 times

    1. 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.

    1. 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

        }

    }

    1. Ensure ActivateAsync gets triggered every restart and before each retry, reset the client:

    LanguageClientBroker.Dispose();

    1. Restart Visual Studio services if still failing

    Tools and next Command Palette and select "Developer: Reload Window"

    1. 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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.