-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronize suggestions loading after the reconnect 2 #9142
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -110,6 +110,8 @@ final class SuggestionsHandler( | |||||||||||||||||||||
) | ||||||||||||||||||||||
context.system.eventStream | ||||||||||||||||||||||
.subscribe(self, classOf[Api.LibraryLoaded]) | ||||||||||||||||||||||
context.system.eventStream | ||||||||||||||||||||||
.subscribe(self, classOf[Api.BackgroundJobsStartedNotification]) | ||||||||||||||||||||||
context.system.eventStream.subscribe(self, classOf[FileDeletedEvent]) | ||||||||||||||||||||||
context.system.eventStream | ||||||||||||||||||||||
.subscribe(self, InitializedEvent.SuggestionsRepoInitialized.getClass) | ||||||||||||||||||||||
|
@@ -186,13 +188,29 @@ final class SuggestionsHandler( | |||||||||||||||||||||
|
||||||||||||||||||||||
case msg: Api.SuggestionsDatabaseSuggestionsLoadedNotification | ||||||||||||||||||||||
if state.isSuggestionLoadingRunning => | ||||||||||||||||||||||
state.suggestionLoadingQueue.enqueue(msg) | ||||||||||||||||||||||
logger.trace( | ||||||||||||||||||||||
"SuggestionsDatabaseSuggestionsLoadedNotification [shouldStartBackgroundProcessing={}].", | ||||||||||||||||||||||
state.shouldStartBackgroundProcessing | ||||||||||||||||||||||
) | ||||||||||||||||||||||
if (state.shouldStartBackgroundProcessing) { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this was the main source of the problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to properly synchronize the state of background notifications in runtime enso/engine/language-server/src/main/scala/org/enso/languageserver/search/SuggestionsHandler.scala Lines 317 to 326 in 35fdcd2
|
||||||||||||||||||||||
state.suggestionLoadingQueue.clear() | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
state.suggestionLoadingQueue.enqueue(msg) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
case msg: Api.SuggestionsDatabaseSuggestionsLoadedNotification => | ||||||||||||||||||||||
logger.debug( | ||||||||||||||||||||||
"Starting loading suggestions for library [{}].", | ||||||||||||||||||||||
msg.libraryName | ||||||||||||||||||||||
) | ||||||||||||||||||||||
context.become( | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change isn't strictly necessary since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we need to change the state before starting loading the suggestions |
||||||||||||||||||||||
initialized( | ||||||||||||||||||||||
projectName, | ||||||||||||||||||||||
graph, | ||||||||||||||||||||||
clients, | ||||||||||||||||||||||
state.suggestionLoadingRunning() | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
applyLoadedSuggestions(msg.suggestions) | ||||||||||||||||||||||
.onComplete { | ||||||||||||||||||||||
case Success(notification) => | ||||||||||||||||||||||
|
@@ -214,14 +232,6 @@ final class SuggestionsHandler( | |||||||||||||||||||||
) | ||||||||||||||||||||||
self ! SuggestionsHandler.SuggestionLoadingCompleted | ||||||||||||||||||||||
} | ||||||||||||||||||||||
context.become( | ||||||||||||||||||||||
initialized( | ||||||||||||||||||||||
projectName, | ||||||||||||||||||||||
graph, | ||||||||||||||||||||||
clients, | ||||||||||||||||||||||
state.suggestionLoadingRunning() | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
case msg: Api.SuggestionsDatabaseModuleUpdateNotification | ||||||||||||||||||||||
if state.isSuggestionUpdatesRunning => | ||||||||||||||||||||||
|
@@ -304,39 +314,65 @@ final class SuggestionsHandler( | |||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
case Api.BackgroundJobsStartedNotification() => | ||||||||||||||||||||||
self ! SuggestionLoadingCompleted | ||||||||||||||||||||||
context.become( | ||||||||||||||||||||||
initialized( | ||||||||||||||||||||||
projectName, | ||||||||||||||||||||||
graph, | ||||||||||||||||||||||
clients, | ||||||||||||||||||||||
state.backgroundProcessingStarted() | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
case GetSuggestionsDatabaseVersion => | ||||||||||||||||||||||
suggestionsRepo.currentVersion | ||||||||||||||||||||||
.map(GetSuggestionsDatabaseVersionResult) | ||||||||||||||||||||||
.pipeTo(sender()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
case GetSuggestionsDatabase => | ||||||||||||||||||||||
val responseAction = for { | ||||||||||||||||||||||
_ <- suggestionsRepo.clean | ||||||||||||||||||||||
version <- suggestionsRepo.currentVersion | ||||||||||||||||||||||
} yield GetSuggestionsDatabaseResult(version, Seq()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
responseAction.pipeTo(sender()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
val handlerAction = for { | ||||||||||||||||||||||
_ <- responseAction | ||||||||||||||||||||||
} yield SearchProtocol.InvalidateModulesIndex | ||||||||||||||||||||||
case CleanSuggestionsDatabase => | ||||||||||||||||||||||
if (state.isSuggestionLoadingRunning) stash() | ||||||||||||||||||||||
else { | ||||||||||||||||||||||
context.become( | ||||||||||||||||||||||
initialized( | ||||||||||||||||||||||
projectName, | ||||||||||||||||||||||
graph, | ||||||||||||||||||||||
clients, | ||||||||||||||||||||||
state.suggestionLoadingRunning() | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
for { | ||||||||||||||||||||||
_ <- suggestionsRepo.clean | ||||||||||||||||||||||
} yield { | ||||||||||||||||||||||
logger.trace( | ||||||||||||||||||||||
"CleanSuggestionsDatabase [{}].", | ||||||||||||||||||||||
state.suggestionLoadingQueue | ||||||||||||||||||||||
) | ||||||||||||||||||||||
state.suggestionLoadingQueue.clear() | ||||||||||||||||||||||
runtimeConnector ! Api.Request(Api.StartBackgroundProcessing()) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
case GetSuggestionsDatabase => | ||||||||||||||||||||||
val handler = context.system.actorOf( | ||||||||||||||||||||||
InvalidateModulesIndexHandler.props( | ||||||||||||||||||||||
RuntimeFailureMapper(contentRootManager), | ||||||||||||||||||||||
timeout, | ||||||||||||||||||||||
runtimeConnector | ||||||||||||||||||||||
runtimeConnector, | ||||||||||||||||||||||
self | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
handlerAction.pipeTo(handler) | ||||||||||||||||||||||
handler ! SearchProtocol.InvalidateModulesIndex | ||||||||||||||||||||||
|
||||||||||||||||||||||
sender() ! GetSuggestionsDatabaseResult(0, Seq()) | ||||||||||||||||||||||
|
||||||||||||||||||||||
context.become( | ||||||||||||||||||||||
initialized( | ||||||||||||||||||||||
projectName, | ||||||||||||||||||||||
graph, | ||||||||||||||||||||||
clients, | ||||||||||||||||||||||
state.backgroundProcessingStarted() | ||||||||||||||||||||||
state.backgroundProcessingStopped() | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -419,7 +455,8 @@ final class SuggestionsHandler( | |||||||||||||||||||||
InvalidateModulesIndexHandler.props( | ||||||||||||||||||||||
runtimeFailureMapper, | ||||||||||||||||||||||
timeout, | ||||||||||||||||||||||
runtimeConnector | ||||||||||||||||||||||
runtimeConnector, | ||||||||||||||||||||||
self | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
action.pipeTo(handler)(sender()) | ||||||||||||||||||||||
|
@@ -450,6 +487,7 @@ final class SuggestionsHandler( | |||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
case SuggestionLoadingCompleted => | ||||||||||||||||||||||
unstashAll() | ||||||||||||||||||||||
if (state.suggestionLoadingQueue.nonEmpty) { | ||||||||||||||||||||||
self ! state.suggestionLoadingQueue.dequeue() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since it is a request, I'd rather we name it
ClearSuggestionsDatabase