I am trying to implement the example of a LSP client: https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-an-lsp-extension?view=vs-2019#create-a-simple-language-client
When I use the code given on this page, I get an error.
1>A:\develop\Training\VSIXProject1\VSIXProject2\BarLanguageClient.cs(17,38,17,53): error CS0535: 'BarLanguageClient' does not implement interface member 'ILanguageClient.OnServerInitializeFailedAsync(ILanguageClientInitializationInfo)'
1>A:\develop\Training\VSIXProject1\VSIXProject2\BarLanguageClient.cs(17,38,17,53): error CS0535: 'BarLanguageClient' does not implement interface member 'ILanguageClient.ShowNotificationOnInitializeFailed'
It seems that ILanguageClient has changed. When I use the old version of Nuget package (https://www.nuget.org/packages/Microsoft.VisualStudio.LanguageServer.Client/16.10.1220/) it compiles. But when executing my ILanguageClient derived class is not created. Here is my Code:
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Utilities;
namespace VSIXProject2
{
[ContentType("reni")]
[Export(typeof(ILanguageClient))]
public class BarLanguageClient : ILanguageClient
{
public BarLanguageClient() { Debugger.Launch();}
public string Name => "Bar Language Extension";
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();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Server", @"MockLanguageServer.exe");
info.Arguments = "bar";
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 OnServerInitializeFailedAsync(Exception e)
{
return Task.CompletedTask;
}
public Task OnServerInitializedAsync()
{
return Task.CompletedTask;
}
}
}
This is my content type definition:
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Utilities;
namespace VSIXProject2
{
public class ReniContentDefinition
{
[Export]
[Name("reni")]
[BaseDefinition("code")]
internal static ContentTypeDefinition ReniContentTypeDefinition;
[Export]
[FileExtension(".reni")]
[ContentType("reni")]
internal static FileExtensionToContentTypeDefinition ReniFileExtensionDefinition;
}
}
When I press F5 on the VSIX-project another Visual Studio is openend with commandline parameters "/rootsuffix Exp". I select a folder that contains some files with extension ".reni". I open such a file. I would expect that my ILanguageClient-derived class is instantiated then. But the "Debugger.Launch()" I put inside the ctor is obviously not reached.
After some investigation I wonder if it is a problem with different versions of ILanguageClient. My current version of VS2019 is Version 16.11.7. I guess the Microsoft.VisualStudio.LanguageServer.Client where ILanguageClient is contained in also has this version. The nuget packages for Microsoft.VisualStudio.LanguageServer.Client are available for 16.10 and for 17.x. Not for 16.11.7.
I can't imagine how that can work at all.