From a2620e1e1545378c1edc43862048e9976b0ef6a6 Mon Sep 17 00:00:00 2001 From: Arkadii Sapozhnikov Date: Wed, 3 Jan 2024 14:50:22 +0100 Subject: [PATCH] create EditorService.kt --- .../testspark/services/CoverageVisualisationService.kt | 4 ++-- .../research/testspark/services/EditorService.kt | 9 +++++++++ .../research/testspark/services/ProjectContextService.kt | 3 --- .../research/testspark/services/ReportLockingService.kt | 2 +- .../testspark/services/TestCaseDisplayService.kt | 6 +++--- 5 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/org/jetbrains/research/testspark/services/EditorService.kt diff --git a/src/main/kotlin/org/jetbrains/research/testspark/services/CoverageVisualisationService.kt b/src/main/kotlin/org/jetbrains/research/testspark/services/CoverageVisualisationService.kt index 50c0e02b1..170e1aad3 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/services/CoverageVisualisationService.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/services/CoverageVisualisationService.kt @@ -95,7 +95,7 @@ class CoverageVisualisationService(private val project: Project) { testReport: Report, ) { currentHighlightedData = - HighlightedData(linesToCover, selectedTests, testReport, project.service().editor!!) + HighlightedData(linesToCover, selectedTests, testReport, project.service().editor!!) clear() val settingsProjectState = project.service().state @@ -140,7 +140,7 @@ class CoverageVisualisationService(private val project: Project) { for (i in linesToCover) { val line = i - 1 - val hl = project.service().editor!!.markupModel.addLineHighlighter( + val hl = project.service().editor!!.markupModel.addLineHighlighter( line, HighlighterLayer.ADDITIONAL_SYNTAX, textAttribute, diff --git a/src/main/kotlin/org/jetbrains/research/testspark/services/EditorService.kt b/src/main/kotlin/org/jetbrains/research/testspark/services/EditorService.kt new file mode 100644 index 000000000..eb3ca4280 --- /dev/null +++ b/src/main/kotlin/org/jetbrains/research/testspark/services/EditorService.kt @@ -0,0 +1,9 @@ +package org.jetbrains.research.testspark.services + +import com.intellij.openapi.components.Service +import com.intellij.openapi.editor.Editor + +@Service(Service.Level.PROJECT) +class EditorService { + var editor: Editor? = null +} diff --git a/src/main/kotlin/org/jetbrains/research/testspark/services/ProjectContextService.kt b/src/main/kotlin/org/jetbrains/research/testspark/services/ProjectContextService.kt index 92a259c45..4c3294c7a 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/services/ProjectContextService.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/services/ProjectContextService.kt @@ -1,14 +1,11 @@ package org.jetbrains.research.testspark.services import com.intellij.openapi.components.Service -import com.intellij.openapi.editor.Editor import com.intellij.openapi.module.Module import com.intellij.psi.PsiClass @Service(Service.Level.PROJECT) class ProjectContextService { - var editor: Editor? = null - // The class path of the project. var projectClassPath: String? = null diff --git a/src/main/kotlin/org/jetbrains/research/testspark/services/ReportLockingService.kt b/src/main/kotlin/org/jetbrains/research/testspark/services/ReportLockingService.kt index d5487785f..b5510de17 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/services/ReportLockingService.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/services/ReportLockingService.kt @@ -27,7 +27,7 @@ class ReportLockingService(private val project: Project) { project.service().updateEditorForFileUrl(project.service().fileUrl) - if (project.service().editor != null) { + if (project.service().editor != null) { project.service().displayTestCases() project.service().showCoverage(report) } else { diff --git a/src/main/kotlin/org/jetbrains/research/testspark/services/TestCaseDisplayService.kt b/src/main/kotlin/org/jetbrains/research/testspark/services/TestCaseDisplayService.kt index cf4ef03a6..b82519325 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/services/TestCaseDisplayService.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/services/TestCaseDisplayService.kt @@ -95,7 +95,7 @@ class TestCaseDisplayService(private val project: Project) { */ fun displayTestCases() { val report = project.service().getReport() - val editor = project.service().editor!! + val editor = project.service().editor!! allTestCasePanel.removeAll() testCasePanels.clear() @@ -224,7 +224,7 @@ class TestCaseDisplayService(private val project: Project) { * Removes all coverage highlighting from the editor. */ private fun removeAllHighlights() { - project.service().editor?.markupModel?.removeAllHighlighters() + project.service().editor?.markupModel?.removeAllHighlighters() } /** @@ -469,7 +469,7 @@ class TestCaseDisplayService(private val project: Project) { val currentFile = documentManager.getFile(it.document) if (currentFile != null) { if (currentFile.presentableUrl == fileUrl) { - project.service().editor = it + project.service().editor = it } } }