csharp-language-server-protocol icon indicating copy to clipboard operation
csharp-language-server-protocol copied to clipboard

Exception "No method by the name 'initialize' is found."

Open hahoyer opened this issue 6 months ago • 0 comments

When starting my languageserver from my extension I get an exception from "VS/IDE/TaskStatusCenter/RunningRegisteredTaskFailed":

            StreamJsonRpc.RemoteMethodNotFoundException: No method by the name 'initialize' is found.
            at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__154`1.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.LanguageServer.Client.JsonRpcExtensionMethods.<SendMethodRequestWithTelemetryAsync>d__0`2.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.LanguageServer.Client.RemoteLanguageClientInstance.<SendInitializeRequestAsync>d__115.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.LanguageServer.Client.RemoteLanguageClientInstance.<InitializeAsync>d__110.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.Threading.TplExtensions.<WithTimeout>d__5.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.LanguageServer.Client.RemoteLanguageClientInstance.<TrackTaskAsync>d__113.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            at Microsoft.VisualStudio.LanguageServer.Client.RemoteLanguageClientInstance.<ActivateLanguageClientAsync>d__122.MoveNext()

What does this message mean? For which class is the "initialize" method missing?

I use

  • omnisharp.extensions.languageserver 0.19.9
  • Visual Studio Extensibility Sdk and Visual Studio Extensibility Framework 17.10.2084
  • VS2022
  • Nerdbank-Streams (as suggested)

Here is my language-server-provider:

using System.Diagnostics;
using System.IO.Pipelines;
using JetBrains.Annotations;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.LanguageServer;
using Microsoft.VisualStudio.RpcContracts.LanguageServerProvider;
using Nerdbank.Streams;
using ReniLSP;

namespace Reni.LSPVSIX;

#pragma warning disable VSEXTPREVIEW_LSP
[VisualStudioContribution]
[UsedImplicitly]
public sealed class ReniLanguageServerProvider : LanguageServerProvider
{
	[UsedImplicitly]
	Task? ServerPipeTask;

	public ReniLanguageServerProvider
		(ExtensionCore container, VisualStudioExtensibility extensibilityObject, TraceSource traceSource)
		: base(container, extensibilityObject) { }

	public override LanguageServerProviderConfiguration LanguageServerProviderConfiguration =>
		new("Reni Language Server",
			new[]
			{
				DocumentFilter.FromDocumentType(Constants.LanguageName),
			});

	// Activate the language server and return a duplex pipe that communicates with the server. 
	public override Task<IDuplexPipe?> CreateServerConnectionAsync(CancellationToken token)
	{
		var (pipeToServer, pipeToVS) = FullDuplexStream.CreatePair();

		ServerPipeTask = Task.Run(
			() => MainContainer.RunServer(pipeToVS.UsePipeReader(), pipeToServer.UsePipeWriter())
			, token
		);

		return Task.FromResult<IDuplexPipe?>(new DuplexPipe(pipeToServer.UsePipeReader(), pipeToVS.UsePipeWriter()));
	}

	protected override void Dispose(bool isDisposing)
	{
		if(isDisposing)
			ServerPipeTask?.Dispose();
		base.Dispose(isDisposing);
	}

	public override Task OnServerInitializationResultAsync
	(
		ServerInitializationResult startState, LanguageServerInitializationFailureInfo? initializationFailureInfo
		, CancellationToken cancellationToken
	) =>
		// Method called when server activation was completed successfully or failed, denoted by "startState".
		Task.CompletedTask;
}

hahoyer avatar Aug 13 '24 09:08 hahoyer