Skip to content

Commit

Permalink
[Dart] IDEA-363959 Pub workspaces: false error for inner package: 'Pu…
Browse files Browse the repository at this point in the history
…b Get has not been run'

close #933


(cherry picked from commit 42ed461a1682d59fe6642a672a466c1fd722bb28)

IJ-CR-150418

GitOrigin-RevId: 8fe072ed99b4f73c90f4c157a94c8794270ee0e8
  • Loading branch information
alexander-doroshko authored and intellij-monorepo-bot committed Nov 28, 2024
1 parent c89aa10 commit c1b3c4d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.lang.dart.ide.inspections;

import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
Expand Down Expand Up @@ -69,7 +69,7 @@ public final class DartOutdatedDependenciesInspection extends LocalInspectionToo
if (FlutterUtil.isPubspecDeclaringFlutter(pubspecFile)) return null; // 'pub get' will fail anyway

VirtualFile packagesFile = DartAnalysisServerService.isDartSdkVersionSufficientForPackageConfigJson(sdk)
? DotPackagesFileUtil.getPackageConfigJsonFile(pubspecFile)
? DotPackagesFileUtil.getPackageConfigJsonFile(project, pubspecFile)
: pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);

if (packagesFile == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.lang.dart.psi;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
Expand Down Expand Up @@ -44,11 +45,12 @@ class DartPackageAwareFileReference extends FileReference {
return new ResolveResult[]{new PsiElementResolveResult(psiDirectory)};
}

DartSdk sdk = DartSdk.getDartSdk(containingFile.getProject());
final Project project = containingFile.getProject();
DartSdk sdk = DartSdk.getDartSdk(project);
VirtualFile packagesFile;
if (sdk != null && pubspecYamlFile != null) {
if (DartAnalysisServerService.isDartSdkVersionSufficientForPackageConfigJson(sdk)) {
packagesFile = DotPackagesFileUtil.getPackageConfigJsonFile(pubspecYamlFile);
packagesFile = DotPackagesFileUtil.getPackageConfigJsonFile(project, pubspecYamlFile);
}
else {
packagesFile = pubspecYamlFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.lang.dart.util;

import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -212,7 +212,7 @@ private void initLivePackageNameToDirMap() {

Map<String, String> packagesMap;
if (myDartSdk == null || DartAnalysisServerService.isDartSdkVersionSufficientForPackageConfigJson(myDartSdk)) {
VirtualFile packagesFile = DotPackagesFileUtil.getPackageConfigJsonFile(myPubspecYamlFile);
VirtualFile packagesFile = DotPackagesFileUtil.getPackageConfigJsonFile(myProject, myPubspecYamlFile);
packagesMap = packagesFile != null ? DotPackagesFileUtil.getPackagesMapFromPackageConfigJsonFile(packagesFile) : null;
}
else {
Expand Down
27 changes: 24 additions & 3 deletions Dart/src/com/jetbrains/lang/dart/util/DotPackagesFileUtil.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.lang.dart.util;

import com.google.gson.JsonArray;
Expand All @@ -7,6 +7,8 @@
import com.google.gson.JsonParser;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
Expand Down Expand Up @@ -54,13 +56,32 @@ public final class DotPackagesFileUtil {
/**
* Given a file Dart pub root (either the yaml pubspec {@link VirtualFile} or the parent of a yaml pubspec), return the
* .dart_tool/package_config.json {@link VirtualFile}, if it exists.
* <p>
* After looking in the parent directory for a `.dart_tool/` directory containing a `package_config.json` file, the parent directory is
* also searched recursively.
*/
public static @Nullable VirtualFile getPackageConfigJsonFile(@NotNull VirtualFile pubspecYamlFile) {
public static @Nullable VirtualFile getPackageConfigJsonFile(@NotNull Project project, @NotNull VirtualFile pubspecYamlFile) {
VirtualFile packageConfigFile = null;
VirtualFile dir = pubspecYamlFile.getParent();
VirtualFile dartToolDir = dir.findChild(DART_TOOL_DIR);
if (dartToolDir != null && dartToolDir.isDirectory()) {
return dartToolDir.findChild(PACKAGE_CONFIG_JSON);
packageConfigFile = dartToolDir.findChild(PACKAGE_CONFIG_JSON);
}
if (packageConfigFile != null) {
return packageConfigFile;
}
else {
ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
VirtualFile parentDir = dir.getParent();
while (parentDir != null && fileIndex.isInContent(parentDir)) {
VirtualFile parentPubspecYamlFile = parentDir.findChild(PubspecYamlUtil.PUBSPEC_YAML);
if (parentPubspecYamlFile != null) {
return getPackageConfigJsonFile(project, parentPubspecYamlFile);
}
parentDir = parentDir.getParent();
}
}

return null;
}

Expand Down

0 comments on commit c1b3c4d

Please sign in to comment.