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

New simple IJ inspector for the analysis_options.yaml file #7858

Closed
wants to merge 1 commit 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
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 @@ -401,6 +401,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 @@ -338,6 +338,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
Loading