Skip to content
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ File type recognition for `lets.yaml` and `lets.*.yaml` configs
- [x] Complete commands in `depends` with code snippet
- [ ] Complete commands in `depends` from mixins
- [ ] Complete env mode in `env` with code snippet
- [ ] Complete environment variables in cmd scripts
- **Go To Definition**
- [x] Navigate to definitions of `mixins` files
- [x] Navigate to definitions of optional `mixins` files (with - at the beginning)
- [x] Navigate to definitions of `mixins` remote files (as http links)
- [ ] Navigate to definitions of commands in `depends`
- [x] Navigate to definitions of commands in `depends`
- [ ] Navigate to definitions of commands in `depends` from mixins
- **Highlighting**
- [ ] Highlighting for shell script in cmd
- [x] Highlighting for shell script in cmd
- **Diagnostic**
- [ ] Diagnostic for missing `depends` commands
- [ ] Diagnostic for missing `mixins` files
- [ ] Diagnostic for errors in shell script

<!-- Plugin description end -->

Expand Down
12 changes: 9 additions & 3 deletions example/lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ mixins:
commands:
test:
depends: [build]
cmd: echo Test
cmd: echo ${LETS_COMMAND_NAME}

hello: echo Test
hello: echo Hello

run:
depends: [test, hello]
cmd: echo Run
cmd: |
set -ex
echo Run
echo Rff
if [ -n "${LE}" ]; then
exit 1
fi
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ platformDownloadSources = true
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =
# Example: platformBundledPlugins = com.intellij.java
platformBundledPlugins = org.jetbrains.plugins.yaml
platformBundledPlugins = org.jetbrains.plugins.yaml,com.jetbrains.sh

# Opt-out flag for bundling Kotlin standard library.
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.kindermax.intellijlets

import com.intellij.lang.Language
import com.intellij.lang.injection.MultiHostInjector
import com.intellij.lang.injection.MultiHostRegistrar
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiLanguageInjectionHost
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import org.jetbrains.yaml.psi.YAMLKeyValue
import org.jetbrains.yaml.psi.YAMLScalar

class LetsBashInjector : MultiHostInjector {
override fun elementsToInjectIn(): List<Class<out PsiElement>> {
return listOf(YAMLScalar::class.java) // We only care about YAML string values
}

override fun getLanguagesToInject(registrar: MultiHostRegistrar, context: PsiElement) {
// Ensure we are in a `cmd` field inside `commands`
val keyValue = PsiTreeUtil.getParentOfType(context, YAMLKeyValue::class.java) ?: return
if (keyValue.keyText == "cmd") {
val bashLanguage = Language.findLanguageByID("Shell Script") ?: return
val text = context.text
var startOffset = 0;
if (text.startsWith("|")) {
startOffset += 1
}
val endOffset = keyValue.endOffset - (keyValue.value?.startOffset ?: keyValue.endOffset)
val injectionTextRange = TextRange(startOffset, endOffset)
registrar.startInjecting(bashLanguage)
.addPlace(null, null, context as PsiLanguageInjectionHost, injectionTextRange)
.doneInjecting()
}
}
}
2 changes: 2 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,8 @@
<!-- 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>
<depends optional="true" config-file="sh.xml">com.jetbrains.sh</depends>


<extensions defaultExtensionNs="com.intellij">
<fileType
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/sh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<multiHostInjector implementation="com.github.kindermax.intellijlets.LetsBashInjector"/>
</extensions>
</idea-plugin>