Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IntelliJ plugin on IJP 242 #501

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Build ktfmt_idea_plugin
run: |
pushd ktfmt_idea_plugin
./gradlew build
./gradlew build --no-daemon
popd
- name: Build the Online Formatter
run: |
pushd online_formatter
./gradlew build
./gradlew build --no-daemon
popd
2 changes: 1 addition & 1 deletion .github/workflows/publish_artifacts_on_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Publish IntelliJ plugin to JetBrains Marketplace
run: |
pushd ktfmt_idea_plugin
./gradlew publishPlugin --stacktrace
./gradlew publishPlugin --stacktrace --no-daemon
popd
env:
JETBRAINS_MARKETPLACE_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
Expand Down
7 changes: 7 additions & 0 deletions ktfmt_idea_plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType.*

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
Expand Down Expand Up @@ -66,3 +68,8 @@ intellijPlatform {
}

spotless { java { googleJavaFormat(libs.versions.googleJavaFormat.get()) } }

val runIntellij242 by intellijPlatformTesting.runIde.registering {
type = IntellijIdeaCommunity
version = "2024.2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
package com.facebook.ktfmt.intellij;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;

final class InitialConfigurationStartupActivity implements StartupActivity.Background {

private static final String NOTIFICATION_TITLE = "Enable ktfmt";
private static final NotificationGroup NOTIFICATION_GROUP =
NotificationGroupManager.getInstance().getNotificationGroup(NOTIFICATION_TITLE);

@Override
public void runActivity(@NotNull Project project) {

KtfmtSettings settings = KtfmtSettings.getInstance(project);

if (settings.isUninitialized()) {
Expand All @@ -42,16 +40,23 @@ public void runActivity(@NotNull Project project) {
}

private void displayNewUserNotification(Project project, KtfmtSettings settings) {
new Notification(
NOTIFICATION_GROUP.getDisplayId(),
Notification notification =
new Notification(
NotificationGroupManager.getInstance()
.getNotificationGroup(NOTIFICATION_TITLE)
.getDisplayId(),
NOTIFICATION_TITLE,
"The ktfmt plugin is disabled by default. "
+ "<a href=\"enable\">Enable for this project</a>.",
NotificationType.INFORMATION)
.setListener(
(n, e) -> {
settings.setEnabled(true);
n.expire();
"The ktfmt plugin is disabled by default.",
NotificationType.INFORMATION);

notification
.addAction(
new AnAction("Enable for This Project") {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
settings.setEnabled(true);
notification.expire();
}
})
.notify(project);
}
Expand Down