Skip to content

Commit

Permalink
Specify the action update thread (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
thepieterdc authored Apr 20, 2024
1 parent bd4bd6a commit edd72c0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
22 changes: 10 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,23 @@ compileJava.dependsOn generateBuildConfig
prepareKotlinBuildScriptModel.dependsOn generateBuildConfig

static def getVerifiableVersions() {
// FIXME: Re-enable PyCharm checks.
def versions = ["IC-222.4554.10", /*"PC-203.6682.168" */]
def versions = ["IC-241.14494.240"]

// Get the list of all versions.
def versionUrl = new URL("https://data.services.jetbrains.com/products?code=IIC%2CPCC&fields=code%2Creleases.build%2Creleases.type")
def parsedJson = new JsonSlurper().parse(versionUrl)

// Find the latest EAP IntelliJ version.
versions.add(String.format("IC-%s", parsedJson.find { it -> it.code == "IIC" }.releases.find { it -> it.type == "eap" }.build))

// Find the latest EAP PyCharm version.
// FIXME: Re-enable PyCharm checks.
// versions.add(String.format("PC-%s", parsedJson.find { it -> it.code == "PCC" }.releases.find { it -> it.type == "eap" }.build))
// Find the latest release IntelliJ version.
versions.add(String.format("IC-%s", parsedJson.find { it -> it.code == "IIC" }.releases.find { it -> it.type == "release" }.build))
return versions
}

intellij {
downloadSources.set(false)
pluginName.set('dodona')
plugins.set(['java', 'PythonCore:222.4459.24'])
plugins.set(['java', 'PythonCore:241.14494.17'])
updateSinceUntilBuild.set(false)
version.set('222.4554.10')
version.set('241.14494.240')
}

jacocoTestReport {
Expand All @@ -103,11 +98,14 @@ jacocoTestReport {

patchPluginXml {
changeNotes = """
<ul>
<li>[BUG] Fixed compatibility with IntelliJ/PyCharm 2024.1</li>
</ul>
"""

pluginDescription = 'Companion plugin for the Ghent University Dodona platform, which allows you to submit exercises right from your favourite JetBrains IDE. More information can be found at <a href="https://docs.dodona.be/en/guides/pycharm-plugin/">https://docs.dodona.be/en/guides/pycharm-plugin/</a>'

sinceBuild = '222.4554.10'
sinceBuild = '241.14494.240'
}

publishPlugin {
Expand All @@ -121,5 +119,5 @@ runPluginVerifier {
}

wrapper {
gradleVersion = '8.7.0'
gradleVersion = '8.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package io.github.thepieterdc.dodona.plugin.actions;

import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
Expand Down Expand Up @@ -43,42 +44,47 @@ public class NewExerciseAction extends AnAction implements DumbAware {
Icons.DODONA
);
}

@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final Project project = Objects.requireNonNull(e.getProject());
final IdeView view = Objects.requireNonNull(e.getData(LangDataKeys.IDE_VIEW));

try {
// Prompt the user to identify the exercise.
final FullIdentification identification = IdentifyTask
.create(Objects.requireNonNull(e.getProject()))
.execute()
.orElseThrow(CancelledException::new);

// Get the current directory.
final PsiDirectory directory = Optional
.ofNullable(view.getOrChooseDirectory())
.orElseThrow(CancelledException::new);

// Create the file.
final VirtualFile created = ExerciseCreationService
.getInstance(project)
.create(directory, identification);

// Open the created file.
FileEditorManager.getInstance(project).openFile(created, true);
} catch (final CancelledException ex) {
// Ignore.
}
}


@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
}

@Override
public void update(@NotNull final AnActionEvent e) {
final Project project = e.getProject();
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);

final PsiDirectory[] directory = view != null ? view.getDirectories() : null;
e.getPresentation().setVisible(project != null && directory != null && directory.length > 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package io.github.thepieterdc.dodona.plugin.actions;

import com.intellij.codeInsight.CodeSmellInfo;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Document;
Expand Down Expand Up @@ -48,7 +49,7 @@ public class SubmitAction extends AnAction {
Icons.ACTION_SUBMIT
);
}

@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final Project project = Objects.requireNonNull(e.getProject());
Expand All @@ -59,7 +60,7 @@ public void actionPerformed(@NotNull final AnActionEvent e) {
e.getPresentation().setEnabled(true);
}
}

/**
* Finds a syntax error in the code if it exists.
*
Expand All @@ -77,7 +78,12 @@ private static Optional<CodeSmellInfo> findSyntaxError(final Project project,
.map(codeAnalysisSrv::errors)
.flatMap(smells -> smells.stream().findFirst());
}


@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

/**
* Gets the currently opened document, if available.
*
Expand All @@ -91,7 +97,7 @@ private static Optional<Document> getDocument(@Nullable final Project project) {
.map(FileEditorManager::getSelectedTextEditor)
.map(Editor::getDocument);
}

/**
* Gets the PsiFile of the given document.
*
Expand All @@ -106,7 +112,7 @@ private static Optional<PsiFile> getPsiFile(@Nullable final Project project,
.map(PsiDocumentManager::getInstance)
.map(mgr -> mgr.getPsiFile(document));
}

/**
* Submits the current file to Dodona.
*
Expand All @@ -117,14 +123,14 @@ private static void submit(final Project project,
final boolean checkSyntax) {
// Get the document.
final Document document = getDocument(project).orElseThrow(RuntimeException::new);

// Get the file.
final PsiFile file = getPsiFile(project, document).orElseThrow(RuntimeException::new);

try {
// Get the code.
final String code = document.getText();

// Validate the syntax.
if (checkSyntax) {
final Optional<CodeSmellInfo> syntaxError = findSyntaxError(project, file);
Expand All @@ -140,14 +146,14 @@ private static void submit(final Project project,
}
});
}

// Create a new SubmitTask and execute it.
SubmitSolutionTask.create(project, code).execute();
} catch (final CancelledException ignored) {
} catch (final UnidentifiedCodeException ignored) {
// Create a bus to broadcast the event when the exercise is identified.
final MessageBus bus = project.getMessageBus();

// Identify the exercise.
CodeIdentificationService.getInstance(project).identify(document).whenComplete((id, ex) -> {
if (id != null) {
Expand All @@ -158,9 +164,9 @@ private static void submit(final Project project,
});
}
}

@Override
public void update(@NotNull final AnActionEvent e) {
e.getPresentation().setEnabled(getDocument(e.getProject()).isPresent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.module.Module;
import com.jetbrains.python.module.PythonModuleBuilder;
import com.intellij.python.community.plugin.java.facet.PythonModuleBuilder;
import io.github.thepieterdc.dodona.plugin.DodonaBundle;
import io.github.thepieterdc.dodona.plugin.project.DodonaModuleBuilder;
import io.github.thepieterdc.dodona.plugin.project.types.DodonaPythonType;
Expand All @@ -30,64 +30,64 @@
public final class DodonaPythonBuilder extends PythonModuleBuilder implements DodonaModuleBuilder {
@NonNls
private static final String BUILDER_ID = "dodona-python";

private Course course;

/**
* DodonaJavaBuilder constructor.
*/
public DodonaPythonBuilder() {
super();
this.addListener(this);
}

@Nonnull
@Override
public String getBuilderId() {
return BUILDER_ID;
}

@Nonnull
@Override
public ModuleWizardStep getCustomOptionsStep(final WizardContext context, final Disposable parentDisposable) {
return BuilderUtils.createCourseSelectionStep(this);
}

@Override
public String getDescription() {
return DodonaPythonType.MODULE_TYPE_DESCRIPTION;
}

@Override
public String getGroupName() {
return DodonaBundle.NAME;
}

@Override
public Icon getNodeIcon() {
return Icons.DODONA;
}

@Override
public String getParentGroup() {
return DodonaBundle.NAME;
}

@Override
public String getPresentableName() {
return DodonaPythonType.MODULE_TYPE_NAME;
}

@Override
public int getWeight() {
return DodonaModuleBuilder.WEIGHT;
}

@Override
public void moduleCreated(@NotNull final Module module) {
BuilderUtils.finish(module, this.course);
}

@Override
public void setCourse(final Course course) {
this.course = course;
Expand Down

0 comments on commit edd72c0

Please sign in to comment.