Skip to content

Commit 3915305

Browse files
authored
fix: fallback to child config when no root config was found in project (#210)
1 parent 5a8f1d9 commit 3915305

File tree

1 file changed

+9
-4
lines changed
  • src/main/kotlin/com/github/biomejs/intellijbiome/extensions

1 file changed

+9
-4
lines changed

src/main/kotlin/com/github/biomejs/intellijbiome/extensions/FileExt.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ private val configValidExtensions = listOf("json", "jsonc")
2929
fun VirtualFile.isBiomeConfigFile(): Boolean =
3030
configValidExtensions.map { "${configName}.$it" }.contains(this.name)
3131

32-
fun VirtualFile.findNearestBiomeConfig(root: VirtualFile? = null): VirtualFile? =
33-
this.findNearestFile(root) {
34-
if (it.isBiomeConfigFile()) {
32+
fun VirtualFile.findNearestBiomeConfig(root: VirtualFile? = null, onlyRootConfig: Boolean = true): VirtualFile? =
33+
this.findNearestFile(root) { file ->
34+
if (file.isBiomeConfigFile()) {
3535
// Skip biome.json(c) files that includes `root: false` or `extends: //`
36-
BiomeConfig.loadFromFile(it)?.isRootConfig() ?: false
36+
BiomeConfig.loadFromFile(file)?.let { !onlyRootConfig || it.isRootConfig() } ?: false
3737
} else {
3838
false
3939
}
40+
} ?: if (onlyRootConfig) {
41+
// If no root config was found, fallback to any nearest nested (child) config.
42+
this.findNearestBiomeConfig(root, false)
43+
} else {
44+
null
4045
}

0 commit comments

Comments
 (0)