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

Show error when Dart SDK is not set correctly (#636) #637

Closed
wants to merge 2 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
2 changes: 1 addition & 1 deletion src/io/flutter/FlutterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ flutter.command.missing.pubspec=Missing pubspec
flutter.command.missing.pubspec.message=`{0}` can only be run on a project with a pubspec.yaml.
flutter.incompatible.dart.plugin.warning=Flutter requires a Dart plugin with a minimum version of {0} (currently installed: {1}).
flutter.module.name=Flutter
flutter.no.sdk.warning=No Flutter SDK Configured.
flutter.old.sdk.warning=The current configured Flutter SDK is not known to be fully supported. Please update your SDK and restart IntelliJ.
flutter.project.description=Build high-performance, high-fidelity, mobile apps for iOS and Android using the Flutter framework.
flutter.sdk.browse.path.label=Select Flutter SDK Path
flutter.sdk.is.not.configured=The Flutter SDK is not configured
flutter.sdk.path.label=Flutter &SDK path:
flutter.support.is.not.enabled.for.module.0=Flutter support is not enabled for module ''{0}''
flutter.title=Flutter
flutter.wrong.dart.sdk.warning=The Dart SDK for this module is not the same as Flutter's. Setting Dart to use the Flutter vended SDK is strongly recommended.
flutter.sdk.notAvailable.title=No Flutter SDK Configured
flutter.sdk.notAvailable.message=This action requires a Flutter SDK to be available.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,18 @@ public SdkConfigurationNotificationProvider(@NotNull Project project) {
this.project = project;
}

@Nullable
private static EditorNotificationPanel createWrongSdkPanel(@NotNull Project project, @Nullable Module module) {
if (module == null) return null;

final FlutterUIConfig settings = FlutterUIConfig.getInstance();
if (settings.shouldIgnoreMismatchedDartSdks()) return null;

@SuppressWarnings("SameReturnValue")
private static EditorNotificationPanel createNoFlutterSdkPanel() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this case being handled?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not possible

final EditorNotificationPanel panel = new EditorNotificationPanel();
panel.setText(FlutterBundle.message("flutter.wrong.dart.sdk.warning"));
panel.createActionLabel(FlutterBundle.message("dart.sdk.configuration.action.label"),
() -> FlutterSdkService.getInstance(project).configureDartSdk(module));
panel.setText(FlutterBundle.message("flutter.no.sdk.warning"));
panel.createActionLabel("Dismiss", () -> {
settings.setIgnoreMismatchedDartSdks();
panel.setVisible(false);
});

return panel;
}

@SuppressWarnings("SameReturnValue")
private static EditorNotificationPanel createNoFlutterSdkPanel() {
// TODO(pq): add panel for unconfigured Flutter SDK.
// TODO(skybrian) we should add a link to go to the Dart SDK panel.
// However, not yet because this will change with 2017.1 to be project-specific.

return null;
return panel;
}

@NotNull
Expand All @@ -93,31 +81,13 @@ public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file

if (!FlutterSdkUtil.isFlutterModule(module)) return null;

try {
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
if (flutterSdk == null) {
return createNoFlutterSdkPanel();
}

if (flutterSdk.getVersion().isLessThan(MIN_SUPPORTED_SDK)) {
return createOutOfDateFlutterSdkPanel(flutterSdk);
}

final DartSdk dartSdk = DartSdk.getDartSdk(project);
if (dartSdk == null) {
// TODO(devoncarew): Recommend to set up with Flutter's dart sdk.

return null;
}

final String flutterDartSdkPath = flutterSdk.getDartSdkPath();
final String dartSdkPath = dartSdk.getHomePath();
if (!StringUtil.equals(flutterDartSdkPath, dartSdkPath)) {
return createWrongSdkPanel(project, module);
}
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
if (flutterSdk == null) {
return createNoFlutterSdkPanel();
}
catch (ExecutionException e) {
LOG.warn(e);

if (flutterSdk.getVersion().isLessThan(MIN_SUPPORTED_SDK)) {
return createOutOfDateFlutterSdkPanel(flutterSdk);
}

return null;
Expand Down
19 changes: 8 additions & 11 deletions src/io/flutter/sdk/FlutterSdkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,22 @@ private void listenForSdkChanges() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
@Override
public void projectOpened(@NotNull Project project) {
checkForFlutterSdkAddition();
checkForFlutterSdkChange();
}

@Override
public void projectClosed(@NotNull Project project) {
checkForFlutterSdkRemoval();
checkForFlutterSdkChange();
}
});
}

private void checkForFlutterSdkAddition() {
// Send events if Flutter SDK was configured or unconfigured.
public void checkForFlutterSdkChange() {
if (!isFlutterConfigured && isGlobalFlutterSdkSetAndNeeded()) {
isFlutterConfigured = true;
myDispatcher.getMulticaster().flutterSdkAdded();
}
}

private void checkForFlutterSdkRemoval() {
if (isFlutterConfigured && !isGlobalFlutterSdkSetAndNeeded()) {
} else if (isFlutterConfigured && !isGlobalFlutterSdkSetAndNeeded()) {
isFlutterConfigured = false;
myDispatcher.getMulticaster().flutterSdkRemoved();
}
Expand Down Expand Up @@ -100,13 +97,13 @@ private final class LibraryTableListener implements LibraryTable.Listener {

@Override
public void afterLibraryAdded(Library newLibrary) {
checkForFlutterSdkAddition();
checkForFlutterSdkChange();
}

@Override
public void afterLibraryRenamed(Library library) {
// Since we key off name, test to be safe.
checkForFlutterSdkRemoval();
checkForFlutterSdkChange();
}

@Override
Expand All @@ -116,7 +113,7 @@ public void beforeLibraryRemoved(Library library) {

@Override
public void afterLibraryRemoved(Library library) {
checkForFlutterSdkRemoval();
checkForFlutterSdkChange();
}
}
}
3 changes: 3 additions & 0 deletions src/io/flutter/sdk/FlutterSdkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,8 @@ public static void setFlutterSdkPath(@NotNull final String flutterSdkPath) {

// Update the list of known sdk paths.
FlutterSdkUtil.updateKnownSdkPaths(flutterSdkPath);

// Fire events for a Flutter SDK change, which updates the UI.
FlutterSdkManager.getInstance().checkForFlutterSdkChange();
}
}
6 changes: 5 additions & 1 deletion src/io/flutter/sdk/FlutterSettingsConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,12 @@ public void apply() throws ConfigurationException {
public void reset() {
final FlutterSdk sdk = FlutterSdk.getGlobalFlutterSdk();
final String path = sdk != null ? sdk.getHomePath() : "";
mySdkCombo.getComboBox().getEditor().setItem(FileUtil.toSystemDependentName(path));
FlutterSdkUtil.addKnownSDKPathsToCombo(mySdkCombo.getComboBox());

// Set this after populating the combo box to display correctly when the Flutter SDK is unset.
// (This can happen if the user changed the Dart SDK.)
mySdkCombo.getComboBox().getEditor().setItem(FileUtil.toSystemDependentName(path));

updateVersionText();
myReportUsageInformationCheckBox.setSelected(FlutterInitializer.getCanReportAnalytics());
}
Expand Down