Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to start language server (?) #933

Open
p-lindberg opened this issue Feb 1, 2023 · 13 comments
Open

Unable to start language server (?) #933

p-lindberg opened this issue Feb 1, 2023 · 13 comments

Comments

@p-lindberg
Copy link

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
Copy link

rogerfar commented Feb 3, 2023

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
Copy link

XzuluX commented Feb 27, 2023

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
Copy link

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
Copy link
Author

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
Copy link

XzuluX commented Feb 27, 2023

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

@andyleejordan
Copy link
Contributor

andyleejordan commented Feb 27, 2023

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

FWIW a lot of us are still using it (see #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 #893. David, do you have any insight into future plans for the project?

@XzuluX
Copy link

XzuluX commented Mar 1, 2023

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

This comment was marked as spam.

@XzuluX
Copy link

XzuluX commented Mar 3, 2023

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
Copy link

jcs090218 commented May 1, 2023

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

@XzuluX
Copy link

XzuluX commented Sep 11, 2023

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
Copy link

This issue still exists in 2024.

@kaannt
Copy link

kaannt commented Jul 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants