Skip to content

Commit

Permalink
191 - #196 use ancestor finding
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Dec 20, 2019
1 parent 7882f83 commit a3cb65f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/com/reason/bs/BucklescriptImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public boolean isDependency(@Nullable VirtualFile file) {
return false;
}

VirtualFile bsConfigFile = Platform.findBsconfig(m_project, file);
VirtualFile bsConfigFile = Platform.findAncestorBsconfig(m_project, file);
return bsConfigFile == null || getOrRefreshBsConfig(bsConfigFile).accept(file.getPath());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void addCompletions(@NotNull PsiElement element, @NotNull Completi
PsiFinder psiFinder = PsiFinder.getInstance(project);

Collection<PsiModule> modules = psiFinder.findComponents(scope);
LOG.debug("Modules found", modules.size());
LOG.debug("Modules found", modules);
for (PsiModule module : modules) {
boolean isInner = module instanceof PsiInnerModule;
String moduleName = isInner ? module.getName() : ((FileBase) module).asModuleName();
Expand Down
39 changes: 28 additions & 11 deletions src/com/reason/ide/search/PsiFinder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.reason.ide.search;

import java.util.*;
import java.util.stream.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -14,15 +18,27 @@
import com.reason.bs.Bucklescript;
import com.reason.ide.files.FileBase;
import com.reason.ide.files.FileHelper;
import com.reason.ide.search.index.*;
import com.reason.ide.search.index.ExceptionFqnIndex;
import com.reason.ide.search.index.IndexKeys;
import com.reason.ide.search.index.LetFqnIndex;
import com.reason.ide.search.index.ModuleComponentIndex;
import com.reason.ide.search.index.ModuleFqnIndex;
import com.reason.ide.search.index.ParameterFqnIndex;
import com.reason.ide.search.index.ValFqnIndex;
import com.reason.ide.search.index.VariantFqnIndex;
import com.reason.ide.search.index.VariantIndex;
import com.reason.lang.core.ORFileType;
import com.reason.lang.core.psi.*;
import com.reason.lang.core.psi.PsiException;
import com.reason.lang.core.psi.PsiExternal;
import com.reason.lang.core.psi.PsiInnerModule;
import com.reason.lang.core.psi.PsiLet;
import com.reason.lang.core.psi.PsiModule;
import com.reason.lang.core.psi.PsiParameter;
import com.reason.lang.core.psi.PsiRecordField;
import com.reason.lang.core.psi.PsiType;
import com.reason.lang.core.psi.PsiVal;
import com.reason.lang.core.psi.PsiVariantDeclaration;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.stream.Collectors;

import static com.intellij.psi.search.GlobalSearchScope.allScope;
import static com.reason.lang.core.ORFileType.interfaceOrImplementation;
Expand Down Expand Up @@ -64,18 +80,17 @@ public Collection<PsiModule> findComponents(@NotNull GlobalSearchScope scope) {
return Collections.emptyList();
}

FileModuleIndexService fileModuleIndexService = FileModuleIndexService.getService();
ModuleComponentIndex index = ModuleComponentIndex.getInstance();
PsiManager psiManager = PsiManager.getInstance(project);
Bucklescript bucklescript = ServiceManager.getService(m_project, Bucklescript.class);

List<PsiModule> result = fileModuleIndexService.getComponents(project, scope).
List<PsiModule> result = FileModuleIndexService.getService().getComponents(project, scope).
stream().
filter(bucklescript::isDependency).
map(vFile -> (FileBase) psiManager.findFile(vFile)).
filter(Objects::nonNull).
collect(Collectors.toList());

ModuleComponentIndex index = ModuleComponentIndex.getInstance();
result.addAll(index.getAllKeys(m_project).
stream().
map(key -> index.getUnique(key, m_project, scope)).
Expand Down Expand Up @@ -219,7 +234,9 @@ public Collection<PsiExternal> findExternals(@NotNull String name, @NotNull ORFi
}

@NotNull
private <T extends PsiQualifiedNamedElement> Collection<T> findLowerSymbols(@NotNull String debugName, @NotNull String name, @NotNull ORFileType fileType, @NotNull StubIndexKey<String, T> indexKey, @NotNull Class<T> clazz, @NotNull GlobalSearchScope scope) {
private <T extends PsiQualifiedNamedElement> Collection<T> findLowerSymbols(@NotNull String debugName, @NotNull String name, @NotNull ORFileType fileType,
@NotNull StubIndexKey<String, T> indexKey, @NotNull Class<T> clazz,
@NotNull GlobalSearchScope scope) {
Map<String/*qn*/, T> implNames = new THashMap<>();
Map<String/*qn*/, T> intfNames = new THashMap<>();

Expand Down

0 comments on commit a3cb65f

Please sign in to comment.