Skip to content

Commit

Permalink
Merge pull request #187 from devchat-ai/fix-docstring-indent
Browse files Browse the repository at this point in the history
Fix docstring indent
  • Loading branch information
pplam authored Jul 4, 2024
2 parents 1a1537d + 790931f commit b5e84d3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/kotlin/ai/devchat/plugin/hints/DocStringCVProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import ai.devchat.common.DevChatBundle
import ai.devchat.storage.CONFIG
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.editor.Editor
import com.intellij.psi.*
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import javax.swing.Icon

class DocStringCVProvider : ChatCVProviderBase() {
override fun buildPayload(editor: Editor, element: PsiElement): JSONObject {
editor.selectionModel.setSelection(element.startOffset, null, element.endOffset)
val document = editor.document
val startLine = document.getLineNumber(element.startOffset)
val lineStartOffset = document.getLineStartOffset(startLine)
val startOffset = if (document.text.substring(lineStartOffset, element.startOffset).isBlank()) {
lineStartOffset
} else {
element.startOffset
}
editor.selectionModel.setSelection(startOffset, null, element.endOffset)
return JSONObject(mapOf("message" to "/docstring"))
}

Expand Down

0 comments on commit b5e84d3

Please sign in to comment.