Search in sources :

Example 1 with MasonPurePerlComponentFileType

use of com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType in project Perl5-IDEA by Camelcade.

the class MasonPathsNotification method createNotificationPanel.

@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() instanceof MasonPurePerlComponentFileType) {
        String message = null;
        if (MasonSettings.getInstance(myProject).getComponentsRoots().isEmpty()) {
            message = "Mason2 components roots are not configured";
        } else {
            PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
            if (psiFile instanceof MasonFileImpl && ((MasonFileImpl) psiFile).getComponentRoot() == null) {
                message = "Component is not under one of configured roots";
            }
        }
        if (message != null) {
            EditorNotificationPanel panel = new EditorNotificationPanel();
            panel.setText(message);
            panel.createActionLabel("Configure", () -> Perl5SettingsConfigurable.open(myProject));
            return panel;
        }
    }
    return null;
}
Also used : MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) MasonFileImpl(com.perl5.lang.mason2.psi.impl.MasonFileImpl) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with MasonPurePerlComponentFileType

use of com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType 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 3 with MasonPurePerlComponentFileType

use of com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType 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)

Example 4 with MasonPurePerlComponentFileType

use of com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType in project Perl5-IDEA by Camelcade.

the class MasonComponentsCompletionProvider method addCompletions.

@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    PsiElement parent = position.getParent();
    if (parent instanceof PerlString) {
        Project project = position.getProject();
        MasonSettings masonSettings = MasonSettings.getInstance(project);
        String fullPrefix = ElementManipulators.getValueText(parent).replace(CompletionInitializationContext.DUMMY_IDENTIFIER, "").replace(CompletionInitializationContext.DUMMY_IDENTIFIER_TRIMMED, "");
        result = result.withPrefixMatcher(new PlainPrefixMatcher(fullPrefix));
        final CompletionResultSet finalResultSet = result;
        PsiFile psiFile = position.getContainingFile();
        if (psiFile instanceof MasonFileImpl) {
            final VirtualFile containingFile = MasonCoreUtil.getContainingVirtualFile(psiFile);
            VirtualFile containingDir;
            if (containingFile != null && (containingDir = containingFile.getParent()) != null) {
                VfsUtil.processFilesRecursively(containingDir, new MasonRootsProcessor(containingDir) {

                    @Override
                    public boolean process(VirtualFile virtualFile) {
                        FileType fileType = virtualFile.getFileType();
                        if (fileType instanceof MasonPurePerlComponentFileType && !containingFile.equals(virtualFile)) {
                            String relativePath = VfsUtil.getRelativePath(virtualFile, getRoot());
                            if (StringUtil.isNotEmpty(relativePath)) {
                                finalResultSet.addElement(LookupElementBuilder.create(relativePath).withIcon(fileType.getIcon()));
                            }
                        }
                        return true;
                    }
                });
            }
        }
        for (VirtualFile componentRoot : masonSettings.getComponentsRoots()) {
            VfsUtil.processFilesRecursively(componentRoot, new MasonRootsProcessor(componentRoot) {

                @Override
                public boolean process(VirtualFile virtualFile) {
                    FileType fileType = virtualFile.getFileType();
                    if (fileType instanceof MasonPurePerlComponentFileType) {
                        String relativePath = VfsUtil.getRelativePath(virtualFile, getRoot());
                        if (StringUtil.isNotEmpty(relativePath)) {
                            finalResultSet.addElement(LookupElementBuilder.create("/" + relativePath).withIcon(fileType.getIcon()));
                        }
                    }
                    return true;
                }
            });
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MasonFileImpl(com.perl5.lang.mason2.psi.impl.MasonFileImpl) PerlString(com.perl5.lang.perl.psi.PerlString) MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings) Project(com.intellij.openapi.project.Project) PerlString(com.perl5.lang.perl.psi.PerlString) FileType(com.intellij.openapi.fileTypes.FileType) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 5 with MasonPurePerlComponentFileType

use of com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType in project Perl5-IDEA by Camelcade.

the class Mason2Util method reindexProjectRoots.

public static void reindexProjectRoots(Project project, List<String> rootsToReindex) {
    if (rootsToReindex.isEmpty()) {
        return;
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    VirtualFile projectRoot = project.getBaseDir();
    if (projectRoot != null) {
        final FileBasedIndex index = FileBasedIndex.getInstance();
        for (String root : rootsToReindex) {
            VirtualFile componentRoot = VfsUtil.findRelativeFile(root, projectRoot);
            if (componentRoot != null) {
                for (VirtualFile file : VfsUtil.collectChildrenRecursively(componentRoot)) {
                    if (file.getFileType() instanceof MasonPurePerlComponentFileType) {
                        index.requestReindex(file);
                    }
                }
            }
        }
        if (index instanceof FileBasedIndexImpl) {
            DumbModeTask changedFilesIndexingTask = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(project);
            if (changedFilesIndexingTask != null) {
                DumbServiceImpl.getInstance(project).queueTask(changedFilesIndexingTask);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) DumbModeTask(com.intellij.openapi.project.DumbModeTask) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Aggregations

MasonPurePerlComponentFileType (com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType)5 MasonSettings (com.perl5.lang.mason2.idea.configuration.MasonSettings)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 MasonFileImpl (com.perl5.lang.mason2.psi.impl.MasonFileImpl)2 THashSet (gnu.trove.THashSet)2 FileType (com.intellij.openapi.fileTypes.FileType)1 DumbModeTask (com.intellij.openapi.project.DumbModeTask)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 FileBasedIndexImpl (com.intellij.util.indexing.FileBasedIndexImpl)1 PerlString (com.perl5.lang.perl.psi.PerlString)1 Nullable (org.jetbrains.annotations.Nullable)1