private static void Main() { Log.WriteLine("Plugin host started"); var nvim = new NvimAPI(Console.OpenStandardOutput(), Console.OpenStandardInput()); nvim.OnUnhandledRequest += (sender, request) => { // Load the plugin and get the handler asynchronously Task.Run(() => { var handler = GetPluginHandler(nvim, request.MethodName); if (handler == null) { var error = $"Could not find request handler for {request.MethodName}"; request.SendResponse(null, error); Log.WriteLine(error); return; } Log.WriteLine($"Loaded handler for \"{request.MethodName}\""); try { var result = handler(request.Arguments); request.SendResponse(result); } catch (Exception exception) { request.SendResponse(null, exception); } }); }; nvim.OnUnhandledNotification += (sender, notification) => { // Load the plugin and get the handler asynchronously Task.Run(() => { GetPluginHandler(nvim, notification.MethodName) ?.Invoke(notification.Arguments); }); }; nvim.RegisterHandler("poll", args => "ok"); nvim.RegisterHandler("specs", args => { var slnFilePath = (string)args.First(); var pluginType = GetPluginFromSolutionPath(slnFilePath); return(pluginType == null ? null : PluginHost.GetPluginSpecs(pluginType)); }); nvim.WaitForDisconnect(); Log.WriteLine("Plugin host stopping"); }
public async Task TestCallAndReply() { var api = new NvimAPI(); api.RegisterHandler("client-call", args => { CollectionAssert.AreEqual(new[] { 1L, 2L, 3L }, args); return(new[] { 4, 5, 6 }); }); var objects = await api.GetApiInfo(); var channelID = (long)objects.First(); await api.Command( $"let g:result = rpcrequest({channelID}, 'client-call', 1, 2, 3)"); var result = (object[])await api.GetVar("result"); CollectionAssert.AreEqual(new[] { 4L, 5L, 6L }, result); }
internal void Register(NvimAPI nvim) => nvim.RegisterHandler(HandlerName, Handler);