@@ -3,6 +3,8 @@ package sbt
33package analyzer
44package action
55
6+ import bitlap .sbt .analyzer .util .SbtUtils
7+
68import org .jetbrains .sbt .project .SbtProjectSystem
79
810import com .intellij .openapi .actionSystem .AnActionEvent
@@ -11,10 +13,35 @@ import com.intellij.openapi.externalSystem.dependency.analyzer.{
1113 DependencyAnalyzerView ,
1214 ExternalSystemDependencyAnalyzerOpenConfigAction
1315}
16+ import com .intellij .openapi .externalSystem .service .settings .ExternalSystemConfigLocator
17+ import com .intellij .openapi .vfs .LocalFileSystem
18+ import com .intellij .openapi .vfs .VirtualFile
1419
1520final class SbtDependencyAnalyzerOpenConfigAction
1621 extends ExternalSystemDependencyAnalyzerOpenConfigAction (SbtProjectSystem .Id ):
1722
23+ override def getConfigFile (e : AnActionEvent ): VirtualFile = {
24+ val externalSystemConfigPath = getConfigFileOption(Option (getExternalProjectPath(e)))
25+ // if we cannot find module config, goto root config
26+ val configPath = externalSystemConfigPath
27+ .orElse(getConfigFileOption(SbtUtils .getExternalProjectPath(e.getProject).headOption))
28+ .orNull
29+ if (configPath == null || configPath.isDirectory) null else configPath
30+ }
31+
32+ private def getConfigFileOption (externalProjectPath : Option [String ]): Option [VirtualFile ] = {
33+ val fileSystem = LocalFileSystem .getInstance()
34+ val externalProjectDirectory = externalProjectPath.map(fileSystem.refreshAndFindFileByPath)
35+ val locator = ExternalSystemConfigLocator .EP_NAME .findFirstSafe(_.getTargetExternalSystemId == SbtProjectSystem .Id )
36+ if (locator == null ) {
37+ return null
38+ }
39+
40+ val externalSystemConfigPath = externalProjectDirectory.toList.filterNot(_ == null ).map(locator.adjust)
41+
42+ externalSystemConfigPath.filterNot(_ == null ).headOption
43+ }
44+
1845 override def getExternalProjectPath (e : AnActionEvent ): String =
1946 val dependency = e.getData(DependencyAnalyzerView .Companion .getDEPENDENCY)
2047 if (dependency == null ) return null
0 commit comments