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