use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class Variants method executeOnAliasedName.
/*
* Protected Instance Methods
*/
/**
* Decides whether {@code match} matches the criteria being searched for. All other {@link #execute} methods
* eventually end here.
*
* @param match
* @param aliasedName
* @param state
* @return {@code true} to keep processing; {@code false} to stop processing.
*/
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
if (lookupElementList == null) {
lookupElementList = new ArrayList<LookupElement>();
}
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
String unaliasedName = UnaliasedName.unaliasedName(match);
if (unaliasedName != null) {
Project project = match.getProject();
Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
if (unaliasedNestedNames.size() > 0) {
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
for (String unaliasedNestedName : unaliasedNestedNames) {
Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
if (unaliasedNestedNamedElementCollection.size() > 0) {
List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
List<String> unaliasedNamePartList = split(unaliasedName);
List<String> aliasedNamePartList = split(aliasedName);
List<String> aliasedNestedNamePartList = new ArrayList<String>();
aliasedNestedNamePartList.addAll(aliasedNamePartList);
for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
}
String aliasedNestedName = concat(aliasedNestedNamePartList);
for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
}
}
}
}
}
return true;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class Variants method addProjectNameElementsTo.
/*
* Private Instance Methods
*/
private void addProjectNameElementsTo(List<LookupElement> lookupElementList, PsiElement entrance) {
Project project = entrance.getProject();
/* getAllKeys is not the actual keys in the actual project. They need to be checked.
See https://intellij-support.jetbrains.com/hc/en-us/community/posts/207930789-StubIndex-persisting-between-test-runs-leading-to-incorrect-completions */
Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
GlobalSearchScope scope = GlobalSearchScope.allScope(project);
Collection<String> aliasNameCollection = filterIndexedNameCollection(indexedNameCollection);
String prefix = indexedNamePrefix(multipleAliases);
Collection<String> prefixedNameCollection = filterIndexedNameCollection(aliasNameCollection, prefix);
for (String prefixedName : prefixedNameCollection) {
Collection<NamedElement> prefixedNameNamedElementCollection = StubIndex.getElements(AllName.KEY, prefixedName, project, scope, NamedElement.class);
String lookupName = lookupName(prefixedName, prefix);
for (NamedElement prefixedNameNamedElement : prefixedNameNamedElementCollection) {
/* Generalizes over whether the prefixedNameNamedElement is a source element or a compiled element as
the navigation element is defined to be always be a source element */
PsiElement navigationElement = prefixedNameNamedElement.getNavigationElement();
lookupElementList.add(LookupElementBuilder.createWithSmartPointer(lookupName, navigationElement));
}
}
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class GotoSymbolContributor method getItemsByName.
/*
* Instance Methods
*/
/**
* Returns the list of navigation items matching the specified name.
*
* @param name the name selected from the list.
* @param pattern the original pattern entered in the dialog
* @param project the project in which the navigation is performed.
* @param includeNonProjectItems if true, the navigation items for non-project items (for example,
* library classes) should be included in the returned array.
* @return the array of navigation items.
*/
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
GlobalSearchScope scope = globalSearchScope(project, includeNonProjectItems);
Collection<NamedElement> result = StubIndex.getElements(AllName.KEY, name, project, scope, NamedElement.class);
List<NavigationItem> items = ContainerUtil.newArrayListWithCapacity(result.size());
EnclosingModularByCall enclosingModularByCall = new EnclosingModularByCall();
Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple = new HashMap<CallDefinition.Tuple, CallDefinition>();
for (final NamedElement element : result) {
// Use navigation element so that source element is used for compiled elements
PsiElement sourceElement = element.getNavigationElement();
if (sourceElement instanceof Call) {
getItemsByNameFromCall(name, items, enclosingModularByCall, callDefinitionByTuple, (Call) sourceElement);
}
}
return items.toArray(new NavigationItem[items.size()]);
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class ElixirPsiImplUtil method moduleWithDependentsScope.
private static GlobalSearchScope moduleWithDependentsScope(PsiElement element) {
VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
Project project = element.getProject();
com.intellij.openapi.module.Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
GlobalSearchScope globalSearchScope;
// module can be null for scratch files
if (module != null) {
globalSearchScope = GlobalSearchScope.moduleWithDependentsScope(module);
} else {
globalSearchScope = GlobalSearchScope.allScope(project);
}
return globalSearchScope;
}
use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.
the class FileReferenceFilter method resolveAbsolutePath.
@Nullable
private VirtualFile resolveAbsolutePath(@NotNull String path) {
VirtualFile asIsFile = pathToVirtualFile(path);
if (asIsFile != null) {
return asIsFile;
}
String projectBasedPath = path.startsWith(myProject.getBasePath()) ? path : new File(myProject.getBasePath(), path).getAbsolutePath();
VirtualFile projectBasedFile = pathToVirtualFile(projectBasedPath);
if (projectBasedFile != null) {
return projectBasedFile;
}
Matcher filenameMatcher = PATTERN_FILENAME.matcher(path);
if (filenameMatcher.find()) {
String filename = filenameMatcher.group(1);
GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
PsiFile[] projectFiles = FilenameIndex.getFilesByName(myProject, filename, projectScope);
if (projectFiles.length > 0) {
return projectFiles[0].getVirtualFile();
}
GlobalSearchScope libraryScope = ProjectScope.getLibrariesScope(myProject);
PsiFile[] libraryFiles = FilenameIndex.getFilesByName(myProject, filename, libraryScope);
if (libraryFiles.length > 0) {
return libraryFiles[0].getVirtualFile();
}
}
return null;
}
Aggregations