Skip to content

Commit

Permalink
Fixing test runner (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval authored Apr 30, 2024
1 parent 1493222 commit fc52e33
Show file tree
Hide file tree
Showing 14 changed files with 665 additions and 628 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,15 @@ public void notifyDiagnostic(PublishDiagnosticsParams params) {
}

ReadAction.nonBlocking(() -> {
VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(uri);
if (fileByUrl != null) {
PsiFile file = PsiManager.getInstance(myProject).findFile(fileByUrl);
if (file != null) {
DaemonCodeAnalyzer.getInstance(myProject).restart(file);
VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(uri);
if (fileByUrl != null) {
PsiFile file = PsiManager.getInstance(myProject).findFile(fileByUrl);
if (file != null) {
DaemonCodeAnalyzer.getInstance(myProject).restart(file);
}
}
}
});
return null;
}).submit(AppExecutorUtil.getAppExecutorService());
}
});
languageServerFactory.withSerializationProps(EmptyJvmSerializationProps$.MODULE$);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class WeaveIcons {
public static final Icon RestSdkIcon = IconLoader.findIcon("/icons/rest_sdk_module.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveModuleIcon = IconLoader.findIcon("/icons/dw-module-icon.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveMappingIcon = IconLoader.findIcon("/icons/dw-mapping-icon.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveTestIcon = IconLoader.findIcon("/icons/dw-test-icon.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveTestingFrameworkIcon = IconLoader.findIcon("/icons/dw-testing-framework.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveTestIcon = IconLoader.findIcon("/icons/dw-module-icon.png", WeaveIcons.class.getClassLoader());
public static final Icon DataWeaveTestingFrameworkIcon = IconLoader.findIcon("/icons/dw-module-icon.png", WeaveIcons.class.getClassLoader());

private WeaveIcons() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,10 @@
import com.intellij.lang.annotation.Annotator;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.highlighter.WeaveSyntaxHighlighter;
import org.mule.tooling.lang.dw.parser.psi.WeaveBinaryExpression;
import org.mule.tooling.lang.dw.parser.psi.WeaveFunctionCallExpression;
import org.mule.tooling.lang.dw.parser.psi.WeaveFunctionDefinition;
import org.mule.tooling.lang.dw.parser.psi.WeaveIdentifier;
import org.mule.tooling.lang.dw.parser.psi.WeaveVariableDefinition;


public class WeaveAnnotator implements Annotator {
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {

if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveFunctionDefinition) {
holder.createInfoAnnotation(element, "Function").setTextAttributes(WeaveSyntaxHighlighter.FUNCTION_DECLARATION);
}
if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveVariableDefinition) {
holder.createInfoAnnotation(element, "Variable").setTextAttributes(WeaveSyntaxHighlighter.VARIABLE);
}
if (element instanceof WeaveIdentifier && element.getParent() instanceof WeaveFunctionCallExpression) {
holder.createInfoAnnotation(element, "Function call").setTextAttributes(WeaveSyntaxHighlighter.FUNCTION_CALL);
}
if (element instanceof WeaveBinaryExpression) {
holder.createInfoAnnotation(((WeaveBinaryExpression) element).getBinaryFunctionIdentifier(), "Infix Function Call")
.setTextAttributes(WeaveSyntaxHighlighter.INFIX_FUNCTION_CALL);
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.mule.tooling.lang.dw.hints;

import com.intellij.codeHighlighting.*;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory;
import com.intellij.codeHighlighting.TextEditorHighlightingPassFactoryRegistrar;
import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar;
import com.intellij.codeInsight.hints.ModificationStampHolder;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
Expand All @@ -12,11 +14,11 @@
import org.mule.tooling.lang.dw.WeaveFileType;
import org.mule.tooling.lang.dw.settings.DataWeaveSettingsState;

public class WeaveTypeHintPassFactory implements TextEditorHighlightingPassFactory, TextEditorHighlightingPassFactoryRegistrar {
public class WeaveTypeHintPassFactory implements TextEditorHighlightingPassFactory, TextEditorHighlightingPassFactoryRegistrar {

public static ModificationStampHolder stampHolder = new ModificationStampHolder(Key.create("LAST_TYPE_PASS_MODIFICATION_TIMESTAMP"));

public void registerHighlightingPassFactory(TextEditorHighlightingPassRegistrar registrar, @NotNull Project project) {
public void registerHighlightingPassFactory(TextEditorHighlightingPassRegistrar registrar, @NotNull Project project) {
registrar.registerTextEditorHighlightingPass(this, null, null, false, -1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected JavaParameters createJavaParameters() throws ExecutionException {
final ProjectRootManager manager = ProjectRootManager.getInstance(module.getProject());
javaParams.setJdk(manager.getProjectSdk());
// All modules to use the same things
javaParams.configureByModule(module, JavaParameters.JDK_AND_CLASSES_AND_TESTS | JavaParameters.INCLUDE_PROVIDED);
javaParams.configureByModule(module, JavaParameters.JDK_AND_CLASSES_AND_TESTS);
javaParams.setMainClass(WeaveRunnerHelper.WEAVE_RUNNER_MAIN_CLASS);

//Add default vm parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import static java.util.Optional.ofNullable;

public class WeaveTestConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule, RunProfileState> implements ModuleRunProfile, RunConfigurationWithSuppressedDefaultDebugAction, WeaveTestBaseRunnerConfig {
public class WeaveTestConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule, RunProfileState> implements ModuleRunProfile, WeaveTestBaseRunnerConfig {

public static final String PREFIX = "DataWeaveTestConfig-";
public static final String WEAVE_FILE = PREFIX + "WeaveFile";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.mule.tooling.lang.dw.lineMarker;

import com.intellij.execution.lineMarker.ExecutorAction;
import com.intellij.execution.lineMarker.RunLineMarkerContributor;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.testintegration.WeaveTestFramework;

public class RunTestLineMarkerContributor extends RunLineMarkerContributor {

public Info getInfo(@NotNull PsiElement element){
if(WeaveTestFramework.isWeaveTestMethod(element)){
final AnAction[] actions = ExecutorAction.getActions(Integer.MAX_VALUE);
return new Info(
AllIcons.RunConfigurations.TestState.Run,
actions,
e -> StringUtil.join(ContainerUtil.mapNotNull(actions, action -> getText(action, e)), "\n")
);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,47 +121,49 @@ public void onChanged(org.mule.weave.v2.editor.VirtualFile vf) {

private void onFileChanged(VirtualFile virtualFile) {
ReadAction.nonBlocking(() -> {
if (project.isDisposed()) {
return;
}
//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
onChanged(intellijVirtualFile);
}).expireWith(project)
if (project.isDisposed()) {
return null;
}
//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
onChanged(intellijVirtualFile);
return null;
}).expireWith(project)
.submit(fs_updater);
}

private void onFileDeleted(VirtualFile virtualFile) {
ReadAction.nonBlocking(() -> {
if (project.isDisposed()) {
return;
}

//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
for (ChangeListener listener : listeners) {
if (listener != null) {
listener.onDeleted(intellijVirtualFile);
}
}
})
if (project.isDisposed()) {
return null;
}

//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
for (ChangeListener listener : listeners) {
if (listener != null) {
listener.onDeleted(intellijVirtualFile);
}
}
return null;
})
.expireWith(project)
.submit(fs_updater);
}

private void onFileCreated(VirtualFile virtualFile) {
ReadAction.nonBlocking(() -> {
if (project.isDisposed()) {
return;
}
//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
for (ChangeListener listener : listeners) {
if (listener != null) {
listener.onCreated(intellijVirtualFile);
}
}
}).expireWith(project)
if (project.isDisposed()) {
return;
}
//If it is a file from the project
final IJVirtualFileAdaptor intellijVirtualFile = new IJVirtualFileAdaptor(IJVirtualFileSystemAdaptor.this, virtualFile, project, null);
for (ChangeListener listener : listeners) {
if (listener != null) {
listener.onCreated(intellijVirtualFile);
}
}
}).expireWith(project)
.submit(fs_updater);
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,21 @@ private void onFileChanged(VirtualFile modifiedFile) {
if (myProject.isDisposed()) {
return;
}
final Application app = ApplicationManager.getApplication();
final Runnable scenarioTask = () -> {
if (myProject.isDisposed()) {
return; //sometime
}

final Module moduleForFile = ModuleUtil.findModuleForFile(modifiedFile, myProject);
app.runWriteAction(() -> {
final VirtualFile dwitFolder = getScenariosRootFolder(moduleForFile);
if (dwitFolder != null && VfsUtil.isAncestor(dwitFolder, modifiedFile, true)) {
VirtualFile scenario = findScenario(modifiedFile, dwitFolder);
onModified(new Scenario(scenario));
}
});
};
app.invokeLater(scenarioTask);
WriteAction
.compute(() -> {
final Application app = ApplicationManager.getApplication();
if (myProject.isDisposed()) {
return null; //sometime
}
final Module moduleForFile = ModuleUtil.findModuleForFile(modifiedFile, myProject);
final VirtualFile dwitFolder = getScenariosRootFolder(moduleForFile);
if (dwitFolder != null && VfsUtil.isAncestor(dwitFolder, modifiedFile, true)) {
VirtualFile scenario = findScenario(modifiedFile, dwitFolder);
onModified(new Scenario(scenario));
}
return null;
});
}

public void availableDataFormat(Consumer<WeaveDataFormatDescriptor[]> callback) {
Expand Down
Loading

0 comments on commit fc52e33

Please sign in to comment.