-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
584 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/com/sourcegraph/cody/agent/protocol/GetRepoIdsParam.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class GetRepoIdsParam(val names: List<String>, val first: Int) |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/com/sourcegraph/cody/agent/protocol/GetRepoIdsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class GetRepoIdsResponse(val repos: List<Repo>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class Repo(val name: String, val id: String) |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/sourcegraph/cody/agent/protocol/util/ChatRemoteReposResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sourcegraph.cody.agent.protocol.util | ||
|
||
import com.sourcegraph.cody.agent.protocol.Repo | ||
|
||
data class ChatRemoteReposResponse(val remoteRepos: List<Repo>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/sourcegraph/cody/context/RemoteRepoUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.sourcegraph.cody.context | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.sourcegraph.cody.agent.CodyAgentService | ||
import com.sourcegraph.cody.agent.protocol.GetRepoIdsParam | ||
import com.sourcegraph.cody.agent.protocol.Repo | ||
import java.util.concurrent.CompletableFuture | ||
|
||
object RemoteRepoUtils { | ||
fun getRepository(project: Project, url: String): CompletableFuture<Repo?> { | ||
val result = CompletableFuture<List<Repo>>() | ||
CodyAgentService.applyAgentOnBackgroundThread(project) { agent -> | ||
try { | ||
agent.server.getRepoIds(GetRepoIdsParam(listOf(url), 1)).thenApply { | ||
result.complete(it?.repos) | ||
} | ||
} catch (e: Exception) { | ||
result.complete(null) | ||
} | ||
} | ||
return result.thenApply { it?.firstOrNull() } | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/kotlin/com/sourcegraph/cody/context/ui/AddRepositoryDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.sourcegraph.cody.context.ui | ||
|
||
import com.intellij.openapi.editor.event.DocumentListener | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.ui.DialogWrapper | ||
import com.intellij.openapi.ui.ValidationInfo | ||
import com.intellij.ui.TextFieldWithAutoCompletion | ||
import com.intellij.ui.TextFieldWithAutoCompletionListProvider | ||
import com.intellij.util.Alarm | ||
import com.sourcegraph.cody.config.DialogValidationUtils | ||
import com.sourcegraph.cody.context.RemoteRepoUtils | ||
import java.net.URL | ||
import java.util.concurrent.TimeUnit | ||
import javax.swing.JComponent | ||
import javax.swing.JLabel | ||
import javax.swing.JPanel | ||
import org.jetbrains.annotations.NotNull | ||
|
||
class AddRepositoryDialog(private val project: Project, private val addAction: (String) -> Unit) : | ||
DialogWrapper(project) { | ||
|
||
private val repoUrlInputField = TextFieldWithAutoCompletion.create(project, listOf(), false, null) | ||
|
||
init { | ||
init() | ||
title = "Add Remote Repository" | ||
setOKButtonText("Add") | ||
setValidationDelay(100) | ||
} | ||
|
||
override fun doValidateAll(): List<ValidationInfo> { | ||
fun validateNonEmpty() = | ||
DialogValidationUtils.custom(repoUrlInputField, "Remote repository URL cannot be empty") { | ||
repoUrlInputField.text.isNotBlank() | ||
} | ||
|
||
fun validateValidUrl() = | ||
DialogValidationUtils.custom(repoUrlInputField, "Remote repository URL must be valid") { | ||
val url = | ||
if (repoUrlInputField.text.startsWith("http")) repoUrlInputField.text | ||
else "http://" + repoUrlInputField.text | ||
runCatching { URL(url) }.isSuccess | ||
} | ||
|
||
fun validateRepoExists() = | ||
DialogValidationUtils.custom( | ||
repoUrlInputField, "Remote repository not found on the server") { | ||
val repo = | ||
RemoteRepoUtils.getRepository(project, repoUrlInputField.text) | ||
.completeOnTimeout(null, 2, TimeUnit.SECONDS) | ||
.get() | ||
repo != null | ||
} | ||
|
||
return listOfNotNull(validateNonEmpty() ?: validateValidUrl() ?: validateRepoExists()) | ||
} | ||
|
||
override fun getValidationThreadToUse(): Alarm.ThreadToUse { | ||
return Alarm.ThreadToUse.POOLED_THREAD | ||
} | ||
|
||
override fun doOKAction() { | ||
addAction(repoUrlInputField.text) | ||
close(OK_EXIT_CODE, true) | ||
} | ||
|
||
override fun createCenterPanel(): JComponent { | ||
val panel = JPanel() | ||
val label = JLabel("Repository URL: ") | ||
panel.add(label) | ||
|
||
// TODO: we can provide repository suggestions using `provider.setItems` method | ||
val completionProvider: TextFieldWithAutoCompletionListProvider<String> = | ||
object : TextFieldWithAutoCompletionListProvider<String>(listOf()) { | ||
@NotNull | ||
override fun getLookupString(@NotNull s: String): String { | ||
return s | ||
} | ||
} | ||
|
||
repoUrlInputField.setPreferredWidth(300) | ||
repoUrlInputField.installProvider(completionProvider) | ||
repoUrlInputField.addDocumentListener( | ||
object : DocumentListener { | ||
override fun documentChanged(event: com.intellij.openapi.editor.event.DocumentEvent) { | ||
initValidation() | ||
} | ||
}) | ||
|
||
panel.add((repoUrlInputField)) | ||
|
||
return panel | ||
} | ||
} |
Oops, something went wrong.