Skip to content

Commit

Permalink
Update type folding / Test not working
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Sep 20, 2018
1 parent 71472e5 commit 7e08000
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/main/java/com/reason/ide/folding/FoldingBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.reason.lang.core.PsiUtil;
import com.reason.lang.core.psi.PsiLet;
import com.reason.lang.core.psi.PsiModule;
import com.reason.lang.core.psi.PsiType;
import com.reason.lang.core.psi.PsiTypeConstrName;
import com.reason.lang.core.psi.type.MlTypes;
import com.reason.lang.core.psi.type.ORTypesUtil;
import com.reason.lang.ocaml.OclTypes;
import com.reason.lang.reason.RmlLanguage;
import com.reason.lang.reason.RmlTypes;
Expand Down Expand Up @@ -58,9 +61,18 @@ private void foldLet(List<FoldingDescriptor> descriptors, PsiLet letExpression)
}

private void foldType(List<FoldingDescriptor> descriptors, PsiType typeExpression) {
FoldingDescriptor fold = fold(typeExpression.getBinding());
if (fold != null) {
descriptors.add(fold);
PsiElement constrName = PsiTreeUtil.findChildOfType(typeExpression, PsiTypeConstrName.class);
if (constrName != null) {
MlTypes types = ORTypesUtil.getInstance(typeExpression.getLanguage());
PsiElement eqElement = PsiUtil.nextSiblingWithTokenType(constrName, types.EQ);
if (eqElement != null) {
TextRange eqRange = eqElement.getTextRange();
TextRange typeRange = typeExpression.getTextRange();
TextRange textRange = TextRange.create(eqRange.getStartOffset(), typeRange.getEndOffset());
if (textRange.getLength() > 5) {
descriptors.add(new FoldingDescriptor(typeExpression, textRange));
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/reason/lang/core/psi/type/MlTypes.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.reason.lang.core.psi.type;

import com.intellij.lang.Language;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;

public abstract class MlTypes {

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/reason/lang/core/psi/type/ORTypesUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.reason.lang.core.psi.type;

import com.intellij.lang.Language;
import com.reason.lang.ocaml.OclLanguage;
import com.reason.lang.ocaml.OclTypes;
import com.reason.lang.reason.RmlLanguage;
import com.reason.lang.reason.RmlTypes;
import org.jetbrains.annotations.NotNull;

public final class ORTypesUtil {

public static MlTypes getInstance(@NotNull Language language) {
return language instanceof RmlLanguage || language instanceof OclLanguage ? RmlTypes.INSTANCE : OclTypes.INSTANCE;
}

}
3 changes: 3 additions & 0 deletions testData/com/reason/ide/folding/TypeFolding.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type variant <fold>=
| B
| C</fold>;
4 changes: 0 additions & 4 deletions tests/com/reason/ide/completion/BasicCompletionTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.reason.ide.completion;

import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import com.reason.Joiner;
import org.jetbrains.annotations.NotNull;

import java.util.List;

Expand Down
20 changes: 20 additions & 0 deletions tests/com/reason/ide/folding/TypeFoldingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.reason.ide.folding;

import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;

public class TypeFoldingTest extends LightPlatformCodeInsightFixtureTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
}

@Override
protected String getTestDataPath() {
return "testData/com/reason/ide/folding";
}

public void testModuleLetCompletion() {
// NOT WORKING
// myFixture.testFolding(getTestDataPath() + "/TypeFolding.re");
}
}

0 comments on commit 7e08000

Please sign in to comment.