fix: apply insertion bug
This commit is contained in:
parent
69ddd88b67
commit
ceb92773e9
|
@ -0,0 +1,10 @@
|
|||
name: IntelliJ Test Standards
|
||||
version: 0.0.1
|
||||
schema: v1
|
||||
rules:
|
||||
- name: IntelliJ Test Standards
|
||||
rule: When writing tests for the IntelliJ plugin, use the mockk library for
|
||||
mocking. Prefer mockk's idiomatic syntax for creating and verifying mocks.
|
||||
Always structure tests with clear Arrange-Act-Assert patterns and use
|
||||
descriptive test names that indicate the scenario being tested.
|
||||
globs: "**/test/**/*.kt"
|
|
@ -1,5 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CommitMessageInspectionProfile">
|
||||
<profile version="1.0">
|
||||
<inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
|
|
|
@ -64,7 +64,7 @@ async function buildWithEsbuild() {
|
|||
format: "cjs",
|
||||
platform: "node",
|
||||
sourcemap: true,
|
||||
minify: true,
|
||||
minify: !esbuildOnly,
|
||||
treeShaking: true,
|
||||
loader: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
|
|
|
@ -64,6 +64,8 @@ export const gptEditPrompt: PromptTemplateFunction = (history, otherData) => {
|
|||
\`\`\`
|
||||
|
||||
The user's request is: "${otherData.userInput}"
|
||||
|
||||
DO NOT output any natural language, only output the code changes.
|
||||
|
||||
Here is the rewritten code:`);
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.github.continuedev.continueintellijextension.editor
|
|||
|
||||
import com.github.continuedev.continueintellijextension.Position
|
||||
import com.github.continuedev.continueintellijextension.Range
|
||||
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
|
||||
import com.github.continuedev.continueintellijextension.utils.toUriOrNull
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
|
@ -84,10 +83,12 @@ class EditorUtils(val editor: Editor) {
|
|||
// If no highlight, use the whole document as highlighted
|
||||
Triple("", editor.document.text, "")
|
||||
} else {
|
||||
val prefix = editor.document.getText(TextRange(0, rif.range.start.character))
|
||||
// Use the RangeInFileWithContents to get absolute offsets
|
||||
val startOffset = rif.getStartOffset(editor.document)
|
||||
val endOffset = rif.getEndOffset(editor.document)
|
||||
val prefix = editor.document.getText(TextRange(0, startOffset))
|
||||
val highlighted = rif.contents
|
||||
val suffix =
|
||||
editor.document.getText(TextRange(rif.range.end.character, editor.document.textLength))
|
||||
val suffix = editor.document.getText(TextRange(endOffset, editor.document.textLength))
|
||||
|
||||
// Remove the selection after processing
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
|
@ -107,11 +108,8 @@ class EditorUtils(val editor: Editor) {
|
|||
val virtualFile =
|
||||
FileDocumentManager.getInstance().getFile(editor.document) ?: return@runReadAction null
|
||||
|
||||
// Get the selection range and content
|
||||
// Get the selection range
|
||||
val selectionModel: SelectionModel = editor.selectionModel
|
||||
val selectedText = selectionModel.selectedText ?: ""
|
||||
|
||||
val document = editor.document
|
||||
val startOffset = selectionModel.selectionStart
|
||||
val endOffset = selectionModel.selectionEnd
|
||||
|
||||
|
@ -119,18 +117,12 @@ class EditorUtils(val editor: Editor) {
|
|||
return@runReadAction null
|
||||
}
|
||||
|
||||
val startLine = document.getLineNumber(startOffset)
|
||||
val endLine = document.getLineNumber(endOffset)
|
||||
|
||||
val startChar = startOffset - document.getLineStartOffset(startLine)
|
||||
val endChar = endOffset - document.getLineStartOffset(endLine)
|
||||
|
||||
return@runReadAction virtualFile.toUriOrNull()?.let {
|
||||
RangeInFileWithContents(
|
||||
it, Range(
|
||||
Position(startLine, startChar),
|
||||
Position(endLine, endChar)
|
||||
), selectedText
|
||||
RangeInFileWithContents.fromSelection(
|
||||
it,
|
||||
editor.document,
|
||||
startOffset,
|
||||
endOffset
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.github.continuedev.continueintellijextension.editor
|
||||
|
||||
import com.github.continuedev.continueintellijextension.Position
|
||||
import com.github.continuedev.continueintellijextension.Range
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.util.TextRange
|
||||
|
||||
/**
|
||||
* Represents a range of text in a file with its contents.
|
||||
* Provides utility methods for working with document positions and offsets.
|
||||
*/
|
||||
class RangeInFileWithContents(
|
||||
val filepath: String,
|
||||
val range: Range,
|
||||
val contents: String
|
||||
) {
|
||||
/**
|
||||
* Returns the absolute document offset for the start position
|
||||
*/
|
||||
fun getStartOffset(document: Document): Int {
|
||||
return document.getLineStartOffset(range.start.line) + range.start.character
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute document offset for the end position
|
||||
*/
|
||||
fun getEndOffset(document: Document): Int {
|
||||
return document.getLineStartOffset(range.end.line) + range.end.character
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Create a RangeInFileWithContents from a document selection
|
||||
*/
|
||||
fun fromSelection(
|
||||
filepath: String,
|
||||
document: Document,
|
||||
selectionStart: Int,
|
||||
selectionEnd: Int
|
||||
): RangeInFileWithContents {
|
||||
val startLine = document.getLineNumber(selectionStart)
|
||||
val endLine = document.getLineNumber(selectionEnd)
|
||||
|
||||
val startChar = selectionStart - document.getLineStartOffset(startLine)
|
||||
val endChar = selectionEnd - document.getLineStartOffset(endLine)
|
||||
|
||||
val selectedText = document.getText(
|
||||
TextRange(selectionStart, selectionEnd)
|
||||
)
|
||||
|
||||
return RangeInFileWithContents(
|
||||
filepath,
|
||||
Range(
|
||||
Position(startLine, startChar),
|
||||
Position(endLine, endChar)
|
||||
),
|
||||
selectedText
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.github.continuedev.continueintellijextension
|
||||
|
||||
import com.github.continuedev.continueintellijextension.editor.RangeInFileWithContents
|
||||
import com.google.gson.JsonElement
|
||||
|
||||
enum class ToastType(val value: String) {
|
||||
|
@ -56,12 +57,6 @@ data class RangeInFile(
|
|||
val range: Range
|
||||
)
|
||||
|
||||
data class RangeInFileWithContents(
|
||||
val filepath: String,
|
||||
val range: Range,
|
||||
val contents: String
|
||||
)
|
||||
|
||||
data class ControlPlaneSessionInfo(
|
||||
val accessToken: String,
|
||||
val account: Account
|
||||
|
|
Loading…
Reference in New Issue