Skip to content

Commit

Permalink
Resolves this issue, flutter#7843 (if we want to include it).
Browse files Browse the repository at this point in the history
  • Loading branch information
jwren committed Dec 10, 2024
1 parent 1388a17 commit 984dab8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions flutter-idea/src/io/flutter/FlutterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ error.sdk.not.found.in.specified.location=Flutter SDK is not found in the specif
flutter.command.exception.message=Exception: {0}
flutter.module.name=Flutter
flutter.no.sdk.warning=No Flutter SDK configured.
flutter.analysis.options.docs=Static analysis documentation
flutter.project.description=Build high-performance, high-fidelity, apps using the Flutter framework.
flutter.sdk.browse.path.label=Select Flutter SDK Path
flutter.sdk.is.not.configured=The Flutter SDK is not configured
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2024 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.inspections;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotificationProvider;
import icons.FlutterIcons;
import io.flutter.FlutterBundle;
import io.flutter.pub.PubRoot;
import io.flutter.utils.FlutterModuleUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.function.Function;

/**
* This EditorNotificationProvider opens a banner at the top of analysis_options.yaml files and directs developers to reference the
* documentation at dart.dev/tools/analysis
*/
public class AnalysisOptionsNotificationProvider implements EditorNotificationProvider {
private static final String DOC_URL = "https://dart.dev/tools/analysis";

@Override
@Nullable
public Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project,
@NotNull VirtualFile file) {
// If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;

// If the file name does not match "analysis_options.yaml"
if (!file.getName().equals(PubRoot.ANALYSIS_OPTIONS_YAML)) return null;

final Module module = ModuleUtilCore.findModuleForFile(file, project);
if (!FlutterModuleUtils.isFlutterModule(module)) return null;

return fileEditor -> createAnalysisOptionsPanel(fileEditor, project);
}

private static EditorNotificationPanel createAnalysisOptionsPanel(@NotNull FileEditor fileEditor, @NotNull Project project) {
final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.icon(FlutterIcons.Flutter);
panel.setText(FlutterBundle.message("flutter.analysis.options.docs"));
// When the user dismissed this banner, it goes away, but will appear when the user opens the file again
panel.createActionLabel(DOC_URL, () -> BrowserUtil.browse(DOC_URL));
panel.createActionLabel("Dismiss", () -> panel.setVisible(false));
return panel;
}
}
1 change: 1 addition & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
<editorNotificationProvider implementation="io.flutter.inspections.SdkConfigurationNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.editor.NativeEditorNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.samples.FlutterSampleNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.inspections.AnalysisOptionsNotificationProvider"/>

<projectService serviceInterface="io.flutter.run.FlutterReloadManager"
serviceImplementation="io.flutter.run.FlutterReloadManager"
Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/plugin_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
<editorNotificationProvider implementation="io.flutter.inspections.SdkConfigurationNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.editor.NativeEditorNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.samples.FlutterSampleNotificationProvider"/>
<editorNotificationProvider implementation="io.flutter.inspections.AnalysisOptionsNotificationProvider"/>

<projectService serviceInterface="io.flutter.run.FlutterReloadManager"
serviceImplementation="io.flutter.run.FlutterReloadManager"
Expand Down

0 comments on commit 984dab8

Please sign in to comment.