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

LSP Server not working in Visual Studio #132

Closed
gep13 opened this issue Mar 21, 2019 · 10 comments
Closed

LSP Server not working in Visual Studio #132

gep13 opened this issue Mar 21, 2019 · 10 comments
Labels
bug Something isn't working

Comments

@gep13
Copy link
Contributor

gep13 commented Mar 21, 2019

I have been setting up an LSP implementation for Chocolatey nuspec files in VSCode, and this has been working well. I am now trying to take the same Language Server implementation and run it in Visual Studio. When I try this, I get the following error returned:

image

The code that I am using the initialise the client within Visual Studio is the following:

    [ContentType("nuspec")]
    [Export(typeof(ILanguageClient))]
    public class ChocolateyLanguageClient : ILanguageClient
    {
        public string Name => "Chocolatey Language Server Client";

        public IEnumerable<string> ConfigurationSections => null;

        public object InitializationOptions => null;

        public IEnumerable<string> FilesToWatch => null;

        public event AsyncEventHandler<EventArgs> StartAsync;
        public event AsyncEventHandler<EventArgs> StopAsync;

        public async Task<Connection> ActivateAsync(CancellationToken token)
        {
            await Task.Yield();

            var info = new ProcessStartInfo();
            info.FileName = "dotnet";
            info.Arguments = "C:\\github_local\\gep13\\chocolatey-vs\\lib\\ChocolateyLanguageServer\\Chocolatey.Language.Server.dll";
            info.RedirectStandardInput = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
            info.CreateNoWindow = true;

            Process process = new Process();
            process.StartInfo = info;

            if (process.Start())
            {
                return new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
            }

            return null;
        }

        public async Task OnLoadedAsync()
        {
            await StartAsync?.InvokeAsync(this, EventArgs.Empty);
        }

        public Task OnServerInitializedAsync()
        {
            return Task.CompletedTask;
        }

        public Task OnServerInitializeFailedAsync(Exception e)
        {
            return Task.CompletedTask;
        }
    }

Is there additional configuration that needs to be provided, or is this a bug that needs to be addressed. Let me know if you need any further information.

@gep13
Copy link
Contributor Author

gep13 commented Mar 21, 2019

@mholo65 @david-driscoll @tintoy any ideas about the above?

@gep13
Copy link
Contributor Author

gep13 commented Mar 21, 2019

Seems the related code is here:

var handlerType = typeof(T).GetTypeInfo().ImplementedInterfaces
.Single(x => x.GetTypeInfo().IsGenericType && x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ConnectedCapability<>))
.GetTypeInfo().GetGenericArguments()[0].GetTypeInfo();

I am using the 0.12.0 version of OmniSharp.Extensions.LanguageServer.

@gep13
Copy link
Contributor Author

gep13 commented Mar 21, 2019

I had a concern that the issue was the custom implementation of the ConfigurationHandler that I was using, but I have just removed that, and I am still getting the same error.

@NickAcPT
Copy link
Contributor

I've had some problems like that when I tried to run my language server on Sublime (with the LSP plugin) and on IntelliJ. Sadly, I no longer have the logs.
Don't quote me on this, but I think it might be something related to static registration since the error doesn't happen for me on vscode.

@bjorkstromm
Copy link
Member

IIRC, I was able to reproduce using the Client bits in the OmniSharp.Extensions LSP library. I’ll have a look in the upcoming days.

@bjorkstromm
Copy link
Member

Did some debugging. It currently fails due to the fact that SynchronizationCapability implements generic interface ConnectedCapability<T> more than once. I am able to reproduce via unit tests by adding typeof(SynchronizationCapability) to ClientCapabilityProviderTests.

Will try to provide a fix in the upcoming days.

@gep13
Copy link
Contributor Author

gep13 commented Apr 3, 2019

@mholo65 nice one!

Any thoughts on why this works in VSCode, but not in Visual Studio?

@bjorkstromm
Copy link
Member

@gep13 I'd go with same theory as @NickAcPT regarding static and dynamic registrations.

@gep13
Copy link
Contributor Author

gep13 commented Apr 3, 2019

@mholo65 ah, sorry, missed that part!

bjorkstromm added a commit to bjorkstromm/csharp-language-server-protocol that referenced this issue Apr 3, 2019
@bjorkstromm bjorkstromm added the bug Something isn't working label Apr 3, 2019
@bjorkstromm
Copy link
Member

I managed to find a fix for this and submitted a PR #133. Tested it out with OmniSharp, and wasn't able to reproduce the bug anymore. Also tested OmniSharp with VSCode, and everything seemed to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants