Skip to content

Commit

Permalink
index class methods, can navigate (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Sep 20, 2022
1 parent b0dfc61 commit f60a51e
Show file tree
Hide file tree
Showing 35 changed files with 294 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Unreleased

- :bug: [#358](https://github.com/giraud/reasonml-idea-plugin/issues/358) Incorrect resolution with module in pattern
- :bug: [#323](https://github.com/giraud/reasonml-idea-plugin/issues/323) Method declarations in .ml files should link to their implementations

NOTE: minimal version supported is 2021.3

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ intellij {
changeNotes = """
<ul>
<li>#358 - Incorrect resolution with module in pattern</li>
<li>#323 - Method declarations in .ml files should link to their implementations</li>
</ul>
<p><a href="https://github.com/giraud/reasonml-idea-plugin/blob/master/CHANGELOG.md">Full change log...</a></p>
<p/>
Expand Down
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
implementationClass="com.reason.ide.highlight.RmlSyntaxHighlighterFactory"/>
<!-- Rescript -->
<stubElementTypeHolder externalIdPrefix="Rescript."
class="com.reason.lang.core.stub.RescriptStubBasedElementTypes"/>
class="com.reason.lang.core.stub.ResStubBasedElementTypes"/>
<lang.ast.factory language="Rescript" implementationClass="com.reason.lang.rescript.ResASTFactory"/>
<lang.parserDefinition language="Rescript" implementationClass="com.reason.lang.rescript.ResSafeParserDefinition"/>
<lang.syntaxHighlighterFactory language="Rescript"
Expand Down Expand Up @@ -232,7 +232,8 @@
<stubIndex implementation="com.reason.ide.search.index.ModuleIndex"/>
<stubIndex implementation="com.reason.ide.search.index.ModuleAliasedIndex"/>
<stubIndex implementation="com.reason.ide.search.index.ModuleAliasesIndex"/>
<stubIndex implementation="com.reason.ide.search.index.KlassFqnIndex"/>
<stubIndex implementation="com.reason.ide.search.index.ClassFqnIndex"/>
<stubIndex implementation="com.reason.ide.search.index.ClassMethodFqnIndex"/>
<stubIndex implementation="com.reason.ide.search.index.LetIndex"/>
<stubIndex implementation="com.reason.ide.search.index.LetFqnIndex"/>
<stubIndex implementation="com.reason.ide.search.index.ValIndex"/>
Expand Down
6 changes: 6 additions & 0 deletions src/com/reason/hints/InsightManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public void queryTypes(@NotNull VirtualFile sourceFile, @NotNull Path cmtPath, @
String ocamlVersion = Rincewind.extractOcamlVersion(fullVersion);
String rincewindVersion = Rincewind.getLatestVersion(ocamlVersion);

// ocaml version default - opam -> use ocaml -version ??
// opam switch different than default
// opam settings set correctly (not default)



if (ocamlVersion != null && !rincewindVersion.equals(excludedVersion)) {
return "rincewind_" + getOsPrefix() + ocamlVersion + "-" + rincewindVersion + ".exe";
}
Expand Down
1 change: 1 addition & 0 deletions src/com/reason/hints/RincewindProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void types(@NotNull VirtualFile sourceFile, @NotNull String rincewindBina
StringBuilder msgBuffer = new StringBuilder();
if (errReader.ready()) {
errReader.lines().forEach(line -> msgBuffer.append(line).append(System.lineSeparator()));
LOG.warn("Error when processing types");
LOG.warn(msgBuffer.toString());
} else {
final InferredTypesImplementation types = new InferredTypesImplementation();
Expand Down
47 changes: 27 additions & 20 deletions src/com/reason/ide/go/ORLineMarkerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,33 @@ protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Co
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "method", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
} else {
if (parent instanceof PsiType) {
String valQName = ((PsiTypeImpl) parent).getQualifiedName();
Collection<PsiType> elements = TypeFqnIndex.getElements(valQName.hashCode(), project, scope);
elements.stream()
.filter(isInterface ? PSI_IMPL_PREDICATE : PSI_INTF_PREDICATE)
.findFirst()
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "type", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
} else if (parent instanceof PsiKlass) {
String qName = ((PsiKlassImpl) parent).getQualifiedName();
Collection<PsiKlass> elements = KlassFqnIndex.getElements(qName.hashCode(), project, scope);
elements.stream()
.filter(isInterface ? PSI_IMPL_PREDICATE : PSI_INTF_PREDICATE)
.findFirst()
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "class", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
}
} else if (parent instanceof PsiType) {
String valQName = ((PsiTypeImpl) parent).getQualifiedName();
Collection<PsiType> elements = TypeFqnIndex.getElements(valQName.hashCode(), project, scope);
elements.stream()
.filter(isInterface ? PSI_IMPL_PREDICATE : PSI_INTF_PREDICATE)
.findFirst()
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "type", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
} else if (parent instanceof RsiClass) {
String qName = ((RsiClassImpl) parent).getQualifiedName();
Collection<RsiClass> elements = ClassFqnIndex.getElements(qName.hashCode(), project, scope);
elements.stream()
.filter(isInterface ? PSI_IMPL_PREDICATE : PSI_INTF_PREDICATE)
.findFirst()
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "class", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
} else if (parent instanceof RsiClassMethodImpl) {
String qName = ((RsiClassMethodImpl) parent).getQualifiedName();
Collection<RsiClassMethod> elements = ClassMethodFqnIndex.getElements(qName.hashCode(), project, scope);
elements.stream()
.filter(isInterface ? PSI_IMPL_PREDICATE : PSI_INTF_PREDICATE)
.findFirst()
.ifPresent(psiTarget ->
result.add(createGutterIcon(element, isInterface, "method", (FileBase) psiTarget.getContainingFile(), psiTarget))
);
}
} else if (element instanceof PsiUpperSymbol) {
if (parent instanceof PsiInnerModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static void addFileExpressions(@NotNull FileBase element, @NotNull Colle
modules.remove(modules.size() - 1); // remove fake module
expressions.addAll(modules);
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(element, PsiFunctor.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(element, PsiKlass.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(element, RsiClass.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(element, PsiExternal.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(element, PsiException.class));
}
Expand Down Expand Up @@ -177,7 +177,7 @@ private static void addChildren(@Nullable PsiElement body, @NotNull Collection<P
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiVal.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiModule.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiFunctor.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiKlass.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, RsiClass.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiExternal.class));
expressions.addAll(PsiTreeUtil.getStubChildrenOfTypeAsList(body, PsiException.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

import java.util.*;

public class KlassFqnIndex extends IntStubIndexExtension<PsiKlass> {
public class ClassFqnIndex extends IntStubIndexExtension<RsiClass> {
@Override
public int getVersion() {
return super.getVersion() + ORStubVersions.KLASS;
return super.getVersion() + ORStubVersions.CLASS;
}

@Override
public @NotNull StubIndexKey<Integer, PsiKlass> getKey() {
public @NotNull StubIndexKey<Integer, RsiClass> getKey() {
return IndexKeys.CLASSES_FQN;
}

public static @NotNull Collection<PsiKlass> getElements(int key, @NotNull Project project, @Nullable GlobalSearchScope scope) {
return StubIndex.getElements(IndexKeys.CLASSES_FQN, key, project, scope, PsiKlass.class);
public static @NotNull Collection<RsiClass> getElements(int key, @NotNull Project project, @Nullable GlobalSearchScope scope) {
return StubIndex.getElements(IndexKeys.CLASSES_FQN, key, project, scope, RsiClass.class);
}
}
26 changes: 26 additions & 0 deletions src/com/reason/ide/search/index/ClassMethodFqnIndex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.reason.ide.search.index;

import com.intellij.openapi.project.*;
import com.intellij.psi.search.*;
import com.intellij.psi.stubs.*;
import com.reason.lang.core.psi.*;
import com.reason.lang.core.stub.type.*;
import org.jetbrains.annotations.*;

import java.util.*;

public class ClassMethodFqnIndex extends IntStubIndexExtension<RsiClassMethod> {
@Override
public int getVersion() {
return super.getVersion() + ORStubVersions.CLASS_METHOD;
}

@Override
public @NotNull StubIndexKey<Integer, RsiClassMethod> getKey() {
return IndexKeys.CLASS_METHODS_FQN;
}

public static @NotNull Collection<RsiClassMethod> getElements(int key, @NotNull Project project, @Nullable GlobalSearchScope scope) {
return StubIndex.getElements(IndexKeys.CLASS_METHODS_FQN, key, project, scope, RsiClassMethod.class);
}
}
3 changes: 2 additions & 1 deletion src/com/reason/ide/search/index/IndexKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ interface ProcessElement<T> {
public static final StubIndexKey<String, PsiModule> MODULES_ALIASED = StubIndexKey.createIndexKey("reason.module.aliased");
public static final StubIndexKey<String, PsiModule> MODULES_ALIASES = StubIndexKey.createIndexKey("reason.module.aliases");
public static final StubIndexKey<Integer, PsiModule> MODULES_FQN = StubIndexKey.createIndexKey("reason.module.fqn");
public static final StubIndexKey<Integer, PsiKlass> CLASSES_FQN = StubIndexKey.createIndexKey("reason.class.fqn");
public static final StubIndexKey<Integer, RsiClass> CLASSES_FQN = StubIndexKey.createIndexKey("reason.class.fqn");
public static final StubIndexKey<Integer, RsiClassMethod> CLASS_METHODS_FQN = StubIndexKey.createIndexKey("reason.method.fqn");
public static final StubIndexKey<String, PsiVariantDeclaration> VARIANTS = StubIndexKey.createIndexKey("reason.variant");
public static final StubIndexKey<Integer, PsiVariantDeclaration> VARIANTS_FQN = StubIndexKey.createIndexKey("reason.variant.fqn");
public static final StubIndexKey<String, PsiLet> LETS = StubIndexKey.createIndexKey("reason.let");
Expand Down
1 change: 0 additions & 1 deletion src/com/reason/ide/settings/ORSettingsConfigurable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.reason.ide.settings;

import com.intellij.execution.wsl.*;
import com.intellij.openapi.application.*;
import com.intellij.openapi.fileChooser.*;
import com.intellij.openapi.module.Module;
Expand Down
6 changes: 3 additions & 3 deletions src/com/reason/ide/structure/StructureViewElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public Icon getIcon(boolean unused) {
treeElements = buildFunctorStructure((PsiFunctor) m_element);
} else if (m_element instanceof PsiType) {
treeElements = buildTypeStructure((PsiType) m_element);
} else if (m_element instanceof PsiKlass) {
treeElements = buildClassStructure((PsiKlass) m_element);
} else if (m_element instanceof RsiClass) {
treeElements = buildClassStructure((RsiClass) m_element);
} else if (m_element instanceof PsiStanza) {
treeElements = buildStanzaStructure((PsiStanza) m_element);
} else if (m_element instanceof PsiLet) {
Expand Down Expand Up @@ -212,7 +212,7 @@ public Icon getIcon(boolean unused) {
return treeElements;
}

private @NotNull List<TreeElement> buildClassStructure(@NotNull PsiKlass classElement) {
private @NotNull List<TreeElement> buildClassStructure(@NotNull RsiClass classElement) {
List<TreeElement> treeElements = new ArrayList<>();

PsiElement rootElement = classElement.getClassBody();
Expand Down
4 changes: 2 additions & 2 deletions src/com/reason/lang/PsiFileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public static List<PsiFunctor> getFunctorExpressions(@Nullable PsiFile file) {
}

@NotNull
public static List<PsiKlass> getClassExpressions(@Nullable PsiFile file) {
return PsiTreeUtil.getStubChildrenOfTypeAsList(file, PsiKlass.class);
public static List<RsiClass> getClassExpressions(@Nullable PsiFile file) {
return PsiTreeUtil.getStubChildrenOfTypeAsList(file, RsiClass.class);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
import java.util.*;

// Using a K to avoid confusion with PsiClass from IntelliJ
public interface PsiKlass extends PsiQualifiedPathElement, NavigatablePsiElement, PsiStructuredElement, StubBasedPsiElement<PsiKlassStub> {
public interface RsiClass extends PsiQualifiedPathElement, NavigatablePsiElement, PsiStructuredElement, StubBasedPsiElement<RsiClassStub> {
@Nullable
PsiElement getClassBody();

@NotNull
Collection<PsiClassField> getFields();
Collection<RsiClassField> getFields();

@NotNull
Collection<PsiClassMethod> getMethods();
Collection<RsiClassMethod> getMethods();

@NotNull
Collection<PsiParameters> getParameters();

@Nullable
PsiClassConstructor getConstructor();
RsiClassConstructor getConstructor();
}
10 changes: 10 additions & 0 deletions src/com/reason/lang/core/psi/RsiClassMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.reason.lang.core.psi;

import com.intellij.psi.*;
import com.reason.lang.core.stub.*;
import org.jetbrains.annotations.*;

// Using a K to avoid confusion with PsiClass from IntelliJ
public interface RsiClassMethod extends PsiQualifiedPathElement, NavigatablePsiElement, PsiNameIdentifierOwner, PsiStructuredElement, StubBasedPsiElement<RsiClassMethodStub> {
@Nullable PsiSignature getSignature();
}
7 changes: 2 additions & 5 deletions src/com/reason/lang/core/psi/impl/ORASTFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,10 @@ public ORASTFactory(T types) {
return new PsiOption(myTypes, type);
}
if (type == myTypes.C_CLASS_CONSTR) {
return new PsiClassConstructor(myTypes, type);
return new RsiClassConstructor(myTypes, type);
}
if (type == myTypes.C_CLASS_FIELD) {
return new PsiClassField(myTypes, type);
}
if (type == myTypes.C_CLASS_METHOD) {
return new PsiClassMethod(myTypes, type);
return new RsiClassField(myTypes, type);
}
if (type == myTypes.C_SWITCH_BODY) {
return new PsiSwitchBody(myTypes, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.reason.lang.core.type.*;
import org.jetbrains.annotations.*;

public class PsiClassConstructor extends ORCompositePsiElement<ORTypes> {
protected PsiClassConstructor(@NotNull ORTypes types, @NotNull IElementType elementType) {
public class RsiClassConstructor extends ORCompositePsiElement<ORTypes> {
protected RsiClassConstructor(@NotNull ORTypes types, @NotNull IElementType elementType) {
super(types, elementType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import javax.swing.*;

public class PsiClassField extends ORCompositePsiElement<ORTypes> implements NavigatablePsiElement, PsiNameIdentifierOwner, PsiStructuredElement {
protected PsiClassField(@NotNull ORTypes types, @NotNull IElementType elementType) {
public class RsiClassField extends ORCompositePsiElement<ORTypes> implements NavigatablePsiElement, PsiNameIdentifierOwner, PsiStructuredElement {
protected RsiClassField(@NotNull ORTypes types, @NotNull IElementType elementType) {
super(types, elementType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import javax.swing.*;
import java.util.*;

public class PsiKlassImpl extends PsiTokenStub<ORTypes, PsiKlass, PsiKlassStub> implements PsiKlass {
public class RsiClassImpl extends PsiTokenStub<ORTypes, RsiClass, RsiClassStub> implements RsiClass {
// region Constructors
public PsiKlassImpl(@NotNull ORTypes types, @NotNull ASTNode node) {
public RsiClassImpl(@NotNull ORTypes types, @NotNull ASTNode node) {
super(types, node);
}

public PsiKlassImpl(@NotNull ORTypes types, @NotNull PsiKlassStub stub, @NotNull IStubElementType nodeType) {
public RsiClassImpl(@NotNull ORTypes types, @NotNull RsiClassStub stub, @NotNull IStubElementType nodeType) {
super(types, stub, nodeType);
}
// endregion
Expand All @@ -44,11 +44,10 @@ public PsiKlassImpl(@NotNull ORTypes types, @NotNull PsiKlassStub stub, @NotNull
}
// endregion


//region PsiQualifiedName
@Override
public @Nullable String[] getPath() {
PsiKlassStub stub = getGreenStub();
RsiClassStub stub = getGreenStub();
if (stub != null) {
return stub.getPath();
}
Expand All @@ -58,7 +57,7 @@ public PsiKlassImpl(@NotNull ORTypes types, @NotNull PsiKlassStub stub, @NotNull

@Override
public @NotNull String getQualifiedName() {
PsiKlassStub stub = getGreenStub();
RsiClassStub stub = getGreenStub();
if (stub != null) {
return stub.getQualifiedName();
}
Expand All @@ -73,13 +72,13 @@ public PsiKlassImpl(@NotNull ORTypes types, @NotNull PsiKlassStub stub, @NotNull
}

@Override
public @NotNull Collection<PsiClassField> getFields() {
return PsiTreeUtil.findChildrenOfType(getClassBody(), PsiClassField.class);
public @NotNull Collection<RsiClassField> getFields() {
return PsiTreeUtil.findChildrenOfType(getClassBody(), RsiClassField.class);
}

@Override
public @NotNull Collection<PsiClassMethod> getMethods() {
return PsiTreeUtil.findChildrenOfType(getClassBody(), PsiClassMethod.class);
public @NotNull Collection<RsiClassMethod> getMethods() {
return PsiTreeUtil.findChildrenOfType(getClassBody(), RsiClassMethod.class);
}

@Override
Expand All @@ -88,8 +87,8 @@ public PsiKlassImpl(@NotNull ORTypes types, @NotNull PsiKlassStub stub, @NotNull
}

@Override
public @Nullable PsiClassConstructor getConstructor() {
return findChildByClass(PsiClassConstructor.class);
public @Nullable RsiClassConstructor getConstructor() {
return findChildByClass(RsiClassConstructor.class);
}

public ItemPresentation getPresentation() {
Expand Down
Loading

0 comments on commit f60a51e

Please sign in to comment.