Skip to content

Commit 089c12d

Browse files
committed
feat(RunTestUtil): add extension property for RangeMarker to retrieve TextRange
1 parent 7d71cc7 commit 089c12d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/observer/test/RunTestUtil.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView
1212
import com.intellij.execution.ui.ExecutionConsole
1313
import com.intellij.execution.ui.RunContentManager
1414
import com.intellij.openapi.application.runReadAction
15+
import com.intellij.openapi.editor.RangeMarker
1516
import com.intellij.openapi.project.Project
1617
import com.intellij.openapi.util.TextRange
1718
import com.intellij.openapi.vfs.VirtualFile
1819
import com.intellij.psi.search.GlobalSearchScope
19-
import com.intellij.refactoring.suggested.range
2020
import java.lang.reflect.Field
2121

2222
object RunTestUtil {
@@ -141,4 +141,18 @@ object RunTestUtil {
141141
return null
142142
}
143143
}
144-
}
144+
}
145+
146+
147+
val RangeMarker.range: TextRange?
148+
get() {
149+
if (!isValid) return null
150+
val start = startOffset
151+
val end = endOffset
152+
return if (start in 0..end) {
153+
TextRange(start, end)
154+
} else {
155+
// Probably a race condition had happened and range marker is invalidated
156+
null
157+
}
158+
}

0 commit comments

Comments
 (0)