@@ -7,8 +7,12 @@ import com.intellij.execution.configurations.ParametersList
77import com.intellij.notification.NotificationGroupManager
88import com.intellij.notification.NotificationType
99import com.intellij.openapi.diagnostic.Logger
10+ import com.intellij.openapi.module.ModuleUtilCore
1011import com.intellij.openapi.project.Project
12+ import com.intellij.openapi.project.rootManager
1113import com.intellij.openapi.util.io.FileUtil
14+ import com.intellij.openapi.vfs.LocalFileSystem
15+ import com.intellij.openapi.vfs.VirtualFile
1216import com.intellij.psi.PsiFile
1317import com.jetbrains.php.tools.quality.QualityToolAnnotator
1418import com.jetbrains.php.tools.quality.QualityToolAnnotatorInfo
@@ -23,21 +27,36 @@ open class MagoAnnotatorProxy : QualityToolAnnotator<MagoValidationInspection>()
2327
2428 fun getFormatOptions (settings : MagoProjectConfiguration , project : Project , files : Collection <String >) =
2529 buildList {
26- addWorkspace(project)
27- addConfig(project, settings)
30+ val workspace = findWorkspace(project, files.firstOrNull())
31+ addWorkspace(workspace, project)
32+ addConfig(workspace, project, settings)
2833
2934 add(" fmt" )
30- addAll(files.map { toWorkspaceRelativePath(project , it) })
35+ addAll(files.map { toWorkspaceRelativePath(workspace , it) })
3136 }
3237 .plus(ParametersList .parse(settings.formatAdditionalParameters))
33- .apply { println (" format options: ${this .joinToString(" " )} " ) }
38+ .apply { val options = this .joinToString(" " )
39+ println (" format options: $options " )
40+ NotificationGroupManager .getInstance()
41+ .getNotificationGroup(" Mago" )
42+ .createNotification(" Format options" , """ Options: $options , filePaths: ${files.joinToString(" , " ) { it }} """ , NotificationType .INFORMATION )
43+ .notify(project)
44+ }
45+
46+ fun findWorkspace (project : Project , filePath : String? ): VirtualFile {
47+ if (filePath == null ) return project.baseDir
48+ val file = LocalFileSystem .getInstance().findFileByPath(filePath) ? : return project.baseDir
49+ val module = ModuleUtilCore .findModuleForFile(file, project) ? : return project.baseDir
50+ return module.rootManager.contentRoots.firstOrNull() ? : project.baseDir
51+ }
3452
3553 fun getAnalyzeOptions (settings : MagoProjectConfiguration , project : Project , filePath : String ) = buildList {
36- addWorkspace(project)
37- addConfig(project, settings)
54+ val workspace = findWorkspace(project, filePath)
55+ addWorkspace(workspace, project)
56+ addConfig(workspace, project, settings)
3857
3958 add(" analyze" )
40- add(toWorkspaceRelativePath(project , filePath))
59+ add(toWorkspaceRelativePath(workspace , filePath))
4160 add(" --reporting-format=json" )
4261// filePath?.let { add(it) }
4362 }
@@ -55,6 +74,9 @@ open class MagoAnnotatorProxy : QualityToolAnnotator<MagoValidationInspection>()
5574 val basePath = project.basePath ? : return absoluteFilePath
5675 return toRelativePath(basePath, absoluteFilePath)
5776 }
77+ private fun toWorkspaceRelativePath (workspace : VirtualFile , absoluteFilePath : String ): String {
78+ return toRelativePath(workspace.path, absoluteFilePath)
79+ }
5880
5981 internal fun toRelativePath (basePath : String , absoluteFilePath : String ): String {
6082 val basePath = basePath.normalizePath()
@@ -79,21 +101,21 @@ open class MagoAnnotatorProxy : QualityToolAnnotator<MagoValidationInspection>()
79101 return path.length >= 2 && path[0 ].isLetter() && path[1 ] == ' :'
80102 }
81103
82- private fun MutableList<String>.addWorkspace (project : Project ) {
104+ private fun MutableList<String>.addWorkspace (workspace : VirtualFile , project : Project ) {
83105 val projectPath = updateIfRemoteMappingExists(
84- project.basePath ? : return ,
106+ workspace.path ,
85107 project,
86108 INSTANCE .qualityToolType
87109 ).let { FileUtil .toSystemIndependentName(it) }
88110 add(" --workspace=$projectPath " )
89111 }
90112
91- private fun MutableList<String>.addConfig (project : Project , settings : MagoProjectConfiguration ) {
113+ private fun MutableList<String>.addConfig (workspace : VirtualFile , project : Project , settings : MagoProjectConfiguration ) {
92114 val configurationFile = updateIfRemoteMappingExists(
93115 settings.configurationFile,
94116 project,
95- INSTANCE .qualityToolType
96- ).let { toWorkspaceRelativePath(project , it) }
117+ INSTANCE .qualityToolType,
118+ ).let { toWorkspaceRelativePath(workspace , it) }
97119
98120 if (configurationFile.isNotEmpty()) {
99121 add(" --config=$configurationFile " )
0 commit comments