Search in sources :

Example 1 with MasonFileImpl

use of com.perl5.lang.mason2.psi.impl.MasonFileImpl 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 MasonFileImpl

use of com.perl5.lang.mason2.psi.impl.MasonFileImpl 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

PsiFile (com.intellij.psi.PsiFile)2 MasonPurePerlComponentFileType (com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType)2 MasonFileImpl (com.perl5.lang.mason2.psi.impl.MasonFileImpl)2 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)1 MasonSettings (com.perl5.lang.mason2.idea.configuration.MasonSettings)1 PerlString (com.perl5.lang.perl.psi.PerlString)1 Nullable (org.jetbrains.annotations.Nullable)1