Reload module's sources when LS reloads buffer (#4083)

LS needs to notify runtime that modules' sources need to be reloaded from FS, once its own buffer has been reloaded as well.

# Important Notes
Discovered during integration of https://github.com/enso-org/enso/pull/4050.
The test illustrates the problem if we don't reload module's sources - the sources essentially become stale even though they have changed.
This commit is contained in:
Hubert Plociniczak 2023-01-26 20:07:54 +01:00 committed by GitHub
parent 1097c41297
commit ad6419f204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 298 additions and 164 deletions

View File

@ -254,6 +254,7 @@ class CollaborativeBuffer(
inMemoryBuffer: Boolean
): Receive = {
case ReadTextualFileResult(Right(file)) =>
timeoutCancellable.cancel()
val buffer = Buffer(file.path, file.content, inMemoryBuffer)
// Notify *all* clients about the new buffer
@ -265,8 +266,10 @@ class CollaborativeBuffer(
oldBuffer.version.toHexString,
buffer.version.toHexString
)
runtimeConnector ! Api.Request(
Api.SetModuleSourcesNotification(file.path, file.content)
)
clients.values.foreach { _.rpcController ! TextDidChange(List(change)) }
timeoutCancellable.cancel()
unstashAll()
replyTo ! ReloadedBuffer(path)
context.become(
@ -631,7 +634,7 @@ class CollaborativeBuffer(
Right(OpenFileResult(buffer, Some(cap)))
)
runtimeConnector ! Api.Request(
Api.OpenFileNotification(file.path, file.content)
Api.SetModuleSourcesNotification(file.path, file.content)
)
context.become(
collaborativeEditing(

View File

@ -88,7 +88,7 @@ class FileNotificationsTest extends BaseServerTest with FlakySpec {
// 4
runtimeConnectorProbe.expectMsg(
Api.Request(
Api.OpenFileNotification(file("foo.txt"), "123456789")
Api.SetModuleSourcesNotification(file("foo.txt"), "123456789")
)
)

View File

@ -94,8 +94,8 @@ object Runtime {
name = "getComponentGroupsResponse"
),
new JsonSubTypes.Type(
value = classOf[Api.OpenFileNotification],
name = "openFileNotification"
value = classOf[Api.SetModuleSourcesNotification],
name = "setModuleSourcesNotification"
),
new JsonSubTypes.Type(
value = classOf[Api.EditFileNotification],
@ -1289,13 +1289,12 @@ object Runtime {
*/
final case class InvalidStackItemError(contextId: ContextId) extends Error
/** A notification sent to the server about switching a file to literal
* contents.
/** A notification sent to the server about setting module's sources to literal contents.
*
* @param path the file being moved to memory.
* @param contents the current file contents.
* @param contents the current module's contents.
*/
final case class OpenFileNotification(
final case class SetModuleSourcesNotification(
path: File,
contents: String
) extends ApiRequest
@ -1303,7 +1302,7 @@ object Runtime {
/** @inheritdoc */
override def toLogString(shouldMask: Boolean): String =
"OpenFileNotification(" +
"SetModuleSourcesNotification(" +
s"path=${MaskedPath(path.toPath).toLogString(shouldMask)}," +
s"contents=${MaskedString(contents).toLogString(shouldMask)}," +
")"

View File

@ -19,12 +19,12 @@ import org.enso.polyglot.runtime.Runtime$Api$ExecutionFailed;
import org.enso.polyglot.runtime.Runtime$Api$ExpressionUpdates;
import org.enso.polyglot.runtime.Runtime$Api$InitializedNotification;
import org.enso.polyglot.runtime.Runtime$Api$MethodPointer;
import org.enso.polyglot.runtime.Runtime$Api$OpenFileNotification;
import org.enso.polyglot.runtime.Runtime$Api$PushContextRequest;
import org.enso.polyglot.runtime.Runtime$Api$PushContextResponse;
import org.enso.polyglot.runtime.Runtime$Api$Request;
import org.enso.polyglot.runtime.Runtime$Api$Response;
import org.enso.polyglot.runtime.Runtime$Api$SetExpressionValueNotification;
import org.enso.polyglot.runtime.Runtime$Api$SetModuleSourcesNotification;
import org.enso.polyglot.runtime.Runtime$Api$StackItem$ExplicitCall;
import org.enso.polyglot.runtime.Runtime$Api$StackItem$LocalCall;
import org.enso.text.editing.model;
@ -196,7 +196,7 @@ public class IncrementalUpdatesTest {
);
// Open the new file
context.send(
Request(new Runtime$Api$OpenFileNotification(mainFile, contents))
Request(new Runtime$Api$SetModuleSourcesNotification(mainFile, contents))
);
assertTrue("No reply", context.receiveNone().isEmpty());

View File

@ -111,7 +111,7 @@ class BuiltinTypesTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -121,7 +121,7 @@ class RuntimeAsyncCommandsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -182,7 +182,7 @@ class RuntimeAsyncCommandsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -222,7 +222,7 @@ class RuntimeComponentsTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveOne shouldEqual None
@ -316,7 +316,7 @@ class RuntimeComponentsTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveOne shouldEqual None

View File

@ -135,7 +135,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -221,7 +221,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -302,7 +302,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -371,7 +371,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -456,7 +456,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -532,7 +532,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -686,7 +686,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -781,7 +781,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -872,7 +872,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -977,7 +977,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1098,7 +1098,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1226,7 +1226,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1340,7 +1340,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1441,7 +1441,7 @@ class RuntimeErrorsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -119,7 +119,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -166,7 +166,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -219,7 +219,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -281,7 +281,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -343,7 +343,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -402,7 +402,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -459,7 +459,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -517,7 +517,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -584,7 +584,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -646,7 +646,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -705,7 +705,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -767,7 +767,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -827,7 +827,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -885,7 +885,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -956,7 +956,7 @@ class RuntimeInstrumentTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -346,7 +346,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -467,7 +467,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -523,7 +523,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -628,10 +628,10 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
context.send(Api.Request(Api.OpenFileNotification(aFile, aCode)))
context.send(Api.Request(Api.SetModuleSourcesNotification(aFile, aCode)))
context.receiveNone shouldEqual None
// push main
@ -714,7 +714,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -773,7 +773,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -836,7 +836,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -901,7 +901,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -962,7 +962,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1030,9 +1030,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1166,9 +1166,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1258,7 +1258,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1356,7 +1356,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1453,7 +1453,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1740,7 +1740,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1954,9 +1954,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2008,9 +2008,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2056,8 +2056,8 @@ class RuntimeServerTest
// Create a new file
val mainFile = context.writeMain(code)
// Open the new file
context.send(Api.Request(Api.OpenFileNotification(mainFile, code)))
// Set sources for the module
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
@ -2128,8 +2128,8 @@ class RuntimeServerTest
// Create a new file
val mainFile = context.writeMain(code)
// Open the new file
context.send(Api.Request(Api.OpenFileNotification(mainFile, code)))
// Set sources for the module
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
@ -2169,7 +2169,7 @@ class RuntimeServerTest
)
// Re-open the the file and apply the same operation
context.send(Api.Request(Api.OpenFileNotification(mainFile, code)))
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
@ -2211,8 +2211,8 @@ class RuntimeServerTest
// Create a new file
val mainFile = context.writeMain(code)
// Open the new file
context.send(Api.Request(Api.OpenFileNotification(mainFile, code)))
// Set sources for the module
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
// Push new item on the stack to trigger the re-execution
@ -2271,9 +2271,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, context.Main.code))
Api.Request(Api.SetModuleSourcesNotification(mainFile, context.Main.code))
)
context.receiveNone shouldEqual None
@ -2380,8 +2380,8 @@ class RuntimeServerTest
// Create a new file
val mainFile = context.writeMain(code)
// Open the new file
context.send(Api.Request(Api.OpenFileNotification(mainFile, code)))
// Set sources for the module
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
@ -2449,6 +2449,136 @@ class RuntimeServerTest
context.consumeOut shouldEqual List()
}
it should "send reload file notifications when file is restored" in {
val contextId = UUID.randomUUID()
val requestId = UUID.randomUUID()
val moduleName = "Enso_Test.Test.Main"
val newline = System.lineSeparator()
context.send(Api.Request(requestId, Api.CreateContextRequest(contextId)))
context.receive shouldEqual Some(
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
def template(text: String) =
s"""from Standard.Base.Data.Numbers import Number
|import Standard.Base.IO
|
|main = IO.println "${text}"
|""".stripMargin.linesIterator.mkString("\n")
val code = template("I'm a file!")
// Create a new file
val mainFile = context.writeMain(code)
// Set sources for the module
context.send(Api.Request(Api.SetModuleSourcesNotification(mainFile, code)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
// Push new item on the stack to trigger the re-execution
context.send(
Api.Request(
requestId,
Api.PushContextRequest(
contextId,
Api.StackItem
.ExplicitCall(
Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "main"),
None,
Vector()
)
)
)
)
context.receiveNIgnorePendingExpressionUpdates(
2
) should contain theSameElementsAs Seq(
Api.Response(requestId, Api.PushContextResponse(contextId)),
context.executionComplete(contextId)
)
context.consumeOut shouldEqual List("I'm a file!")
/*
Modify the file:
"""from Standard.Base.Data.Numbers import Number
|import Standard.Base.IO
|
|Number.lucky = 42
|
|main = IO.println "I'm a modified!"
|""".stripMargin.linesIterator.mkString("\n")
*/
context.send(
Api.Request(
Api.EditFileNotification(
mainFile,
Seq(
TextEdit(
model.Range(model.Position(3, 25), model.Position(3, 29)),
"modified"
),
TextEdit(
model.Range(model.Position(3, 0), model.Position(3, 0)),
s"Number.lucky = 42$newline$newline"
)
),
execute = true
)
)
)
context.receiveNIgnoreExpressionUpdates(
1
) should contain theSameElementsAs Seq(
context.executionComplete(contextId)
)
context.consumeOut shouldEqual List("I'm a modified!")
// Simulate file update in FS
val prompt = "I'm a foo"
context.writeMain(template(prompt))
context.send(
Api.Request(requestId, Api.RecomputeContextRequest(contextId, None))
)
context.receiveNIgnorePendingExpressionUpdates(
2
) should contain theSameElementsAs Seq(
Api.Response(requestId, Api.RecomputeContextResponse(contextId)),
context.executionComplete(contextId)
)
// Lack of API.SetModuleSourcesNotification illustrating the fact that
// module sources haven't been updated resulting in the old result
context.consumeOut shouldEqual List("I'm a modified!")
context.send(
Api.Request(
Api.SetModuleSourcesNotification(
mainFile,
template(prompt)
)
)
)
context.send(
Api.Request(requestId, Api.RecomputeContextRequest(contextId, None))
)
context.receiveNIgnorePendingExpressionUpdates(
2
) should contain theSameElementsAs Seq(
Api.Response(requestId, Api.RecomputeContextResponse(contextId)),
context.executionComplete(contextId)
)
// API.SetModuleSourcesNotification triggers reloading of module sources
context.consumeOut shouldEqual List(prompt)
// Close the file
context.send(Api.Request(Api.CloseFileNotification(mainFile)))
context.receiveNone shouldEqual None
context.consumeOut shouldEqual List()
}
it should "recompute expressions without invalidation" in {
val contents = context.Main.code
val mainFile = context.writeMain(contents)
@ -2462,9 +2592,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2512,9 +2642,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2568,9 +2698,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2625,9 +2755,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2671,9 +2801,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2724,9 +2854,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2784,9 +2914,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2854,9 +2984,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2932,9 +3062,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3012,9 +3142,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3092,9 +3222,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3187,9 +3317,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3248,9 +3378,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3308,9 +3438,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3373,9 +3503,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3442,9 +3572,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3504,9 +3634,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3555,9 +3685,9 @@ class RuntimeServerTest
Api.Response(requestId, Api.CreateContextResponse(contextId))
)
// Open the new file
// Set sources for the module
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3608,7 +3738,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(
Api.OpenFileNotification(mainFile, contents)
Api.SetModuleSourcesNotification(mainFile, contents)
)
)
context.receiveNone shouldEqual None
@ -3725,7 +3855,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3779,7 +3909,7 @@ class RuntimeServerTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -218,7 +218,7 @@ class RuntimeStdlibTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveOne shouldEqual None

View File

@ -119,7 +119,7 @@ class RuntimeSuggestionUpdatesTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, code))
Api.Request(Api.SetModuleSourcesNotification(mainFile, code))
)
context.receiveNone shouldEqual None
@ -746,7 +746,7 @@ class RuntimeSuggestionUpdatesTest
// open file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -927,11 +927,11 @@ class RuntimeSuggestionUpdatesTest
// open files
context.send(
Api.Request(Api.OpenFileNotification(mainFile, mainCode))
Api.Request(Api.SetModuleSourcesNotification(mainFile, mainCode))
)
context.receiveNone shouldEqual None
context.send(
Api.Request(Api.OpenFileNotification(aFile, aCode))
Api.Request(Api.SetModuleSourcesNotification(aFile, aCode))
)
context.receiveNone shouldEqual None

View File

@ -275,7 +275,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -294,7 +294,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -393,7 +393,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -412,7 +412,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -530,7 +530,7 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -538,7 +538,7 @@ class RuntimeVisualizationsTest
)
context.receiveNone shouldEqual None
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -657,7 +657,7 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -665,7 +665,7 @@ class RuntimeVisualizationsTest
)
context.receiveNone shouldEqual None
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -784,7 +784,7 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -792,7 +792,7 @@ class RuntimeVisualizationsTest
)
context.receiveNone shouldEqual None
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -987,12 +987,12 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -1114,12 +1114,12 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -1259,7 +1259,7 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -1267,7 +1267,7 @@ class RuntimeVisualizationsTest
)
context.receiveNone shouldEqual None
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1366,12 +1366,12 @@ class RuntimeVisualizationsTest
// open files
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -1515,7 +1515,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1579,7 +1579,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1674,7 +1674,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1752,7 +1752,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1844,7 +1844,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
visualisationCode
)
@ -1863,7 +1863,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -1972,7 +1972,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2062,7 +2062,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2176,7 +2176,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2275,7 +2275,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2353,7 +2353,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.Visualisation.code
)
@ -2372,7 +2372,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2479,7 +2479,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.AnnotatedVisualisation.code
)
@ -2498,7 +2498,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2651,7 +2651,7 @@ class RuntimeVisualizationsTest
context.send(
Api.Request(
Api.OpenFileNotification(
Api.SetModuleSourcesNotification(
visualisationFile,
context.AnnotatedVisualisation.code
)
@ -2670,7 +2670,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2830,7 +2830,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -2920,7 +2920,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3014,7 +3014,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None
@ -3117,7 +3117,7 @@ class RuntimeVisualizationsTest
// Open the new file
context.send(
Api.Request(Api.OpenFileNotification(mainFile, contents))
Api.Request(Api.SetModuleSourcesNotification(mainFile, contents))
)
context.receiveNone shouldEqual None

View File

@ -46,7 +46,8 @@ object CommandFactory {
case payload: Api.RenameProject =>
new RenameProjectCmd(request.requestId, payload)
case payload: Api.OpenFileNotification => new OpenFileCmd(payload)
case payload: Api.SetModuleSourcesNotification =>
new SetModuleSourcesCmd(payload)
case payload: Api.CloseFileNotification => new CloseFileCmd(payload)
case payload: Api.EditFileNotification => new EditFileCmd(payload)
case payload: Api.SetExpressionValueNotification =>

View File

@ -5,11 +5,12 @@ import org.enso.polyglot.runtime.Runtime.Api
import scala.concurrent.{ExecutionContext, Future}
/** A command that opens a file.
/** A command that sets sources for the module..
*
* @param request a request for a service
*/
class OpenFileCmd(request: Api.OpenFileNotification) extends Command(None) {
class SetModuleSourcesCmd(request: Api.SetModuleSourcesNotification)
extends Command(None) {
/** @inheritdoc */
override def execute(implicit