Skip to content

Commit

Permalink
Fix extensionConfiguration/change type, respect authStatus from cody (#…
Browse files Browse the repository at this point in the history
…2623)

## Changes

1. Bumped cody commit to match the one from `jb-v7.1.x` branch
2. Fixed `"extensionConfiguration/change"` endpoint type - issue was
introduced
[there](8ea63fc)
3. For the sake of correctness I also added check of returned auth state
and if auth fails I set the token as invalid.

## Test plan

1. Run IDE
4. Remove all account in the cody settings
5. Login panel shoul appear
6. Sign in to enterprise account 
7. Make sure chat panel appears and in the account panel enterprise acc
is shown
8. Remove all account in the cody settings
9. Login panel should appear
10. Sign in to free dotcom account
11. Make sure chat panel appears and in the account panel free acc is
shown
  • Loading branch information
pkukielka authored Nov 12, 2024
1 parent 1fcaf83 commit 24160e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface _SubsetGeneratedCodyAgentServer {
@JsonRequest("extensionConfiguration/getSettingsSchema")
fun extensionConfiguration_getSettingsSchema(params: Null?): CompletableFuture<String>

@JsonNotification("extensionConfiguration/change")
@JsonRequest("extensionConfiguration/change")
fun extensionConfiguration_change(
params: ExtensionConfiguration
): CompletableFuture<ProtocolAuthStatus?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.intellij.openapi.project.ProjectManager
import com.intellij.util.AuthData
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.sourcegraph.cody.agent.CodyAgentService
import com.sourcegraph.cody.agent.protocol_generated.ProtocolAuthenticatedAuthStatus
import com.sourcegraph.cody.api.SourcegraphApiRequestExecutor
import com.sourcegraph.cody.api.SourcegraphApiRequests
import com.sourcegraph.cody.config.notification.AccountSettingChangeActionNotifier
Expand Down Expand Up @@ -212,8 +213,15 @@ class CodyAuthenticationManager :
ProjectManager.getInstance().openProjects.forEach { project ->
CodyAgentService.withAgentRestartIfNeeded(project) { agent ->
if (!project.isDisposed) {
agent.server.extensionConfiguration_change(ConfigUtil.getAgentConfiguration(project))
publisher(project).afterAction(AccountSettingChangeContext(accessTokenChanged = true))
agent.server
.extensionConfiguration_change(ConfigUtil.getAgentConfiguration(project))
.thenApply { authStatus ->
isTokenInvalid =
CompletableFuture.completedFuture(
authStatus !is ProtocolAuthenticatedAuthStatus)
publisher(project)
.afterAction(AccountSettingChangeContext(accessTokenChanged = true))
}
}
}
}
Expand All @@ -236,15 +244,21 @@ class CodyAuthenticationManager :
ProjectManager.getInstance().openProjects.forEach { project ->
CodyAgentService.withAgentRestartIfNeeded(project) { agent ->
if (!project.isDisposed) {
agent.server.extensionConfiguration_change(ConfigUtil.getAgentConfiguration(project))
if (serverUrlChanged || tierChanged || accountChanged) {
publisher(project)
.afterAction(
AccountSettingChangeContext(
serverUrlChanged = serverUrlChanged,
accountTierChanged = tierChanged,
accessTokenChanged = accountChanged))
}
agent.server
.extensionConfiguration_change(ConfigUtil.getAgentConfiguration(project))
.thenApply { authStatus ->
isTokenInvalid =
CompletableFuture.completedFuture(
authStatus !is ProtocolAuthenticatedAuthStatus)
if (serverUrlChanged || tierChanged || accountChanged) {
publisher(project)
.afterAction(
AccountSettingChangeContext(
serverUrlChanged = serverUrlChanged,
accountTierChanged = tierChanged,
accessTokenChanged = accountChanged))
}
}
}
}
}
Expand Down

0 comments on commit 24160e8

Please sign in to comment.