-
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.
initial scaffolding for inline edits
This code is WIP and is being pushed up to the branch so Olaf can play with it Current state is that it should be making successful roundtrips now, but is not robust yet, and the UI and editing are not wired up.
- Loading branch information
1 parent
67c6910
commit e300708
Showing
39 changed files
with
1,000 additions
and
57 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/sourcegraph/cody/CodyFileDocumentManagerListener.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,19 @@ | ||
package com.sourcegraph.cody | ||
|
||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.fileEditor.FileDocumentManagerListener | ||
import com.intellij.openapi.project.Project | ||
import com.sourcegraph.cody.agent.CodyAgentService | ||
import com.sourcegraph.cody.agent.protocol.ProtocolTextDocument | ||
|
||
class CodyFileDocumentManagerListener(val project: Project) : FileDocumentManagerListener { | ||
|
||
override fun beforeDocumentSaving(document: Document) { | ||
CodyAgentService.applyAgentOnBackgroundThread(project) { agent -> | ||
FileDocumentManager.getInstance().getFile(document)?.path?.let { path -> | ||
agent.server.textDocumentDidSave(ProtocolTextDocument.fromPath(path)) | ||
} | ||
} | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/sourcegraph/cody/agent/protocol/ClientCapabilities.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,10 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class ClientCapabilities( | ||
var completions: String? = null, | ||
var chat: String? = null, | ||
var git: String? = null, | ||
var progressBars: String? = null, | ||
var edit: String? = null, | ||
var codeLenses: String? = null, | ||
) |
6 changes: 4 additions & 2 deletions
6
src/main/kotlin/com/sourcegraph/cody/agent/protocol/ClientInfo.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
import com.sourcegraph.cody.agent.ExtensionConfiguration | ||
import java.net.URI | ||
|
||
data class ClientInfo( | ||
var version: String, | ||
var workspaceRootUri: String, | ||
var extensionConfiguration: ExtensionConfiguration? = null | ||
var workspaceRootUri: URI, | ||
var extensionConfiguration: ExtensionConfiguration? = null, | ||
var capabilities: ClientCapabilities? = null, | ||
) { | ||
val name = "JetBrains" | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/sourcegraph/cody/agent/protocol/CodyTaskState.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,20 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
enum class CodyTaskState(val value: Int) { | ||
idle(1), | ||
working(2), | ||
inserting(3), | ||
applying(4), | ||
formatting(5), | ||
applied(6), | ||
finished(7), | ||
error(8), | ||
pending(9) | ||
} | ||
|
||
val CodyTaskState.isTerminal | ||
get() = when(this) { | ||
CodyTaskState.finished, | ||
CodyTaskState.error -> true | ||
else -> false | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/sourcegraph/cody/agent/protocol/DisplayCodeLensParams.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 | ||
|
||
data class DisplayCodeLensParams( | ||
val uri: String, | ||
val codeLenses: List<ProtocolCodeLens>) |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/com/sourcegraph/cody/agent/protocol/EditTask.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 EditTask(val id: String, val state: CodyTaskState) |
13 changes: 12 additions & 1 deletion
13
src/main/kotlin/com/sourcegraph/cody/agent/protocol/Position.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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class Position(val line: Int, val character: Int) | ||
import com.intellij.openapi.editor.Document | ||
|
||
data class Position(val line: Int, val character: Int) { | ||
|
||
/** Return zero-based offset of this position in the document. */ | ||
fun toOffset(document: Document): Int { | ||
val lineStartOffset = document.getLineStartOffset(line) | ||
return lineStartOffset + character | ||
} | ||
|
||
} | ||
|
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/sourcegraph/cody/agent/protocol/ProtocolCodeLens.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,7 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class ProtocolCodeLens( | ||
val range: Range, | ||
val command: ProtocolCommand? = null, | ||
val isResolved: Boolean | ||
) |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/sourcegraph/cody/agent/protocol/ProtocolCommand.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,8 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class ProtocolCommand( | ||
val title: String, | ||
val command: String, | ||
val tooltip: String? = null, | ||
val arguments: List<*> | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
package com.sourcegraph.cody.agent.protocol | ||
|
||
data class Range(val start: Position, val end: Position) | ||
import com.intellij.openapi.editor.Document | ||
|
||
data class Range(val start: Position, val end: Position) { | ||
|
||
fun toOffsets(document: Document): Pair<Int, Int> { | ||
return Pair(start.toOffset(document), end.toOffset(document)) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/com/sourcegraph/cody/agent/protocol/TextDocumentEditOptions.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 TextDocumentEditOptions(val undoStopBefore: Boolean, val undoStopAfter: Boolean) |
Oops, something went wrong.