-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* adds an inspection that checks for mismatched SDKs and pops up an editor notification (#54) * introduces `FlutterSettings` for persisting settings * adds a new `FlutterSdkService` with Small and IDEA IDE implementations (#61)
- Loading branch information
Showing
10 changed files
with
277 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- Defines IDEA IDE-specific contributions and implementations. --> | ||
<idea-plugin version="2"> | ||
<extensions defaultExtensionNs="com.intellij"> | ||
<projectService serviceInterface="io.flutter.sdk.FlutterSdkService" serviceImplementation="io.flutter.sdk.FlutterIdeaSdkService" | ||
overrides="true"/> | ||
<editorNotificationProvider implementation="io.flutter.inspections.WrongDartSdkConfigurationNotificationProvider"/> | ||
</extensions> | ||
</idea-plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
<idea-plugin version="2"> | ||
<id>io.flutter</id> | ||
<name>flutter-intellij</name> | ||
<description><![CDATA[ | ||
Flutter-specific extensions for Dart. | ||
]]></description> | ||
|
||
<vendor>flutter.io</vendor> | ||
|
||
<depends>Dart</depends> | ||
|
||
<description><![CDATA[ | ||
Flutter-specific extensions for Dart. | ||
]]></description> | ||
<!-- Contributes IDEA-specific features and implementations. --> | ||
<depends optional="true" config-file="idea-contribs.xml">com.intellij.modules.java</depends> | ||
|
||
<!-- Everything following should be SmallIDE-friendly.--> | ||
<!-- See: http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html --> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<configurationType implementation="io.flutter.run.FlutterRunConfigurationType"/> | ||
<runConfigurationProducer implementation="io.flutter.run.FlutterRunConfigurationProducer"/> | ||
<programRunner implementation="io.flutter.run.FlutterRunner"/> | ||
|
||
<moduleType id="FLUTTER_MODULE_TYPE" implementationClass="io.flutter.module.FlutterModuleType"/> | ||
|
||
<projectService serviceInterface="io.flutter.settings.FlutterSettings" serviceImplementation="io.flutter.settings.FlutterSettings"/> | ||
|
||
<!-- SDK type support WIP; see: #55 /--> | ||
<!--sdkType implementation="io.flutter.sdk.FlutterSdkType"/--> | ||
|
||
<!-- Plugin service with SmallIDE default, optionally overridden by product-specific implementations --> | ||
<projectService serviceInterface="io.flutter.sdk.FlutterSdkService" serviceImplementation="io.flutter.sdk.FlutterSmallIDESdkService" | ||
overrides="false"/> | ||
|
||
<applicationConfigurable groupId="language" instance="io.flutter.sdk.FlutterSettingsConfigurable" | ||
id="flutter.settings" key="flutter.title" bundle="io.flutter.FlutterBundle" nonDefaultProject="true"/> | ||
id="flutter.settings" key="flutter.title" bundle="io.flutter.FlutterBundle" nonDefaultProject="true"/> | ||
</extensions> | ||
|
||
</idea-plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/io/flutter/inspections/WrongDartSdkConfigurationNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2016 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.execution.ExecutionException; | ||
import com.intellij.openapi.fileEditor.FileEditor; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.module.ModuleType; | ||
import com.intellij.openapi.module.ModuleUtilCore; | ||
import com.intellij.openapi.project.DumbAware; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.Key; | ||
import com.intellij.openapi.util.text.StringUtil; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.PsiManager; | ||
import com.intellij.ui.EditorNotificationPanel; | ||
import com.intellij.ui.EditorNotifications; | ||
import com.jetbrains.lang.dart.DartFileType; | ||
import com.jetbrains.lang.dart.DartLanguage; | ||
import com.jetbrains.lang.dart.sdk.DartSdk; | ||
import io.flutter.FlutterBundle; | ||
import io.flutter.module.FlutterModuleType; | ||
import io.flutter.sdk.FlutterSdk; | ||
import io.flutter.sdk.FlutterSdkService; | ||
import io.flutter.settings.FlutterSettings; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class WrongDartSdkConfigurationNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> | ||
implements DumbAware { | ||
private static final Key<EditorNotificationPanel> KEY = Key.create("Setup Dart SDK"); | ||
|
||
private final Project project; | ||
|
||
public WrongDartSdkConfigurationNotificationProvider(@NotNull Project project, @NotNull EditorNotifications notifications) { | ||
this.project = project; | ||
} | ||
|
||
@NotNull | ||
private static EditorNotificationPanel createWrongSdkPanel(@NotNull Project project, @Nullable Module module) { | ||
|
||
final FlutterSettings settings = FlutterSettings.getInstance(project); | ||
if (settings.ignoreMismatchedDartSdks()) return null; | ||
|
||
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.createActionLabel("Dismiss", () -> { | ||
settings.setIgnoreMismatchedDartSdks(true); | ||
panel.setVisible(false); | ||
}); | ||
|
||
return panel; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Key<EditorNotificationPanel> getKey() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { | ||
if (file.getFileType() != DartFileType.INSTANCE) return null; | ||
|
||
PsiFile psiFile = PsiManager.getInstance(project).findFile(file); | ||
if (psiFile == null) return null; | ||
|
||
if (psiFile.getLanguage() != DartLanguage.INSTANCE) return null; | ||
|
||
Module module = ModuleUtilCore.findModuleForPsiElement(psiFile); | ||
if (module == null) return null; | ||
|
||
if (!ModuleType.is(module, FlutterModuleType.getInstance())) return null; | ||
|
||
try { | ||
final String flutterDartSdkPath = FlutterSdk.getFlutterSdk(project).getDartSdkPath(); | ||
final String dartSdkPath = DartSdk.getDartSdk(project).getHomePath(); | ||
if (!StringUtil.equals(flutterDartSdkPath, dartSdkPath)) { | ||
return createWrongSdkPanel(project, module); | ||
} | ||
} | ||
catch (ExecutionException e) { | ||
//TODO(pq): add panel for unconfigured Flutter SDK. | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2016 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.sdk; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.project.Project; | ||
import com.jetbrains.lang.dart.sdk.DartConfigurable; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class FlutterIdeaSdkService extends FlutterSdkService { | ||
public FlutterIdeaSdkService(Project project) { | ||
super(project); | ||
} | ||
|
||
@Override | ||
public void configureDartSdk(@NotNull Module module) { | ||
//TODO(pq): consider a service that sets this value or seeds the dialog with a proposed path | ||
DartConfigurable.openDartSettings(module.getProject()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2016 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.sdk; | ||
|
||
|
||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.project.Project; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* A service to coordinate SDK configuration with specific IDEA and SmallIDE | ||
* implementations. | ||
*/ | ||
public abstract class FlutterSdkService { | ||
|
||
@NotNull | ||
protected final Project project; | ||
|
||
protected FlutterSdkService(@NotNull Project project) { | ||
this.project = project; | ||
} | ||
|
||
public static FlutterSdkService getInstance(@NotNull Project project) { | ||
return ServiceManager.getService(project, FlutterSdkService.class); | ||
} | ||
|
||
public abstract void configureDartSdk(@Nullable Module module); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2016 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.sdk; | ||
|
||
import com.intellij.openapi.module.Module; | ||
import com.intellij.openapi.project.Project; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class FlutterSmallIDESdkService extends FlutterSdkService { | ||
|
||
public FlutterSmallIDESdkService(Project project) { | ||
super(project); | ||
} | ||
|
||
@Override | ||
public void configureDartSdk(@NotNull Module module) { | ||
//TODO(pq): implement | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2016 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.settings; | ||
|
||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.util.xmlb.XmlSerializerUtil; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
|
||
/** | ||
* Persists Flutter settings. | ||
*/ | ||
@State( | ||
name = "FlutterSettings", | ||
storages = { | ||
@Storage("FlutterSettings.xml")} | ||
) | ||
public class FlutterSettings implements PersistentStateComponent<FlutterSettings> { | ||
|
||
private boolean ignoreMismatchedDartSdks; | ||
|
||
@Nullable | ||
public static FlutterSettings getInstance(Project project) { | ||
return ServiceManager.getService(project, FlutterSettings.class); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public FlutterSettings getState() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void loadState(FlutterSettings settings) { | ||
XmlSerializerUtil.copyBean(settings, this); | ||
} | ||
|
||
public boolean ignoreMismatchedDartSdks() { | ||
return ignoreMismatchedDartSdks; | ||
} | ||
|
||
public void setIgnoreMismatchedDartSdks(boolean ignoreMismatchedDartSdks) { | ||
this.ignoreMismatchedDartSdks = ignoreMismatchedDartSdks; | ||
} | ||
} |