mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
let groovyScript in live templates use the plugin of the language under caret (IDEA-218938)
GitOrigin-RevId: c89810fc3bbe0b5cbeaa1241b5dfecee98579b66
This commit is contained in:
committed by
intellij-monorepo-bot
parent
14ef0d43c3
commit
b5e20e8892
+8
-2
@@ -19,7 +19,10 @@ import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyShell;
|
||||
@@ -59,12 +62,15 @@ public class GroovyScriptMacro extends Macro {
|
||||
}
|
||||
|
||||
private static Object runIt(Expression[] params, ExpressionContext context) {
|
||||
Editor editor = context.getEditor();
|
||||
Language language = editor == null ? null : PsiUtilBase.getLanguageInEditor(editor, context.getProject());
|
||||
|
||||
try {
|
||||
Result result = params[0].calculateResult(context);
|
||||
if (result == null) return null;
|
||||
|
||||
String text = result.toString();
|
||||
GroovyShell shell = new GroovyShell();
|
||||
GroovyShell shell = new GroovyShell(language == null ? null : language.getClass().getClassLoader());
|
||||
File possibleFile = new File(text);
|
||||
Script script = possibleFile.exists() ? shell.parse(possibleFile) : shell.parse(text);
|
||||
Binding binding = new Binding();
|
||||
@@ -80,7 +86,7 @@ public class GroovyScriptMacro extends Macro {
|
||||
binding.setVariable("_"+i, value);
|
||||
}
|
||||
|
||||
binding.setVariable("_editor", context.getEditor());
|
||||
binding.setVariable("_editor", editor);
|
||||
|
||||
script.setBinding(binding);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user