OmniSharp / OmniSharp/csharp-language-server-protocol

Custom handler isn't being called

Open
#1,615 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
638
Forks
109
Avg merge
1m
Merged PRs (30d)
2

Description

While handlers that handle 'known' events such as IHoverHandler work, I cannot find a way to get a custom handler to register.

In the code below, placing a breakpoint on server.WaitForExit shows that the handler isn't in the server.HandersManager's list of handlers. The other known handlers are registered and work well.

I cant find any errors in any output as to why this wouldn't register in the output, it appears to just silently fail.

What would cause the handler to be ignored? Shouldn't there be an error or warning somewhere?

using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace BitMagic.X16Debugger.LSP;

[Method("bitmagic/preview", Direction.ClientToServer)]
public class PreviewHandler : IJsonRpcRequestHandler<PreviewHandler.PreviewParameters, PreviewHandler.PreviewResult>
{
    public async Task<PreviewHandler.PreviewResult> Handle(PreviewHandler.PreviewParameters request, CancellationToken cancellationToken)
    {
        return new PreviewResult() { Content = "This is something" };
    }
    public class PreviewParameters : IRequest<PreviewResult>
    {
        public string Filename { get; set; } = "";
    }

    public class PreviewResult
    {
        public string Content { get; set; } = "";
    }
}
    public async Task Run()
    {
        var server = await LanguageServer.From(options =>
        {
            options.Services
                .AddSingleton<DocumentCache>()
                .AddSingleton<TokenDescriptionService>()
                .AddSingleton<ITokenDescriptionProvider, X16KernelDocumentation>()
                .AddSingleton<ProjectService>()
                .AddSingleton<ProjectBuilder>()
                .AddSingleton<ServiceManager>(e => new ServiceManager(getEmulator, e.GetService<IEmulatorLogger>()))
                .AddSingleton<FileChangeHandler>()
                .AddSingleton<PreviewHandler>()
                .AddSingleton<IEmulatorLogger, Logger>()
                ;

            options
                //.WithInput(new LoggingStreamWrapper(inputStream, "input"))
                //.WithOutput(new LoggingStreamWrapper(outputStream, "output"))
                .WithInput(inputStream)
                .WithOutput(outputStream)
                .WithHandler<HoverHandler>()
                .WithHandler<FileChangeHandler>()
                .WithHandler<PreviewHandler>()
                .WithLoggerFactory(new LogFactory())
                .ConfigureLogging(logging =>
                {
                    logging.SetMinimumLevel(LogLevel.Trace); // Trace logs everything
                })
                .OnInitialize(OnInitialise)
                ;
        });

        await server.WaitForExit;
    }
Image

The code generator appears to be working:

using OmniSharp.Extensions.JsonRpc;

[assembly: AssemblyJsonRpcHandlers(typeof(BitMagic.X16Debugger.LSP.PreviewHandler))]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the Run method's options.Services registration and the subsequent WithHandler() call; compare that path with the working HoverHandler registration and inspect the generated AssemblyJsonRpcHandlers attribute. Done means identifying why PreviewHandler is omitted and establishing whether the behavior should produce a warning or register the handler.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.