Search in sources :

Example 6 with MasonSettings

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

the class MasonVirtualFileListener method beforePropertyChange.

/**
 * Fired before the change of a name or writable status of a file is processed.
 *
 * @param event the event object containing information about the change.
 */
@Override
public void beforePropertyChange(@NotNull VirtualFilePropertyEvent event) {
    if (!event.getPropertyName().equals(VirtualFile.PROP_NAME)) {
        return;
    }
    MasonSettings masonSettings = MasonSettings.getInstance(getProject());
    List<VirtualFile> componentsRoots = masonSettings.getComponentsRoots();
    if (componentsRoots.isEmpty()) {
        return;
    }
    VirtualFile renamedFile = event.getFile();
    if (renamedFile.isDirectory()) {
        if (// contains component root
        containsAtLeastOneFile(renamedFile, componentsRoots)) {
            renamedFile.putUserData(FORCE_REINDEX, true);
        }
    }
}
Also used : MasonSettings(com.perl5.lang.mason2.idea.configuration.MasonSettings)

Example 7 with MasonSettings

use of com.perl5.lang.mason2.idea.configuration.MasonSettings 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)

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