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;
}
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);
}
}
}
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);
}
}
}
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;
}
});
}
}
}
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);
}
}
}
}
Aggregations