Skip to content
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

Fix internal error on quick project close & open #447

Merged
merged 7 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/com/sourcegraph/cody/SubscriptionTabUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sourcegraph.cody.agent.CodyAgentServer
import com.sourcegraph.cody.agent.protocol.GetFeatureFlag
import com.sourcegraph.cody.config.CodyAuthenticationManager
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit

data class SubscriptionTabPanelData(
val isDotcomAccount: Boolean,
Expand All @@ -28,7 +29,10 @@ fun fetchSubscriptionPanelData(
if (activeAccountType.isDotcomAccount()) {
ApplicationManager.getApplication().executeOnPooledThread {
val codyProFeatureFlag =
server.evaluateFeatureFlag(GetFeatureFlag.CodyProJetBrains).get() == true
server
.evaluateFeatureFlag(GetFeatureFlag.CodyProJetBrains)
.completeOnTimeout(false, 4, TimeUnit.SECONDS)
.get() == true
if (codyProFeatureFlag) {
val isCurrentUserPro = getIsCurrentUserPro(server) ?: false
result.complete(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sourcegraph/vcs/RepoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static String doReplacements(
.thenCompose(
agent ->
agent.getServer().convertGitCloneURLToCodebaseName(new CloneURL(cloneURL)))
.completeOnTimeout(/* value= */ null, /* timeout= */ 4, TimeUnit.SECONDS)
.completeOnTimeout(null, 4, TimeUnit.SECONDS)
.get();

if (codebaseName == null) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/com/sourcegraph/cody/agent/CodyAgentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class CodyAgentService(project: Project) : Disposable {
init {
onStartup { agent ->
agent.client.onNewMessage = Consumer { params ->
AgentChatSessionService.getInstance(project)
.getSession(params.id)
?.receiveMessage(params.message)
if (!project.isDisposed) {
AgentChatSessionService.getInstance(project)
.getSession(params.id)
?.receiveMessage(params.message)
}
}

AgentChatSessionService.getInstance(project).restoreAllSessions(agent)
if (!project.isDisposed) {
AgentChatSessionService.getInstance(project).restoreAllSessions(agent)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class EndOfTrialNotificationScheduler private constructor(val project: Project)

CodyAgentService.applyAgentOnBackgroundThread(project) { agent ->
val currentUserCodySubscription =
agent.server.getCurrentUserCodySubscription().get(4, TimeUnit.SECONDS)
agent.server
.getCurrentUserCodySubscription()
.completeOnTimeout(null, 4, TimeUnit.SECONDS)
.get()

if (currentUserCodySubscription == null) {
logger.debug("currentUserCodySubscription is null")
Expand All @@ -48,12 +51,15 @@ class EndOfTrialNotificationScheduler private constructor(val project: Project)
val codyProTrialEnded =
agent.server
.evaluateFeatureFlag(GetFeatureFlag.CodyProTrialEnded)
.get(4, TimeUnit.SECONDS) == true
.completeOnTimeout(false, 4, TimeUnit.SECONDS)
.get() == true

val useSscForCodySubscription =
agent.server
.evaluateFeatureFlag(GetFeatureFlag.UseSscForCodySubscription)
.get(4, TimeUnit.SECONDS) == true
.orTimeout(4, TimeUnit.SECONDS)
.completeOnTimeout(false, 4, TimeUnit.SECONDS)
.get() == true

showProperNotificationIfApplicable(
currentUserCodySubscription, codyProTrialEnded, useSscForCodySubscription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class CodyAutocompleteStatusService : CodyAutocompleteStatusListener, Disposable

override fun onCodyAutocompleteStatusReset(project: Project) {
ApplicationManager.getApplication().executeOnPooledThread {
val notify = didStatusChanged(project)
if (notify) {
updateCodyStatusBarIcons()
if (!project.isDisposed) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue - the same scenario (a quick open & close project) - this one is (almost) deterministic. Should not be a case anymore.

val notify = didStatusChanged(project)
if (notify) {
updateCodyStatusBarIcons()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.notification.NotificationType
import com.intellij.notification.impl.NotificationFullContent
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.sourcegraph.Icons
Expand Down Expand Up @@ -77,9 +76,7 @@ private constructor(title: String, content: String, shouldShowUpgradeOption: Boo
else -> CodyBundle.getString("UpgradeToCodyProNotification.title.explain")
}

ApplicationManager.getApplication().invokeLater {
UpgradeToCodyProNotification(title, content, shouldShowUpgradeOption).notify(project)
}
UpgradeToCodyProNotification(title, content, shouldShowUpgradeOption).notify(project)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrel: redundant invokeLater - notify handles the threading already.

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/icons/chat/newChat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/icons/chat/newChat_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading