OmniSharp / csharp-language-server-protocol

Language Server Protocol in C#
MIT License
515 stars 103 forks source link

Unable to start language server (?) #933

Open p-lindberg opened 1 year ago

p-lindberg commented 1 year ago

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.

rogerfar commented 1 year ago

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

XzuluX commented 1 year ago

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

rogerfar commented 1 year ago

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.

p-lindberg commented 1 year ago

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.

XzuluX commented 1 year ago

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

andyleejordan commented 1 year ago

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?

XzuluX commented 1 year ago

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 commented 1 year ago

spam

XzuluX commented 1 year ago

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;
        }
jcs090218 commented 1 year ago

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

XzuluX commented 1 year ago

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.

cernydav commented 6 months ago

This issue still exists in 2024.

kaannt commented 2 months ago

Are you guys sending the initialize and initialized lsp client requests?