@@ -10,7 +10,9 @@ import com.intellij.psi.search.GlobalSearchScope
1010import com.intellij.psi.util.PsiTreeUtil
1111import com.intellij.util.PathUtil
1212import com.intellij.util.ProcessingContext
13+ import org.jetbrains.yaml.psi.YAMLFile
1314import org.jetbrains.yaml.psi.YAMLKeyValue
15+ import org.jetbrains.yaml.psi.YAMLMapping
1416import org.jetbrains.yaml.psi.YAMLScalar
1517
1618open class LetsReferenceContributor : PsiReferenceContributor () {
@@ -20,16 +22,39 @@ open class LetsReferenceContributor : PsiReferenceContributor() {
2022 object : PsiReferenceProvider () {
2123 override fun getReferencesByElement (element : PsiElement , context : ProcessingContext ): Array <PsiReference > {
2224 val yamlKeyValue = PsiTreeUtil .getParentOfType(element, YAMLKeyValue ::class .java) ? : return emptyArray()
23- if (yamlKeyValue.keyText == " mixins" ) {
24- return arrayOf(LetsMixinReference (element as YAMLScalar ))
25+
26+ return when (yamlKeyValue.keyText) {
27+ " mixins" -> arrayOf(LetsMixinReference (element as YAMLScalar ))
28+ " depends" -> arrayOf(LetsDependsReference (element as YAMLScalar ))
29+ else -> emptyArray()
2530 }
26- return emptyArray()
2731 }
2832 }
2933 )
3034 }
3135}
3236
37+ class LetsDependsReference (element : YAMLScalar ) : PsiReferenceBase<YAMLScalar>(element) {
38+ override fun resolve (): PsiElement ? {
39+ val project = myElement.project
40+ val commandName = myElement.textValue // Extracts the command name inside `depends`
41+
42+ // Locate the command declaration in the same YAML file
43+ val yamlFile = myElement.containingFile as ? YAMLFile ? : return null
44+ return PsiTreeUtil .findChildrenOfType(yamlFile, YAMLKeyValue ::class .java)
45+ .firstOrNull { it.keyText == commandName && it.parent is YAMLMapping }
46+ }
47+
48+ override fun getVariants (): Array <Any > {
49+ val yamlFile = myElement.containingFile as ? YAMLFile ? : return emptyArray()
50+
51+ // Collect all available command names for autocompletion
52+ val commands = PsiTreeUtil .findChildrenOfType(yamlFile, YAMLKeyValue ::class .java)
53+ .mapNotNull { it.keyText }
54+
55+ return commands.map { LookupElementBuilder .create(it) }.toTypedArray()
56+ }
57+ }
3358
3459class LetsMixinReference (element : YAMLScalar ) : PsiReferenceBase<YAMLScalar>(element) {
3560 /* *
@@ -60,15 +85,15 @@ class LetsMixinReference(element: YAMLScalar) : PsiReferenceBase<YAMLScalar>(ele
6085 return yamlFiles.toTypedArray()
6186 }
6287
63- /* *
88+ /* *
6489 * Searches for the mixin file anywhere in the project.
6590 * Supports both top-level files ("lets.build.yaml") and nested files ("lets/lets.docs.yaml").
6691 */
6792 private fun findMixinFile (project : Project , mixinPath : String ): VirtualFile ? {
6893 // Normalize paths (handle both "lets.mixin.yaml" and "lets/lets.mixin.yaml")
6994 val normalizedPath = mixinPath.trimStart(' /' )
7095 // Normalize gitignored files (e.g. "-lets.mixin.yaml" -> "lets.mixin.yaml")
71- .removePrefix(" -" )
96+ .removePrefix(" -" )
7297
7398 // Look for an exact match in the project
7499 return FilenameIndex .getVirtualFilesByName(
0 commit comments