Skip to content

Commit 315fa0c

Browse files
authored
Require Dart 2.12 or later (#91)
* Require Dart 2.12 or later * Add a note about a constant that's not referring to a Dart version
1 parent 2dde5a6 commit 315fa0c

34 files changed

+144
-635
lines changed

third_party/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 501.0.0
2+
3+
### Removed
4+
5+
- Dropped support for Dart SDK versions older than 2.12.
6+
17
## 500.0.0
28

39
### Added

third_party/src/main/java/com/jetbrains/lang/dart/DartFileListener.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import com.jetbrains.lang.dart.sdk.DartPackagesLibraryType;
4040
import com.jetbrains.lang.dart.sdk.DartSdk;
4141
import com.jetbrains.lang.dart.sdk.DartSdkLibUtil;
42-
import com.jetbrains.lang.dart.util.DotPackagesFileUtil;
42+
import com.jetbrains.lang.dart.util.PackageConfigFileUtil;
4343
import org.jetbrains.annotations.NotNull;
4444
import org.jetbrains.annotations.Nullable;
4545

@@ -69,10 +69,8 @@ public final class DartFileListener implements AsyncFileListener {
6969

7070
if (event instanceof VFilePropertyChangeEvent) {
7171
if (((VFilePropertyChangeEvent)event).isRename()) {
72-
if (DotPackagesFileUtil.PACKAGE_CONFIG_JSON.equals(((VFilePropertyChangeEvent)event).getOldValue()) ||
73-
DotPackagesFileUtil.PACKAGE_CONFIG_JSON.equals(((VFilePropertyChangeEvent)event).getNewValue()) ||
74-
DotPackagesFileUtil.DOT_PACKAGES.equals(((VFilePropertyChangeEvent)event).getOldValue()) ||
75-
DotPackagesFileUtil.DOT_PACKAGES.equals(((VFilePropertyChangeEvent)event).getNewValue())) {
72+
if (PackageConfigFileUtil.PACKAGE_CONFIG_JSON.equals(((VFilePropertyChangeEvent)event).getOldValue()) ||
73+
PackageConfigFileUtil.PACKAGE_CONFIG_JSON.equals(((VFilePropertyChangeEvent)event).getNewValue())) {
7674
packagesFileEvents.add(event);
7775
}
7876

@@ -83,8 +81,7 @@ public final class DartFileListener implements AsyncFileListener {
8381
}
8482
}
8583
else {
86-
if (DotPackagesFileUtil.PACKAGE_CONFIG_JSON.equals(PathUtil.getFileName(event.getPath())) ||
87-
DotPackagesFileUtil.DOT_PACKAGES.equals(PathUtil.getFileName(event.getPath()))) {
84+
if (PackageConfigFileUtil.PACKAGE_CONFIG_JSON.equals(PathUtil.getFileName(event.getPath()))) {
8885
packagesFileEvents.add(event);
8986
}
9087

@@ -138,15 +135,9 @@ public static void scheduleDartPackageRootsUpdate(final @NotNull Project project
138135
if (module == null || !DartSdkLibUtil.isDartSdkEnabled(module)) continue;
139136

140137
Map<String, String> packagesMap = null;
141-
VirtualFile packagesFile = DotPackagesFileUtil.findPackageConfigJsonFile(pubspecFile.getParent());
138+
VirtualFile packagesFile = PackageConfigFileUtil.findPackageConfigJsonFile(pubspecFile.getParent());
142139
if (packagesFile != null) {
143-
packagesMap = DotPackagesFileUtil.getPackagesMapFromPackageConfigJsonFile(packagesFile);
144-
}
145-
else {
146-
packagesFile = DotPackagesFileUtil.findDotPackagesFile(pubspecFile.getParent());
147-
if (packagesFile != null) {
148-
packagesMap = DotPackagesFileUtil.getPackagesMap(packagesFile);
149-
}
140+
packagesMap = PackageConfigFileUtil.getPackagesMapFromPackageConfigJsonFile(packagesFile);
150141
}
151142

152143
if (packagesMap != null) {
@@ -359,7 +350,7 @@ public void afterVfsChange() {
359350
if (file == null) continue;
360351

361352
VirtualFile dartRoot = file.getParent();
362-
if (dartRoot != null && file.getName().equals(DotPackagesFileUtil.PACKAGE_CONFIG_JSON)) {
353+
if (dartRoot != null && file.getName().equals(PackageConfigFileUtil.PACKAGE_CONFIG_JSON)) {
363354
dartRoot = dartRoot.getParent();
364355
}
365356
VirtualFile pubspec = dartRoot == null ? null : dartRoot.findChild(PUBSPEC_YAML);

third_party/src/main/java/com/jetbrains/lang/dart/analyzer/DartAnalysisServerService.java

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,11 @@
8080
import java.util.concurrent.TimeUnit;
8181

8282
public final class DartAnalysisServerService implements Disposable {
83-
public static final String MIN_SDK_VERSION = "1.12";
84-
private static final String MIN_MOVE_FILE_SDK_VERSION = "2.3.2";
85-
private static final String COMPLETION_2_SERVER_VERSION = "1.33";
86-
87-
// Webdev works going back to 2.6.0, future minimum version listed in the pubspec.yaml, link below, won't mean that 2.6.0 aren't
88-
// supported.
89-
// https://github.com/dart-lang/webdev/blob/master/webdev/pubspec.yaml#L11
90-
public static final String MIN_WEBDEV_SDK_VERSION = "2.6.0";
83+
public static final String MIN_SDK_VERSION = "2.12";
9184

92-
// As of the Dart SDK version 2.8.0, the file .dart_tool/package_config.json is preferred over the .packages file.
93-
// https://github.com/dart-lang/sdk/issues/48272
94-
public static final String MIN_PACKAGE_CONFIG_JSON_SDK_VERSION = "2.8.0";
85+
// This refers to the Analysis Server API version (from `getVersion`),
86+
// not a Dart SDK version.
87+
private static final String COMPLETION_2_SERVER_VERSION = "1.33";
9588

9689
// The dart cli command provides a language server command, `dart language-server`, which
9790
// should be used going forward instead of `dart .../analysis_server.dart.snapshot`.
@@ -487,18 +480,6 @@ public static boolean isDartSdkVersionSufficient(final @NotNull DartSdk sdk) {
487480
return StringUtil.compareVersionNumbers(sdk.getVersion(), MIN_SDK_VERSION) >= 0;
488481
}
489482

490-
public static boolean isDartSdkVersionSufficientForMoveFileRefactoring(final @NotNull DartSdk sdk) {
491-
return StringUtil.compareVersionNumbers(sdk.getVersion(), MIN_MOVE_FILE_SDK_VERSION) >= 0;
492-
}
493-
494-
public static boolean isDartSdkVersionSufficientForWebdev(final @NotNull DartSdk sdk) {
495-
return StringUtil.compareVersionNumbers(sdk.getVersion(), MIN_WEBDEV_SDK_VERSION) >= 0;
496-
}
497-
498-
public static boolean isDartSdkVersionSufficientForPackageConfigJson(final @NotNull DartSdk sdk) {
499-
return StringUtil.compareVersionNumbers(sdk.getVersion(), MIN_PACKAGE_CONFIG_JSON_SDK_VERSION) >= 0;
500-
}
501-
502483
public static boolean isDartSdkVersionSufficientForDartLangServer(final @NotNull DartSdk sdk) {
503484
return StringUtil.compareVersionNumbers(sdk.getVersion(), MIN_DART_LANG_SERVER_SDK_VERSION) >= 0;
504485
}
@@ -1238,10 +1219,6 @@ public boolean edit_isPostfixCompletionApplicable(VirtualFile file, int _offset,
12381219
return null;
12391220
}
12401221

1241-
if (StringUtil.compareVersionNumbers(mySdkVersion, "1.25") < 0) {
1242-
return PostfixTemplateDescriptor.EMPTY_ARRAY;
1243-
}
1244-
12451222
final Ref<PostfixTemplateDescriptor[]> resultRef = Ref.create();
12461223
final CountDownLatch latch = new CountDownLatch(1);
12471224
server.edit_listPostfixCompletionTemplates(new ListPostfixCompletionTemplatesConsumer() {
@@ -1729,7 +1706,7 @@ public void onError(final RequestError error) {
17291706
final int _selectionOffset,
17301707
final int _selectionLength) {
17311708
final AnalysisServer server = myServer;
1732-
if (server == null || StringUtil.compareVersionNumbers(mySdkVersion, "1.25") < 0) {
1709+
if (server == null) {
17331710
return null;
17341711
}
17351712

@@ -1768,7 +1745,7 @@ public void onError(final RequestError error) {
17681745
final @NotNull List<ImportedElements> importedElements,
17691746
final int _offset) {
17701747
final AnalysisServer server = myServer;
1771-
if (server == null || StringUtil.compareVersionNumbers(mySdkVersion, "1.25") < 0) {
1748+
if (server == null) {
17721749
return null;
17731750
}
17741751

@@ -1933,12 +1910,8 @@ private void analysis_setSubscriptions() {
19331910
subscriptions.put(AnalysisService.NAVIGATION, myVisibleFileUris);
19341911
subscriptions.put(AnalysisService.OVERRIDES, myVisibleFileUris);
19351912
subscriptions.put(AnalysisService.OUTLINE, myVisibleFileUris);
1936-
if (StringUtil.compareVersionNumbers(mySdkVersion, "1.13") >= 0) {
1937-
subscriptions.put(AnalysisService.IMPLEMENTED, myVisibleFileUris);
1938-
}
1939-
if (StringUtil.compareVersionNumbers(mySdkVersion, "1.25.0") >= 0) {
1940-
subscriptions.put(AnalysisService.CLOSING_LABELS, myVisibleFileUris);
1941-
}
1913+
subscriptions.put(AnalysisService.IMPLEMENTED, myVisibleFileUris);
1914+
subscriptions.put(AnalysisService.CLOSING_LABELS, myVisibleFileUris);
19421915

19431916
if (LOG.isDebugEnabled()) {
19441917
LOG.debug("analysis_setSubscriptions, subscriptions:\n" + subscriptions);
@@ -2186,15 +2159,7 @@ else if (!useDartLangServerCall && !dasSnapshotFile.canRead()) {
21862159
vmArgsRaw = "";
21872160
}
21882161

2189-
@NonNls String serverArgsRaw;
2190-
if (useDartLangServerCall) {
2191-
serverArgsRaw = "--protocol=analyzer";
2192-
}
2193-
else {
2194-
// Note that as of Dart 2.12.0 the '--useAnalysisHighlight2' flag is ignored (and is the
2195-
// default highlighting mode). We still want to pass it in for earlier SDKs.
2196-
serverArgsRaw = "--useAnalysisHighlight2";
2197-
}
2162+
String serverArgsRaw = useDartLangServerCall ? "--protocol=analyzer" : "";
21982163

21992164
try {
22002165
serverArgsRaw += " " + Registry.stringValue("dart.server.additional.arguments");

third_party/src/main/java/com/jetbrains/lang/dart/ide/actions/DartEditorNotificationsProvider.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.openapi.module.ModuleUtilCore;
1515
import com.intellij.openapi.project.Project;
1616
import com.intellij.openapi.util.NlsContexts;
17-
import com.intellij.openapi.util.text.StringUtil;
1817
import com.intellij.openapi.vfs.VirtualFile;
1918
import com.intellij.psi.PsiFile;
2019
import com.intellij.psi.PsiManager;
@@ -53,7 +52,7 @@ public final class DartEditorNotificationsProvider implements EditorNotification
5352

5453
final DartSdk sdk = DartSdk.getDartSdk(project);
5554
if (sdk != null && DartSdkLibUtil.isDartSdkEnabled(module)) {
56-
return fileEditor -> new PubActionsPanel(fileEditor, sdk);
55+
return fileEditor -> new PubActionsPanel(fileEditor);
5756
}
5857
}
5958

@@ -116,14 +115,11 @@ public final class DartEditorNotificationsProvider implements EditorNotification
116115
}
117116

118117
private static final class PubActionsPanel extends EditorNotificationPanel {
119-
private PubActionsPanel(@NotNull FileEditor fileEditor, @NotNull DartSdk sdk) {
118+
private PubActionsPanel(@NotNull FileEditor fileEditor) {
120119
super(fileEditor, null, EditorColors.GUTTER_BACKGROUND, Status.Info);
121120
createActionLabel(DartBundle.message("pub.get"), "Dart.pub.get");
122121
createActionLabel(DartBundle.message("pub.upgrade"), "Dart.pub.upgrade");
123-
124-
if (StringUtil.compareVersionNumbers(sdk.getVersion(), DartPubOutdatedAction.MIN_SDK_VERSION) >= 0) {
125-
createActionLabel(DartBundle.message("pub.outdated"), "Dart.pub.outdated");
126-
}
122+
createActionLabel(DartBundle.message("pub.outdated"), "Dart.pub.outdated");
127123

128124
myLinksPanel.add(new JSeparator(SwingConstants.VERTICAL));
129125
createActionLabel(DartBundle.message("webdev.build"), "Dart.build");

third_party/src/main/java/com/jetbrains/lang/dart/ide/actions/DartPubActionBase.kt

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import com.intellij.openapi.util.Disposer
3636
import com.intellij.openapi.util.Key
3737
import com.intellij.openapi.util.NlsContexts
3838
import com.intellij.openapi.util.io.FileUtil
39-
import com.intellij.openapi.util.text.StringUtil
4039
import com.intellij.openapi.vfs.VfsUtil
4140
import com.intellij.openapi.vfs.VirtualFile
4241
import com.intellij.openapi.wm.ToolWindowId
@@ -77,7 +76,7 @@ abstract class DartPubActionBase : AnAction(), DumbAware {
7776
e.presentation.isEnabled = visible && !isInProgress
7877
}
7978

80-
protected abstract fun getTitle(project: Project, pubspecYamlFile: VirtualFile): String
79+
protected abstract fun getTitle(pubspecYamlFile: VirtualFile): String
8180

8281
protected abstract fun calculatePubParameters(project: Project, pubspecYamlFile: VirtualFile): Array<String>?
8382

@@ -92,7 +91,7 @@ abstract class DartPubActionBase : AnAction(), DumbAware {
9291
if (sdk == null && allowModalDialogs) {
9392
val answer = Messages.showDialog(module.project,
9493
DartBundle.message("dart.sdk.is.not.configured"),
95-
getTitle(module.project, pubspecYamlFile),
94+
getTitle(pubspecYamlFile),
9695
arrayOf(DartBundle.message("setup.dart.sdk"), CommonBundle.getCancelButtonText()),
9796
Messages.OK,
9897
Messages.getErrorIcon())
@@ -104,14 +103,13 @@ abstract class DartPubActionBase : AnAction(), DumbAware {
104103

105104
if (sdk == null) return
106105

107-
val useDartPub = StringUtil.compareVersionNumbers(sdk.version, DART_PUB_MIN_SDK_VERSION) >= 0
108-
val exeFile = if (useDartPub) File(DartSdkUtil.getDartExePath(sdk)) else File(DartSdkUtil.getPubPath(sdk))
106+
val exeFile = File(DartSdkUtil.getDartExePath(sdk))
109107

110108
if (!exeFile.isFile) {
111109
if (allowModalDialogs) {
112110
val answer = Messages.showDialog(module.project,
113111
DartBundle.message("dart.sdk.bad.dartpub.path", exeFile.path),
114-
getTitle(module.project, pubspecYamlFile),
112+
getTitle(pubspecYamlFile),
115113
arrayOf(DartBundle.message("setup.dart.sdk"), CommonBundle.getCancelButtonText()),
116114
Messages.OK,
117115
Messages.getErrorIcon())
@@ -135,7 +133,7 @@ abstract class DartPubActionBase : AnAction(), DumbAware {
135133
setupPubExePath(command, sdk)
136134
command.addParameters(*pubParameters)
137135

138-
doPerformPubAction(module, pubspecYamlFile, command, getTitle(module.project, pubspecYamlFile))
136+
doPerformPubAction(module, pubspecYamlFile, command, getTitle(pubspecYamlFile))
139137
}
140138
}
141139

@@ -185,25 +183,12 @@ abstract class DartPubActionBase : AnAction(), DumbAware {
185183
private const val GROUP_DISPLAY_ID: @NonNls String = "Dart Pub Tool"
186184
private val PUB_TOOL_WINDOW_CONTENT_INFO_KEY = Key.create<PubToolWindowContentInfo>("PUB_TOOL_WINDOW_CONTENT_INFO_KEY")
187185

188-
private const val DART_PUB_MIN_SDK_VERSION = "2.10"
189-
private const val DART_RUN_TEST_MIN_SDK_VERSION = "2.11"
190-
191186
private val ourInProgress = AtomicBoolean(false)
192187

193-
@JvmStatic
194-
fun isUseDartRunTestInsteadOfPubRunTest(dartSdk: DartSdk): Boolean =
195-
StringUtil.compareVersionNumbers(dartSdk.version, DART_RUN_TEST_MIN_SDK_VERSION) >= 0
196-
197188
@JvmStatic
198189
fun setupPubExePath(commandLine: GeneralCommandLine, dartSdk: DartSdk) {
199-
val useDartPub = StringUtil.compareVersionNumbers(dartSdk.version, DART_PUB_MIN_SDK_VERSION) >= 0
200-
if (useDartPub) {
201-
commandLine.withExePath(FileUtil.toSystemDependentName(DartSdkUtil.getDartExePath(dartSdk)))
202-
commandLine.addParameter("pub")
203-
}
204-
else {
205-
commandLine.withExePath(FileUtil.toSystemDependentName(DartSdkUtil.getPubPath(dartSdk)))
206-
}
190+
commandLine.withExePath(FileUtil.toSystemDependentName(DartSdkUtil.getDartExePath(dartSdk)))
191+
commandLine.addParameter("pub")
207192
}
208193

209194
@JvmStatic

third_party/src/main/java/com/jetbrains/lang/dart/ide/actions/DartPubBuildAction.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,16 @@ public class DartPubBuildAction extends DartPubActionBase {
1717
@Override
1818
public void update(@NotNull AnActionEvent e) {
1919
super.update(e);
20-
final Project project = e.getProject();
21-
if (project != null && DartWebdev.INSTANCE.useWebdev(DartSdk.getDartSdk(project))) {
22-
e.getPresentation().setText(DartBundle.message("action.text.webdev.build"));
23-
e.getPresentation().setDescription(DartBundle.message("action.description.run.webdev.build"));
24-
}
25-
else {
26-
e.getPresentation().setText(DartBundle.message("action.text.pub.build"));
27-
e.getPresentation().setDescription(DartBundle.message("action.description.run.pub.build"));
28-
}
20+
21+
e.getPresentation().setText(DartBundle.message("action.text.webdev.build"));
22+
e.getPresentation().setDescription(DartBundle.message("action.description.run.webdev.build"));
2923
}
3024

3125
@Override
32-
protected @NotNull @NlsContexts.DialogTitle String getTitle(final @NotNull Project project, final @NotNull VirtualFile pubspecYamlFile) {
26+
protected @NotNull @NlsContexts.DialogTitle String getTitle(final @NotNull VirtualFile pubspecYamlFile) {
3327
final String projectName = PubspecYamlUtil.getDartProjectName(pubspecYamlFile);
3428
final String prefix = projectName == null ? "" : ("[" + projectName + "] ");
35-
return prefix + DartBundle
36-
.message(DartWebdev.INSTANCE.useWebdev(DartSdk.getDartSdk(project)) ? "dart.webdev.build.title" : "dart.pub.build.title");
29+
return prefix + DartBundle.message("dart.webdev.build.title");
3730
}
3831

3932
@Override
@@ -47,12 +40,8 @@ public void update(@NotNull AnActionEvent e) {
4740
final DartSdk sdk = DartSdk.getDartSdk(project);
4841
if (sdk == null) return null; // can't happen, already checked
4942

50-
if (DartWebdev.INSTANCE.useWebdev(sdk)) {
51-
if (!DartWebdev.INSTANCE.ensureWebdevActivated(project)) return null;
52-
53-
return new String[]{"global", "run", "webdev", "build", "--output=" + dialog.getInputFolder() + ":" + dialog.getOutputFolder()};
54-
}
43+
if (!DartWebdev.INSTANCE.ensureWebdevActivated(project)) return null;
5544

56-
return new String[]{"build", "--mode=" + dialog.getPubBuildMode(), "--output=" + dialog.getOutputFolder()};
45+
return new String[]{"global", "run", "webdev", "build", "--output=" + dialog.getInputFolder() + ":" + dialog.getOutputFolder()};
5746
}
5847
}

0 commit comments

Comments
 (0)