Search in sources :

Example 6 with DartUrlResolver

use of com.jetbrains.lang.dart.util.DartUrlResolver in project intellij-plugins by JetBrains.

the class DartTestRunConfigurationProducer method isFileInTestDirAndTestPackageExists.

public static boolean isFileInTestDirAndTestPackageExists(@NotNull final Project project, @NotNull final VirtualFile file) {
    final DartUrlResolver urlResolver = DartUrlResolver.getInstance(project, file);
    final VirtualFile dartTestLib = urlResolver.findFileByDartUrl("package:test/test.dart");
    if (dartTestLib == null)
        return false;
    final VirtualFile pubspec = urlResolver.getPubspecYamlFile();
    final VirtualFile rootDir = pubspec == null ? null : pubspec.getParent();
    final VirtualFile testDir = rootDir == null ? null : rootDir.findChild("test");
    return testDir != null && testDir.isDirectory() && VfsUtilCore.isAncestor(testDir, file, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver)

Example 7 with DartUrlResolver

use of com.jetbrains.lang.dart.util.DartUrlResolver in project intellij-plugins by JetBrains.

the class DartPackageAwareFileReference method bindToElement.

@Override
public PsiElement bindToElement(@NotNull final PsiElement element, final boolean absolute) throws IncorrectOperationException {
    final String path = getFileReferenceSet().getPathString();
    if (path.startsWith(PACKAGES_FOLDER_NAME + "/") || path.contains("/" + PACKAGES_FOLDER_NAME + "/")) {
        final VirtualFile contextFile = DartResolveUtil.getRealVirtualFile(getElement().getContainingFile());
        final VirtualFile targetFile = DartResolveUtil.getRealVirtualFile(element.getContainingFile());
        if (contextFile != null && targetFile != null) {
            final DartUrlResolver urlResolver = DartUrlResolver.getInstance(element.getProject(), contextFile);
            final String newUrl = urlResolver.getDartUrlForFile(targetFile);
            if (newUrl.startsWith(PACKAGE_PREFIX)) {
                final int index = path.startsWith(PACKAGES_FOLDER_NAME + "/") ? 0 : (path.indexOf("/" + PACKAGES_FOLDER_NAME + "/") + 1);
                final String newName = path.substring(0, index) + PACKAGES_FOLDER_NAME + "/" + newUrl.substring(PACKAGE_PREFIX.length());
                return rename(newName);
            }
        }
    }
    return super.bindToElement(element, absolute);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver)

Example 8 with DartUrlResolver

use of com.jetbrains.lang.dart.util.DartUrlResolver in project intellij-plugins by JetBrains.

the class DartTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parentNode, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (parentNode instanceof ExternalLibrariesNode) {
        return ContainerUtil.map(children, node -> {
            if (node instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(node.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(node.getName()))) {
                final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(node.getName());
                return new NamedLibraryElementNode(node.getProject(), ((NamedLibraryElementNode) node).getValue(), settings) {

                    @Override
                    public boolean canNavigate() {
                        return isSdkRoot;
                    }

                    @Override
                    public void navigate(boolean requestFocus) {
                        final Project project = getProject();
                        if (project != null) {
                            DartConfigurable.openDartSettings(project);
                        }
                    }
                };
            }
            return node;
        });
    }
    if (parentNode instanceof NamedLibraryElementNode && (DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(parentNode.getName()) || DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName()))) {
        final boolean isSdkRoot = DartSdk.DART_SDK_LIB_NAME.equals(parentNode.getName());
        return ContainerUtil.map(children, node -> {
            final VirtualFile dir = node instanceof PsiDirectoryNode ? ((PsiDirectoryNode) node).getVirtualFile() : null;
            if (dir != null && dir.isInLocalFileSystem() && dir.isDirectory() && (isSdkRoot || "lib".equals(dir.getName()))) {
                return new DartSdkOrLibraryRootNode(node.getProject(), ((PsiDirectoryNode) node).getValue(), settings);
            }
            return node;
        });
    }
    // root/packages/ThisProject and root/packages/PathPackage folders are excluded in dart projects (see DartProjectComponent.excludeBuildAndPackagesFolders),
    // this provider adds location string tho these nodes in Project View like "ThisProject (ThisProject/lib)"
    final Project project = parentNode.getProject();
    final VirtualFile packagesDir = parentNode instanceof PsiDirectoryNode && project != null ? ((PsiDirectoryNode) parentNode).getVirtualFile() : null;
    final VirtualFile parentFolder = packagesDir != null && packagesDir.isDirectory() && PACKAGES_FOLDER_NAME.equals(packagesDir.getName()) ? packagesDir.getParent() : null;
    final VirtualFile pubspecYamlFile = parentFolder != null ? parentFolder.findChild(PUBSPEC_YAML) : null;
    if (pubspecYamlFile != null && !pubspecYamlFile.isDirectory()) {
        final ArrayList<AbstractTreeNode> modifiedChildren = new ArrayList<>(children);
        final DartUrlResolver resolver = DartUrlResolver.getInstance(project, pubspecYamlFile);
        resolver.processLivePackages((packageName, packageDir) -> {
            final VirtualFile folder = packagesDir.findChild(packageName);
            if (folder != null) {
                final AbstractTreeNode node = getFolderNode(children, folder);
                if (node == null) {
                    modifiedChildren.add(new SymlinkToLivePackageNode(project, packageName, packageDir));
                } else {
                    node.getPresentation().setLocationString(getPackageLocationString(packageDir));
                }
            }
        });
        return modifiedChildren;
    }
    return children;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DartUrlResolver

use of com.jetbrains.lang.dart.util.DartUrlResolver in project intellij-plugins by JetBrains.

the class DartDocumentationProvider method getLibRelatedUrlPart.

@Nullable
private static String getLibRelatedUrlPart(@NotNull final PsiElement element) {
    for (VirtualFile libFile : DartResolveUtil.findLibrary(element.getContainingFile())) {
        final DartUrlResolver urlResolver = DartUrlResolver.getInstance(element.getProject(), libFile);
        final String dartUrl = urlResolver.getDartUrlForFile(libFile);
        // "dart:html" -> "dart-html"
        if (dartUrl.startsWith(DartUrlResolver.DART_PREFIX)) {
            return "dart-" + dartUrl.substring(DartUrlResolver.DART_PREFIX.length());
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)9 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)2 ExecutionResult (com.intellij.execution.ExecutionResult)1 RunProfile (com.intellij.execution.configurations.RunProfile)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 ExternalLibrariesNode (com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode)1 NamedLibraryElementNode (com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 Project (com.intellij.openapi.project.Project)1 SmartList (com.intellij.util.SmartList)1 Url (com.intellij.util.Url)1 XDebugProcess (com.intellij.xdebugger.XDebugProcess)1 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)1 DartRunConfigurationBase (com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase)1 DartRemoteDebugConfiguration (com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration)1