-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AbnerZheng/master
Add folding feature and initial test framework.
- Loading branch information
Showing
18 changed files
with
4,222 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
out/ | ||
.idea/workspace.xml | ||
gen/ | ||
*.java~ | ||
/*.jar | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/dictionaries | ||
.idea/uiDesigner.xml | ||
.idea/misc.xml | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package coop.rchain.lang.folding | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.lang.folding.CustomFoldingBuilder | ||
import com.intellij.lang.folding.FoldingBuilder | ||
import com.intellij.lang.folding.FoldingDescriptor | ||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.project.DumbAware | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.javadoc.PsiDocComment | ||
import com.intellij.psi.tree.IElementType | ||
import com.intellij.psi.util.PsiTreeUtil | ||
import coop.rchain.lang.psi.RhoFile | ||
import coop.rchain.lang.psi.RhoProc | ||
import coop.rchain.lang.psi.RhoTypes | ||
import coop.rchain.lang.psi.impl.RhoProcBlockImpl | ||
|
||
import java.util.ArrayList | ||
|
||
class RholangFoldingBuilder : FoldingBuilder, DumbAware { | ||
|
||
override fun buildFoldRegions(node: ASTNode, document: Document): Array<FoldingDescriptor> { | ||
val descriptors = ArrayList<FoldingDescriptor>() | ||
appendDescriptors(node.psi, descriptors, document) | ||
|
||
return descriptors.toTypedArray() | ||
} | ||
|
||
private fun appendDescriptors(psi: PsiElement, descriptors: MutableList<FoldingDescriptor>, document: Document) { | ||
if (isSingleLine(psi, document)) { // don't fold when text is single line | ||
return | ||
} | ||
|
||
val elementType = psi.node.elementType | ||
|
||
if (elementType === RhoTypes.BLOCK_DOC_COMMENT) { | ||
val blockDocComment = psi.node | ||
val range = TextRange(blockDocComment.textRange.startOffset + 3, blockDocComment.textRange.endOffset - 2) | ||
descriptors.add(FoldingDescriptor(blockDocComment, range)) | ||
} else if (elementType === RhoTypes.PROC_BLOCK) { | ||
val textRange = psi.node.textRange | ||
val textRange1 = TextRange(textRange.startOffset + 1, textRange.endOffset - 1) | ||
descriptors.add(FoldingDescriptor(psi.node, textRange1)) | ||
} | ||
|
||
var child: PsiElement? = psi.firstChild | ||
while (child != null) { | ||
appendDescriptors(child, descriptors, document) | ||
child = child.nextSibling | ||
} | ||
} | ||
|
||
|
||
private fun isSingleLine(element: PsiElement, document: Document): Boolean { | ||
val textRange = element.textRange | ||
return document.getLineNumber(textRange.startOffset) == document.getLineNumber(textRange.endOffset) | ||
} | ||
|
||
override fun getPlaceholderText(node: ASTNode): String? { | ||
return "..." | ||
} | ||
|
||
override fun isCollapsedByDefault(node: ASTNode): Boolean { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package coop.rchain | ||
|
||
import com.intellij.openapi.application.PathManager | ||
|
||
object RholangTestUtil { | ||
val baseTestDataPath: String | ||
get() = PathManager.getHomePath() + "/testData" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package coop.rchain.ide.folding | ||
|
||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase | ||
import coop.rchain.RholangTestUtil.baseTestDataPath | ||
|
||
|
||
class RholangCodeInsightTest : LightCodeInsightFixtureTestCase() { | ||
override fun getTestDataPath(): String { | ||
return baseTestDataPath | ||
} | ||
|
||
fun testFolding() { | ||
doTestFolding("blockDocComment") | ||
doTestFolding("procedure") | ||
} | ||
|
||
private fun doTestFolding(testName: String) { | ||
myFixture.testFolding("$testDataPath/ide/folding/$testName.rho") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package coop.rchain.lang.lexer | ||
|
||
import com.intellij.lexer.Lexer | ||
import com.intellij.openapi.application.PathManager | ||
import com.intellij.testFramework.LexerTestCase | ||
import coop.rchain.RholangTestUtil | ||
import coop.rchain.lang.RhoLexerAdapter | ||
|
||
import java.nio.file.Paths | ||
|
||
class RholangLexTest : LexerTestCase() { | ||
|
||
override fun createLexer(): Lexer { | ||
return RhoLexerAdapter() | ||
} | ||
|
||
override fun getDirPath(): String { | ||
return Paths.get(RholangTestUtil.baseTestDataPath, "lexer").toString().substring(PathManager.getHomePath().length) | ||
} | ||
|
||
fun testToken() { | ||
doFileTest("rho") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package coop.rchain.lang.parser | ||
|
||
import com.intellij.testFramework.ParsingTestCase | ||
import coop.rchain.RholangTestUtil | ||
import coop.rchain.lang.RhoParserDefinition | ||
import java.nio.file.Paths | ||
|
||
class RholangParserTest : ParsingTestCase("", "rho", RhoParserDefinition()) { | ||
|
||
override fun getTestDataPath(): String { | ||
return Paths.get(RholangTestUtil.baseTestDataPath, "parser").toString() | ||
} | ||
|
||
fun testtoken() { | ||
doTest(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/**<fold text='...'> | ||
* Test | ||
</fold>*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
new time_contract in { | ||
contract time_contract(stream) = { | ||
log-time(stream) | ||
} | | ||
time_contract!(ostream-new("test.txt")) | | ||
time_contract!(ostream-new("test2.txt")) | ||
} |
Oops, something went wrong.