generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(shirelang): add spike comment injection and run line markers #133
- Loading branch information
Showing
4 changed files
with
79 additions
and
24 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
shirelang/src/main/kotlin/com/phodal/shirelang/ShireInCommentInjector.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,49 @@ | ||
package com.phodal.shirelang | ||
|
||
import com.intellij.lang.injection.MultiHostInjector | ||
import com.intellij.lang.injection.MultiHostRegistrar | ||
import com.intellij.psi.PsiComment | ||
import com.intellij.psi.PsiDocCommentBase | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiLanguageInjectionHost | ||
import org.jetbrains.annotations.NotNull | ||
import java.util.regex.Matcher | ||
import java.util.regex.Pattern | ||
|
||
/** | ||
* Comment injector for Shire language | ||
*/ | ||
class ShireInCommentInjector : MultiHostInjector { | ||
private val SHIRE_CODE_PATTERN: Pattern = Pattern.compile("```shire\\s*(.*?)\\s*```", Pattern.DOTALL) | ||
|
||
override fun getLanguagesToInject(@NotNull registrar: MultiHostRegistrar, @NotNull host: PsiElement) { | ||
if (host !is PsiDocCommentBase) { | ||
return | ||
} | ||
|
||
val commentText = host.getText() | ||
val matcher: Matcher = SHIRE_CODE_PATTERN.matcher(commentText) | ||
|
||
if (host as? PsiLanguageInjectionHost == null) { | ||
return | ||
} | ||
|
||
/// refs to : https://github.com/intellij-rust/intellij-rust/blob/c6657c02bb62075bf7b7ceb84d000f93dda34dc1/src/main/kotlin/org/rust/ide/injected/RsDoctestLanguageInjector.kt | ||
// while (matcher.find()) { | ||
// val start: Int = matcher.start(1) | ||
// val end: Int = matcher.end(1) | ||
// | ||
// registrar.startInjecting(ShireLanguage.INSTANCE) | ||
// .addPlace(null, null, host as PsiLanguageInjectionHost, TextRange.create(start, end)) | ||
// .doneInjecting() | ||
// } | ||
} | ||
|
||
@NotNull | ||
override fun elementsToInjectIn(): List<Class<out PsiElement>?> { | ||
return listOf(PsiComment::class.java) | ||
} | ||
|
||
companion object { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireCommentRunLineMarkersProvider.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,27 @@ | ||
package com.phodal.shirelang.run | ||
|
||
import com.phodal.shirelang.actions.ShireRunFileAction | ||
import com.intellij.execution.lineMarker.RunLineMarkerContributor | ||
import com.intellij.icons.AllIcons | ||
import com.intellij.openapi.actionSystem.ActionManager | ||
import com.intellij.openapi.actionSystem.AnAction | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.psi.PsiElement | ||
import com.phodal.shirelang.ShireBundle | ||
import com.intellij.psi.PsiDocCommentBase | ||
|
||
class ShireCommentRunLineMarkersProvider : RunLineMarkerContributor(), DumbAware { | ||
override fun getInfo(element: PsiElement): Info? { | ||
if (element !is PsiDocCommentBase) return null | ||
val commentText = element.text | ||
if (!commentText.contains("```shire")) return null | ||
|
||
val actions = arrayOf<AnAction>(ActionManager.getInstance().getAction(ShireRunFileAction.ID)) | ||
|
||
return Info( | ||
AllIcons.RunConfigurations.TestState.Run, | ||
{ ShireBundle.message("shire.line.marker.run.comment") }, | ||
*actions | ||
) | ||
} | ||
} |
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