I try to implement a language client with ILanguageClient in C#
- as I launch the project and open a cpp file, nothing kicks in
- breakpoints are disabled
I tried:
Added a config file to enable the trace, nothing happens either, no log gets created
in the .vs folder, I created VSWorkspaceSettings.json
it contains:
{
"c_cpp.trace.server": "Verbose"
}
I follow the instructions from microsoft
https://learn.microsoft.com/en-us/visualstudio/extensibility/adding-an-lsp-extension?view=vs-2019
Any help appreciated on making this work
here is the code
using Microsoft.VisualStudio.LanguageServer.Client;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace ClangdLSPConnector
{
public class BarContentDefinition
{
[Export]
[Name("c_cpp")]
[BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
internal static ContentTypeDefinition BarContentTypeDefinition;
[Export]
[FileExtension(".cpp")]
[ContentType("c_cpp")]
internal static FileExtensionToContentTypeDefinition BarFileExtensionDefinitionCpp;
[Export]
[FileExtension(".h")]
[ContentType("c_cpp")]
internal static FileExtensionToContentTypeDefinition BarFileExtensionDefinitionH;
}
[ContentType("c_cpp")]
[Export(typeof(ILanguageClient))]
class LSPLanguageClient : ILanguageClient
{
public string Name => "C/C++ Language Extension";
public IEnumerable<string> ConfigurationSections => null;
public object InitializationOptions => null;
public IEnumerable<string> FilesToWatch => null;
public bool ShowNotificationOnInitializeFailed => throw new NotImplementedException();
public event AsyncEventHandler<EventArgs> StartAsync;
public event AsyncEventHandler<EventArgs> StopAsync;
event AsyncEventHandler<EventArgs> ILanguageClient.StartAsync
{
add
{
throw new NotImplementedException();
}
remove
{
throw new NotImplementedException();
}
}
event AsyncEventHandler<EventArgs> ILanguageClient.StopAsync
{
add
{
throw new NotImplementedException();
}
remove
{
throw new NotImplementedException();
}
}
public async Task<Connection> ActivateAsync(CancellationToken token)
{
await Task.Yield();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "C:\\my\\path\\to\\server\\bin\\clangd.exe";
info.Arguments = "";
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;
}
public Task<InitializationFailureContext> OnServerInitializeFailedAsync(ILanguageClientInitializationInfo initializationState)
{
throw new NotImplementedException();
}
}
}