Skip to content

Custom handler isn't being called #1615

@Yazwh0

Description

@Yazwh0

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))]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions