diff --git a/CHANGELOG.md b/CHANGELOG.md index cc27491..1196556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Modularization supports namespace or locale module - Full namespace / locale module support for all file types - Support for object and array elements inside json arrays +- IDE integrated error report functionality ### Changed - Improve exception handling on IO operations diff --git a/src/main/java/de/marhali/easyi18n/service/ErrorReportHandler.java b/src/main/java/de/marhali/easyi18n/service/ErrorReportHandler.java new file mode 100644 index 0000000..c5aa416 --- /dev/null +++ b/src/main/java/de/marhali/easyi18n/service/ErrorReportHandler.java @@ -0,0 +1,77 @@ +package de.marhali.easyi18n.service; + +import com.intellij.ide.BrowserUtil; +import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.ErrorReportSubmitter; +import com.intellij.openapi.diagnostic.IdeaLoggingEvent; +import com.intellij.openapi.diagnostic.SubmittedReportInfo; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.NlsActions; +import com.intellij.util.Consumer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ResourceBundle; + +/** + * Easily create issues on the project repository if exceptions occur. + * @author marhali + */ +public class ErrorReportHandler extends ErrorReportSubmitter { + @Override + public @NlsActions.ActionText @NotNull String getReportActionText() { + return ResourceBundle.getBundle("messages").getString("error.submit"); + } + + @Override + public boolean submit(IdeaLoggingEvent @NotNull [] events, @Nullable String additionalInfo, + @NotNull Component parentComponent, @NotNull Consumer consumer) { + + if(events.length == 0) { + return false; + } + + IdeaLoggingEvent event = events[0]; + + DataManager mgr = DataManager.getInstance(); + DataContext context = mgr.getDataContext(parentComponent); + Project project = CommonDataKeys.PROJECT.getData(context); + + String title = "IDE Error Report"; + String labels = "ide report"; + String body = "# Additional information\n" + + additionalInfo + "\n" + + "# Exception trace\n" + + event.getMessage() + "\n" + + "```\n" + + event.getThrowableText() + + "\n```"; + + String url = "https://github.com/marhali/easy-i18n/issues/new?title=" + + encodeParam(title) + "&labels=" + encodeParam(labels) + "&body=" + encodeParam(body); + + new Task.Backgroundable(project, "Sending error report") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + BrowserUtil.browse(url); + + ApplicationManager.getApplication().invokeLater(() -> + consumer.consume(new SubmittedReportInfo(SubmittedReportInfo.SubmissionStatus.NEW_ISSUE))); + } + }.queue(); + + return true; + } + + private String encodeParam(String param) { + return URLEncoder.encode(param, StandardCharsets.UTF_8); + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index ab68bd6..ccb65d9 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -36,5 +36,7 @@ + + \ No newline at end of file diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 81d0b2b..778a844 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -28,4 +28,5 @@ settings.editor.assistance=I18n key completion, annotation and reference inside error.io=An error occurred while processing translation files. \n\ Config: {0} => {1} ({2}) \n\ Path: {3} \n\ - Please check examples at https://github.com/marhali/easy-i18n before reporting an issue! \ No newline at end of file + Please check examples at https://github.com/marhali/easy-i18n before reporting an issue! +error.submit=Open Issue \ No newline at end of file