csharp-language-server-protocol icon indicating copy to clipboard operation
csharp-language-server-protocol copied to clipboard

Unable to start language server (?)

Open p-lindberg opened this issue 2 years ago • 13 comments

I'm considering using the OmniSharp LanguageServer for one of my projects, but was unable to get the server to start. I read all of the documentation I could find and followed the implementation of the sample server, but still could not figure out what was wrong. I even tried running the sample server as-is, but could not get that to work.

The application gets as far as line 246 in LanguageServer.cs, where it will await _initializingTask.ConfigureAwait(false);, which never runs to completion.

At this point, the server does not respond to any messages passed on the input stream. Connecting with a client (lsp4intellij) fails, and sending an initialisation message manually by pasting it into stdin yields no response. It does not even give you any errors if you send a malformed message or just plain gibberish.

I'm running this on MacOS 13.0, and tried both .NET 6.0 and 7.0.

p-lindberg avatar Feb 01 '23 08:02 p-lindberg

I tried running the sample server and it does the same thing.

Unfortunately that has also affected the OmniSharp-Roslyn builds as the LSP function hangs on https://github.com/OmniSharp/csharp-language-server-protocol/blob/master/src/Server/LanguageServer.cs#L289

rogerfar avatar Feb 03 '23 18:02 rogerfar

Hi @p-lindberg , @rogerfar have you found a solution / workaround for this issue? I'm also having problems getting the sample server to run.

XzuluX avatar Feb 27 '23 14:02 XzuluX

Unfortunately not, this project looks to be abandoned if you look at the log:

https://github.com/OmniSharp/csharp-language-server-protocol/commits/master

We're now 6 months in without a proper commit.

rogerfar avatar Feb 27 '23 14:02 rogerfar

Same. I went down the route of building my own language server instead, using the libraries StreamJsonRpc and Microsoft.VisualStudio.LanguageServer.Protocol. Between those two, you're pretty much covered for everything that is not specific to your language.

p-lindberg avatar Feb 27 '23 14:02 p-lindberg

OK, that's annoying ... But thanks for your quick reply 👍

XzuluX avatar Feb 27 '23 14:02 XzuluX

Unfortunately not, this project looks to be abandoned if you look at the log:

FWIW a lot of us are still using it (see https://github.com/OmniSharp/csharp-language-server-protocol/issues/193) but yeah I don't know how much effort is being made to maintain it. I think I was the last one to contribute a bug fix, and last work I see by @david-driscoll is the work-in-progress for 3.17 in https://github.com/OmniSharp/csharp-language-server-protocol/pull/893. David, do you have any insight into future plans for the project?

andyleejordan avatar Feb 27 '23 18:02 andyleejordan

Found a nice manageable example from @bjorkstromm https://github.com/bjorkstromm/lsp-example that helps to get started implementing a LSP server in C# including a VSCode client. However this demo is a bit older using "OmniSharp.Extensions.LanguageServer" Version="0.10.0".

Seems like this demo stopped working with version 0.14.0. Some fundamental changes have been implemented with this version. Tried to rewrite this example for current version 0.19.7, but server doesn't work anymore and apparently, it is in the state that @rogerfar described.

Does anyone have any idea what is missing to get the demo running with current version?

XzuluX avatar Mar 01 '23 13:03 XzuluX

spam

XzuluX avatar Mar 03 '23 09:03 XzuluX

Update: Finally I revisited the issue and got a small LSP running with current version 0.19.7. The difference is that I'm now using the base classes to derive the handlers from, just like they are implemented in the Omnisharp repo LanguageServerHost.cs:

internal static void RegisterHandlers(ILanguageServer server, CompositionHost compositionHost, RequestHandlers handlers)
        {
            // TODO: Make it easier to resolve handlers from MEF (without having to add more attributes to the services if we can help it)
            var workspace = compositionHost.GetExport<OmniSharpWorkspace>();
            compositionHost.GetExport<DiagnosticEventForwarder>().IsEnabled = true;
            var documentVersions = server.Services.GetRequiredService<DocumentVersions>();
            var serializer = server.Services.GetRequiredService<ISerializer>();
            server.Register(s =>
            {
                foreach (var handler in OmniSharpCodeActionHandler.Enumerate(handlers, serializer, server, documentVersions)
                    .Concat(OmniSharpCodeLensHandler.Enumerate(handlers))
                    .Concat(OmniSharpCompletionHandler.Enumerate(handlers)) 
                    ..........

Sample for a CompletionHander scaffold:

internal class CompletionHandler : CompletionHandlerBase
    {
        public override async Task<CompletionItem> Handle(CompletionItem request, CancellationToken cancellationToken)
        {
            return new CompletionItem();
        }

        public override async Task<CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            return new CompletionList();
        }

        protected override CompletionRegistrationOptions CreateRegistrationOptions(CompletionCapability capability, ClientCapabilities clientCapabilities)
        {
            return new CompletionRegistrationOptions()
            {
                DocumentSelector = new DocumentSelector(new DocumentFilter()
                {
                    Pattern = "**/*.cs"
                }),
                ResolveProvider = true,
                TriggerCharacters = new[] { ".", " " },
            };
        }
    }

Sample initializing the server:

 static async Task Main(string[] args)
        {
            var server = await LanguageServer.From(options =>
               options
                   .WithInput(Console.OpenStandardInput())
                   .WithOutput(Console.OpenStandardOutput())
                   .WithLoggerFactory(new LoggerFactory())
                   .AddDefaultLoggingProvider()                   
                   .WithHandler<CompletionHandler>()
                   );

            await server.WaitForExit;
        }

XzuluX avatar Mar 03 '23 09:03 XzuluX

Any update on this? This is very annoying... Friendly ping @david-driscoll

jcs090218 avatar May 01 '23 03:05 jcs090218

It is very likely that this issue can be traced back to faulty implemeted handlers. Initially, I had the same problem. The small sample code above should work.

XzuluX avatar Sep 11 '23 13:09 XzuluX

This issue still exists in 2024.

cernydav avatar Mar 16 '24 00:03 cernydav