Search in sources :

Example 1 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings in project Perl5-IDEA by Camelcade.

the class MasonNamespaceDefinitionImpl method getImplicitVariables.

@NotNull
@Override
public List<PerlVariableDeclarationElement> getImplicitVariables() {
    MasonSettings settings = MasonSettings.getInstance(getProject());
    if (myImplicitVariables == null || mySettingsChangeCounter != settings.getChangeCounter()) {
        myImplicitVariables = buildImplicitVariables(settings);
        mySettingsChangeCounter = settings.getChangeCounter();
    }
    return myImplicitVariables;
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings in project Perl5-IDEA by Camelcade.

the class Mason2Util method collectComponentNamespacesByPaths.

@NotNull
public static List<PerlNamespaceDefinitionElement> collectComponentNamespacesByPaths(@NotNull Project project, @NotNull List<String> componentPaths, @NotNull VirtualFile anchorDir) {
    List<PerlNamespaceDefinitionElement> result = new ArrayList<>();
    MasonSettings masonSettings = MasonSettings.getInstance(project);
    for (String componentPath : componentPaths) {
        VirtualFile componentFile = null;
        if (componentPath.startsWith(// abs path relative to mason roots, see the Mason::Interp::_determine_parent_compc
        "" + VfsUtil.VFS_SEPARATOR_CHAR)) {
            for (VirtualFile componentRoot : masonSettings.getComponentsRoots()) {
                componentFile = componentRoot.findFileByRelativePath(componentPath.substring(1));
                if (componentFile != null) {
                    break;
                }
            }
        } else // relative path
        {
            componentFile = anchorDir.findFileByRelativePath(componentPath);
        }
        if (componentFile != null) {
            String absolutePath = VfsUtil.getRelativePath(componentFile, project.getBaseDir());
            if (absolutePath != null) {
                result.addAll(Mason2Util.getMasonNamespacesByAbsolutePath(project, absolutePath));
            }
        }
    }
    return result;
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings in project Perl5-IDEA by Camelcade.

the class MasonNamespaceDefinitionImpl method getChildNamespaceDefinitions.

@NotNull
@Override
public List<PerlNamespaceDefinitionElement> getChildNamespaceDefinitions() {
    MasonSettings masonSettings = MasonSettings.getInstance(getProject());
    final List<PerlNamespaceDefinitionElement> childNamespaces = new ArrayList<>();
    // collect psi children
    final Project project = getProject();
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
    final String componentPath = getComponentPath();
    if (componentPath != null) {
        final List<String> relativePaths = new ArrayList<>();
        final List<String> exactPaths = new ArrayList<>();
        StubIndex.getInstance().processAllKeys(MasonParentNamespacesStubIndex.KEY, project, parentPath -> {
            if (// absolute path, should be equal
            parentPath.charAt(0) == VfsUtil.VFS_SEPARATOR_CHAR) {
                if (componentPath.equals(parentPath.substring(1))) {
                    exactPaths.add(parentPath);
                }
            } else if (// relative path
            componentPath.endsWith(parentPath)) {
                relativePaths.add(parentPath);
            }
            return true;
        });
        for (String parentPath : exactPaths) {
            childNamespaces.addAll(StubIndex.getElements(MasonParentNamespacesStubIndex.KEY, parentPath, project, projectScope, MasonNamespaceDefinition.class));
        }
        for (String parentPath : relativePaths) {
            for (MasonNamespaceDefinition masonNamespaceDefinition : StubIndex.getElements(MasonParentNamespacesStubIndex.KEY, parentPath, project, projectScope, MasonNamespaceDefinition.class)) {
                if (masonNamespaceDefinition.getParentNamespaceDefinitions().contains(MasonNamespaceDefinitionImpl.this)) {
                    childNamespaces.add(masonNamespaceDefinition);
                }
            }
        }
    }
    // collect autobased children
    if (masonSettings.autobaseNames.contains(getContainingFile().getName())) {
        VirtualFile containingFile = MasonCoreUtil.getContainingVirtualFile(getContainingFile());
        if (containingFile != null) {
            final String basePath = VfsUtil.getRelativePath(containingFile.getParent(), getProject().getBaseDir());
            if (basePath != null) {
                final List<String> componentPaths = new ArrayList<>();
                StubIndex.getInstance().processAllKeys(MasonNamespaceDefitnitionsStubIndex.KEY, getProject(), componentPath1 -> {
                    if (componentPath1.startsWith(basePath)) {
                        componentPaths.add(componentPath1);
                    }
                    return true;
                });
                for (String compoPath : componentPaths) {
                    for (MasonNamespaceDefinition namespaceDefinition : StubIndex.getElements(MasonNamespaceDefitnitionsStubIndex.KEY, compoPath, project, projectScope, MasonNamespaceDefinition.class)) {
                        if (namespaceDefinition.getParentNamespaceDefinitions().contains(MasonNamespaceDefinitionImpl.this) && !childNamespaces.contains(namespaceDefinition)) {
                            childNamespaces.add(namespaceDefinition);
                        }
                    }
                }
            }
        }
    }
    return childNamespaces;
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) MasonNamespaceDefinition(com.perl5.lang.mason2.psi.MasonNamespaceDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings in project Perl5-IDEA by Camelcade.

the class MasonVirtualFileListener method processFileChange.

private void processFileChange(VirtualFile changedFile) {
    MasonSettings masonSettings = MasonSettings.getInstance(getProject());
    List<VirtualFile> componentsRoots = masonSettings.getComponentsRoots();
    if (componentsRoots.isEmpty()) {
        return;
    }
    Set<VirtualFile> rootsSet = new THashSet<>(componentsRoots);
    if (changedFile.isDirectory()) {
        if (changedFile.getUserData(FORCE_REINDEX) != null || // moved to component root
        VfsUtil.isUnder(changedFile, rootsSet) || containsAtLeastOneFile(changedFile, componentsRoots)) {
            Mason2Util.reindexProjectFile(getProject(), changedFile);
        }
    } else if (// Mason file has been moved
    changedFile.getFileType() instanceof MasonPurePerlComponentFileType) {
        if (changedFile.getUserData(FORCE_REINDEX) != null || VfsUtil.isUnder(changedFile, rootsSet)) {
            FileBasedIndex.getInstance().requestReindex(changedFile);
        }
    }
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) THashSet(gnu.trove.THashSet)

Example 5 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings in project Perl5-IDEA by Camelcade.

the class MasonVirtualFileListener method beforeFileMovement.

/**
 * Fired before the movement of a file is processed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void beforeFileMovement(@NotNull VirtualFileMoveEvent event) {
    MasonSettings masonSettings = MasonSettings.getInstance(getProject());
    List<VirtualFile> componentsRoots = masonSettings.getComponentsRoots();
    if (componentsRoots.isEmpty()) {
        return;
    }
    VirtualFile movedFile = event.getFile();
    Set<VirtualFile> rootsSet = new THashSet<>(componentsRoots);
    if (movedFile.isDirectory()) {
        if (// moved from component root
        VfsUtil.isUnder(movedFile, rootsSet) || // contains component root
        containsAtLeastOneFile(movedFile, componentsRoots)) {
            movedFile.putUserData(FORCE_REINDEX, true);
        }
    } else if (// Mason file has been moved
    movedFile.getFileType() instanceof MasonPurePerlComponentFileType) {
        if (VfsUtil.isUnder(movedFile, rootsSet)) {
            movedFile.putUserData(FORCE_REINDEX, true);
        }
    }
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) THashSet(gnu.trove.THashSet)

Aggregations

MasonSettings (com.perl5.lang.mason2.idea.configuration.MasonSettings)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 MasonPurePerlComponentFileType (com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType)3 NotNull (org.jetbrains.annotations.NotNull)3 Project (com.intellij.openapi.project.Project)2 PerlNamespaceDefinitionElement (com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement)2 THashSet (gnu.trove.THashSet)2 ArrayList (java.util.ArrayList)2 FileType (com.intellij.openapi.fileTypes.FileType)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 MasonNamespaceDefinition (com.perl5.lang.mason2.psi.MasonNamespaceDefinition)1 MasonFileImpl (com.perl5.lang.mason2.psi.impl.MasonFileImpl)1 PerlString (com.perl5.lang.perl.psi.PerlString)1