Skip to content

Commit

Permalink
refactor: start marking functions which require EDT
Browse files Browse the repository at this point in the history
  • Loading branch information
lppedd committed Apr 10, 2020
1 parent 4affc30 commit 24309e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/com/github/lppedd/cc/CCExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.lppedd.cc

import com.github.lppedd.cc.annotation.RequireEDT
import com.intellij.codeInsight.AutoPopupController
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.lookup.impl.LookupImpl
Expand Down Expand Up @@ -82,11 +83,13 @@ internal inline fun Editor.insertStringAtCaret(string: String) {
internal inline fun Editor.getTemplateState(): TemplateState? =
TemplateManagerImpl.getTemplateState(this)

@RequireEDT
internal fun Editor.getCurrentLineRange(): TextRange {
val mainCaretLine = EditorUtil.calcCaretLineRange(this).first.line
return document.getLineRange(mainCaretLine)
}

@RequireEDT
internal fun Editor.getCurrentLine(): CharSequence {
val (start, end) = getCurrentLineRange()
return document.immutableCharSequence.subSequence(start, end)
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/github/lppedd/cc/annotation/RequireEDT.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.lppedd.cc.annotation

/**
* @author Edoardo Luppi
*/
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
annotation class RequireEDT

0 comments on commit 24309e1

Please sign in to comment.