Skip to content

Commit 5e99bee

Browse files
fix goto config (#111)
1 parent d07f2ae commit 5e99bee

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
132132
<h1>0.4.1-242.21829.142</h1>
133133
<ul>
134-
<li>Code improvement, compatible with the latest IJ version.</li>
134+
<li>Improve code and API compatibility.</li>
135+
<li>Fix Open Config Action.</li>
135136
</ul>
136137
<!-- @@ -->
137138

src/main/scala/bitlap/sbt/analyzer/action/SbtDependencyAnalyzerOpenConfigAction.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package sbt
33
package analyzer
44
package action
55

6+
import bitlap.sbt.analyzer.util.SbtUtils
7+
68
import org.jetbrains.sbt.project.SbtProjectSystem
79

810
import 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

1520
final 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

Comments
 (0)