generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from lets-cli/add-mixin-go-to-def
add mixinx Go to definition
- Loading branch information
Showing
7 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
shell: bash | ||
|
||
commands: | ||
build: | ||
cmd: echo Build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
shell: bash | ||
|
||
mixins: | ||
- lets.build.yaml | ||
|
||
commands: | ||
test: | ||
depends: [build] | ||
cmd: echo Test | ||
|
||
run: | ||
depends: [test] | ||
cmd: echo Run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/kotlin/com/github/kindermax/intellijlets/LetsReferenceContributor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.github.kindermax.intellijlets | ||
|
||
import com.intellij.codeInsight.lookup.LookupElementBuilder | ||
import com.intellij.patterns.PlatformPatterns | ||
import com.intellij.psi.* | ||
import com.intellij.psi.search.FilenameIndex | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import com.intellij.util.ProcessingContext | ||
import org.jetbrains.yaml.psi.YAMLKeyValue | ||
import org.jetbrains.yaml.psi.YAMLScalar | ||
|
||
open class LetsReferenceContributor : PsiReferenceContributor() { | ||
override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) { | ||
registrar.registerReferenceProvider( | ||
PlatformPatterns.psiElement(YAMLScalar::class.java), | ||
object : PsiReferenceProvider() { | ||
override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> { | ||
val yamlKeyValue = PsiTreeUtil.getParentOfType(element, YAMLKeyValue::class.java) ?: return emptyArray() | ||
if (yamlKeyValue.keyText == "mixins") { | ||
return arrayOf(LetsMixinReference(element as YAMLScalar)) | ||
} | ||
return emptyArray() | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
|
||
class LetsMixinReference(element: YAMLScalar) : PsiReferenceBase<YAMLScalar>(element) { | ||
/** | ||
* This method is used to resolve the reference to the mixin file. | ||
* Currently, it supports only local files in the project. | ||
*/ | ||
override fun resolve(): PsiElement? { | ||
val project = myElement.project | ||
val mixinFilename = myElement.textValue // Extract the filename from the scalar value | ||
|
||
// Search for the mixin file in the project | ||
val virtualFile = FilenameIndex.getVirtualFilesByName( | ||
project, | ||
mixinFilename, | ||
GlobalSearchScope.allScope(project), | ||
).firstOrNull() ?: return null | ||
|
||
return PsiManager.getInstance(project).findFile(virtualFile) | ||
} | ||
|
||
/** | ||
* This method is used to provide autocompletion suggestions for the mixin filenames | ||
* by suggesting YAML files in the project. | ||
*/ | ||
override fun getVariants(): Array<Any> { | ||
val project = myElement.project | ||
val mixinFiles = FilenameIndex.getAllFilesByExt(project, "yaml") | ||
.map { LookupElementBuilder.create(it.name) } | ||
|
||
return mixinFiles.toTypedArray() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters