From e7909a5fdbe12bab046d353d0ae9892d17b62fe0 Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Sat, 29 Jun 2024 12:28:04 -0600 Subject: [PATCH] update interactive package --- Directory.Packages.props | 2 +- .../InteractiveTests.cs | 72 +++++++------------ src/IxMilia.Lisp.Interactive/LispKernel.cs | 2 +- 3 files changed, 26 insertions(+), 50 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5d62d61..43245d7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,7 @@ - + diff --git a/src/IxMilia.Lisp.Interactive.Test/InteractiveTests.cs b/src/IxMilia.Lisp.Interactive.Test/InteractiveTests.cs index 8c5d65b..e7d9527 100644 --- a/src/IxMilia.Lisp.Interactive.Test/InteractiveTests.cs +++ b/src/IxMilia.Lisp.Interactive.Test/InteractiveTests.cs @@ -20,9 +20,8 @@ public async Task GetCompletions() GetCodeAndPosition(markedCode, out var code, out var position); var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new RequestCompletions(code, GetLinePosition(position)), CancellationToken.None); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var completionsProduced = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var completionsProduced = commandResult.Events.OfType().Single(); var _ = completionsProduced.Completions.Where(c => c.DisplayText == "KERNEL:+/2").Single(); } @@ -33,9 +32,8 @@ public async Task GetHoverText() GetCodeAndPosition(markedCode, out var code, out var position); var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new RequestHoverText(code, GetLinePosition(position)), CancellationToken.None); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var hoverText = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var hoverText = commandResult.Events.OfType().Single(); Assert.Equal("()", hoverText.Content.Single().Value); } @@ -44,9 +42,8 @@ public async Task RequestValueInfosInitiallyProducesEmptySet() { var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name)); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var valueInfosProduced = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var valueInfosProduced = commandResult.Events.OfType().Single(); Assert.Empty(valueInfosProduced.ValueInfos); } @@ -55,13 +52,11 @@ public async Task RequestValueInfosReturnsOnlyWhatHasBeenSet() { var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode("(setf x 1)(setf y 2)")); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); + AssertNoErrors(commandResult.Events); commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name)); - events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var valueInfosProduced = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var valueInfosProduced = commandResult.Events.OfType().Single(); var valueInfos = valueInfosProduced.ValueInfos.Select(v => v.Name).ToArray(); Assert.Equal("X,Y", string.Join(",", valueInfos)); } @@ -71,13 +66,11 @@ public async Task RequestValueInfosDoesNotReportFunctionsOrMacros() { var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode("(setf x 1)(setf y 2)(defun some-function () ())(defmacro some-macro () ())")); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); + AssertNoErrors(commandResult.Events); commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name)); - events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var valueInfosProduced = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var valueInfosProduced = commandResult.Events.OfType().Single(); var valueInfos = valueInfosProduced.ValueInfos.Select(v => v.Name).ToArray(); Assert.Equal("X,Y", string.Join(",", valueInfos)); } @@ -91,13 +84,11 @@ public async Task RequestValueReturnsTheAppropriateValue(string mimeType, string { var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode("(setf x '(1 2 3))")); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); + AssertNoErrors(commandResult.Events); commandResult = await kernel.SendAsync(new RequestValue(valueName, mimeType: mimeType)); - events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var valueProduced = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var valueProduced = commandResult.Events.OfType().Single(); Assert.Equal(valueName, valueProduced.Name); Assert.Equal(mimeType, valueProduced.FormattedValue.MimeType); Assert.Equal(expectedResult, valueProduced.FormattedValue.Value); @@ -109,9 +100,8 @@ public async Task SubmitCodeProducesAResult() var code = "(+ 1 2)"; var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode(code)); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var returnValue = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var returnValue = commandResult.Events.OfType().Single(); Assert.Equal("3", returnValue.FormattedValues.Single(f => f.MimeType == "text/plain").Value); } @@ -121,9 +111,8 @@ public async Task SubmitCodeRedirectsStandardOut() var code = "(format t \"stdout\")"; var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode(code)); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var stdOut = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var stdOut = commandResult.Events.OfType().Single(); Assert.Equal("stdout", stdOut.FormattedValues.Single().Value); } @@ -133,9 +122,8 @@ public async Task SubmitCodeDoesNotReturnAnythingForNil() var code = "()"; var kernel = new LispKernel(); var commandResult = await kernel.SendAsync(new SubmitCode(code)); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - Assert.Empty(events.OfType()); + AssertNoErrors(commandResult.Events); + Assert.Empty(commandResult.Events.OfType()); } [Fact] @@ -144,13 +132,11 @@ public async Task SendValueSetsValueInKernel() var kernel = new LispKernel(); var command = new SendValue("x", null, new FormattedValue("application/json", "[1,2]")); var commandResult = await kernel.SendAsync(command); - var events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); + AssertNoErrors(commandResult.Events); commandResult = await kernel.SendAsync(new RequestValueInfos()); - events = GetEventList(commandResult.KernelEvents); - AssertNoErrors(events); - var valueInfos = events.OfType().Single(); + AssertNoErrors(commandResult.Events); + var valueInfos = commandResult.Events.OfType().Single(); var valueInfo = valueInfos.ValueInfos.Single(); Assert.Equal("X", valueInfo.Name); Assert.Equal("text/plain+summary", valueInfo.FormattedValue.MimeType); @@ -172,15 +158,5 @@ private static LinePosition GetLinePosition(LispSourcePosition position) { return new LinePosition(position.Line - 1, position.Column - 1); } - - private static IList GetEventList(IObservable observable) - { - var result = new List(); - observable.Subscribe(e => - { - result.Add(e); - }); - return result; - } } } diff --git a/src/IxMilia.Lisp.Interactive/LispKernel.cs b/src/IxMilia.Lisp.Interactive/LispKernel.cs index 0cf391b..a627cd2 100644 --- a/src/IxMilia.Lisp.Interactive/LispKernel.cs +++ b/src/IxMilia.Lisp.Interactive/LispKernel.cs @@ -34,7 +34,7 @@ public LispKernel() _host = new Lazy>(async () => { var writer = new ListeningTextWriter(line => _stdoutSubject.OnNext(line)); - var configuration = new LispHostConfiguration(output: writer); + var configuration = new LispHostConfiguration(output: writer, readerType: LispReaderType.NoReaderMacros); var host = await LispHost.CreateAsync(configuration); _suppressedValues = new HashSet(host.RootFrame.GetValues().Select(v => v.Item1.Value)); return host;