Skip to content

add mixinx Go to definition #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# intellij-lets Changelog

## [Unreleased]
### Added
- add reference contributor for `mixins` files
### Updated
- actually make plugin support all future versions of IDEs

## [0.0.13]
### Updated
- make plugin support all future versions of IDEs (remove max version restriction)
- support 2024 IDE version
Expand Down
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ intellijPlatform {
)
}
}

ideaVersion {
sinceBuild = providers.gradleProperty("pluginSinceBuild")
}
}

publishing {
Expand Down
5 changes: 5 additions & 0 deletions example/lets.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shell: bash

commands:
build:
cmd: echo Build
13 changes: 13 additions & 0 deletions example/lets.yaml
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
7 changes: 1 addition & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
pluginGroup = com.github.kindermax.intellijlets
pluginName = intellij-lets
pluginRepositoryUrl = https://github.com/lets-cli/intellij-lets
pluginVersion = 0.0.13

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html#intellij-platform-based-products-of-recent-ide-versions
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 241
pluginUntilBuild =
pluginVersion = 0.0.14

# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
Expand Down
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()
}
}
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<!-- https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html -->
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.plugins.yaml</depends>
<idea-version since-build="241"/>

<extensions defaultExtensionNs="com.intellij">
<fileType
Expand All @@ -25,5 +26,9 @@
order="first"
implementationClass="com.github.kindermax.intellijlets.LetsCompletionContributor"
/>
<psi.referenceContributor
language="yaml"
implementation="com.github.kindermax.intellijlets.LetsReferenceContributor"
/>
</extensions>
</idea-plugin>