diff --git a/src/main/kotlin/insyncwithfoo/ryecharm/TOML.kt b/src/main/kotlin/insyncwithfoo/ryecharm/TOML.kt index 536602a..352a689 100644 --- a/src/main/kotlin/insyncwithfoo/ryecharm/TOML.kt +++ b/src/main/kotlin/insyncwithfoo/ryecharm/TOML.kt @@ -33,7 +33,7 @@ internal val TomlTable.absoluteName: TOMLPath get() = TOMLPath(header.key?.text.orEmpty()) -private val TomlKey.name: String +private val TomlKey.segmentedName: String get() = segments.joinToString(".") { it.text } @@ -43,9 +43,9 @@ private val TomlKey.table: TomlTable? internal val TomlKey.absoluteName: TOMLPath get() = when { - parent === containingFile -> TOMLPath(name) - table == null -> TOMLPath(name) - else -> table!!.absoluteName + TOMLPath(name) + parent === containingFile -> TOMLPath(segmentedName) + table == null -> TOMLPath(segmentedName) + else -> table!!.absoluteName + TOMLPath(segmentedName) } diff --git a/src/main/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjector.kt b/src/main/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjector.kt index 44f6f24..a624677 100644 --- a/src/main/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjector.kt +++ b/src/main/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjector.kt @@ -27,8 +27,8 @@ import org.toml.lang.psi.TomlLiteral * * `uv.upgrade-package` * * `uv.pip.upgrade-package` * - * As a bonus, `pyproject.toml`'s - * `project.optional-dependencies` is also supported. + * As a bonus, `pyproject.toml`'s `project.optional-dependencies` + * and `dependency-groups` (PEP 735) are also supported. */ internal class RequirementsInjector : LanguageInjectionContributor { @@ -64,8 +64,8 @@ internal class RequirementsInjector : LanguageInjectionContributor { val virtualFile = file.virtualFile ?: return null val absoluteName = key.absoluteName - if (virtualFile.isPyprojectToml && absoluteName isChildOf "project.optional-dependencies") { - return injection + if (virtualFile.isPyprojectToml) { + return getPyprojectTomlInjection(absoluteName) } val relativeName = when { @@ -93,4 +93,10 @@ internal class RequirementsInjector : LanguageInjectionContributor { return injection } + private fun getPyprojectTomlInjection(keyAbsoluteName: TOMLPath) = when { + keyAbsoluteName isChildOf "project.optional-dependencies" -> injection + keyAbsoluteName isChildOf "dependency-groups" -> injection + else -> null + } + } diff --git a/src/test/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjectorTest.kt b/src/test/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjectorTest.kt index 6c77334..825ffa8 100644 --- a/src/test/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjectorTest.kt +++ b/src/test/kotlin/insyncwithfoo/ryecharm/common/injections/RequirementsInjectorTest.kt @@ -11,6 +11,11 @@ internal class RequirementsInjectorTest : LanguageInjectionTestCase() { assertEquals(2, fragments.size) } + @Test + fun `test dependency-groups`() = fileBasedTest("dependencyGroups/pyproject.toml") { + assertEquals(1, fragments.size) + } + @Test fun `test other keys`() { val directoriesAndKeyNames = mapOf( diff --git a/src/test/testData/common/injections/RequirementsInjectorTest/dependencyGroups/pyproject.toml b/src/test/testData/common/injections/RequirementsInjectorTest/dependencyGroups/pyproject.toml new file mode 100644 index 0000000..b9dba26 --- /dev/null +++ b/src/test/testData/common/injections/RequirementsInjectorTest/dependencyGroups/pyproject.toml @@ -0,0 +1,5 @@ +[dependency-groups] +foo = [ + "ruff==0.6.9", + { include-group = "bar" } +]