Skip to content

Commit

Permalink
create EditorService.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
arksap2002 committed Jan 3, 2024
1 parent 64740d9 commit a2620e1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CoverageVisualisationService(private val project: Project) {
testReport: Report,
) {
currentHighlightedData =
HighlightedData(linesToCover, selectedTests, testReport, project.service<ProjectContextService>().editor!!)
HighlightedData(linesToCover, selectedTests, testReport, project.service<EditorService>().editor!!)
clear()

val settingsProjectState = project.service<SettingsProjectService>().state
Expand Down Expand Up @@ -140,7 +140,7 @@ class CoverageVisualisationService(private val project: Project) {
for (i in linesToCover) {
val line = i - 1

val hl = project.service<ProjectContextService>().editor!!.markupModel.addLineHighlighter(
val hl = project.service<EditorService>().editor!!.markupModel.addLineHighlighter(
line,
HighlighterLayer.ADDITIONAL_SYNTAX,
textAttribute,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReportLockingService(private val project: Project) {

project.service<TestCaseDisplayService>().updateEditorForFileUrl(project.service<TestGenerationDataService>().fileUrl)

if (project.service<ProjectContextService>().editor != null) {
if (project.service<EditorService>().editor != null) {
project.service<TestCaseDisplayService>().displayTestCases()
project.service<CoverageVisualisationService>().showCoverage(report)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TestCaseDisplayService(private val project: Project) {
*/
fun displayTestCases() {
val report = project.service<ReportLockingService>().getReport()
val editor = project.service<ProjectContextService>().editor!!
val editor = project.service<EditorService>().editor!!

allTestCasePanel.removeAll()
testCasePanels.clear()
Expand Down Expand Up @@ -224,7 +224,7 @@ class TestCaseDisplayService(private val project: Project) {
* Removes all coverage highlighting from the editor.
*/
private fun removeAllHighlights() {
project.service<ProjectContextService>().editor?.markupModel?.removeAllHighlighters()
project.service<EditorService>().editor?.markupModel?.removeAllHighlighters()
}

/**
Expand Down Expand Up @@ -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<ProjectContextService>().editor = it
project.service<EditorService>().editor = it
}
}
}
Expand Down

0 comments on commit a2620e1

Please sign in to comment.