Skip to content

Commit

Permalink
#94 Better keywords completion inside classdef
Browse files Browse the repository at this point in the history
  • Loading branch information
kornilova203 committed Dec 21, 2020
1 parent 20efda8 commit e9456ed
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class MatlabKeywordCompletionContributor : CompletionContributor() {
)
private val IN_CYCLE = and(M, or(IDENT.inside(MatlabWhileLoop::class.java), IDENT.inside(MatlabForLoop::class.java)))
private val IN_CLASS = and(M, psiElement().withSuperParent(2, MatlabClassDeclaration::class.java))
private val IN_CLASS_PROPERTIES = and(M, psiElement().withSuperParent(3, MatlabPropertiesBlock::class.java))
private val IN_CLASS_METHODS = and(M, psiElement().withSuperParent(3, MatlabMethodsBlock::class.java))
private val IN_CLASS_EVENTS = and(M, psiElement().withSuperParent(3, MatlabEventsBlock::class.java))
private val IN_CLASS_ENUMERATIONS = and(M, psiElement().withSuperParent(2, MatlabEnumerationBlock::class.java))
}

init {
Expand All @@ -44,7 +48,14 @@ class MatlabKeywordCompletionContributor : CompletionContributor() {
extend(CompletionType.BASIC,
psiElement().and(IN_CLASS),
provider("properties", "methods", "events", "enumeration", "end"))


extend(CompletionType.BASIC,
psiElement().and(or(IN_CLASS_PROPERTIES, IN_CLASS_METHODS, IN_CLASS_EVENTS, IN_CLASS_ENUMERATIONS)),
provider("end"))

extend(CompletionType.BASIC,
psiElement().and(IN_CLASS_METHODS),
provider("function"))
}

private fun provider(vararg keywords: String): CompletionProvider<CompletionParameters> {
Expand Down
6 changes: 6 additions & 0 deletions testData/completion/EndInEnumeration.after.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
classdef C
enumeration
Error (1, 0, 0)
end
% blank
end
5 changes: 5 additions & 0 deletions testData/completion/EndInEnumeration.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classdef C
enumeration
Error (1, 0, 0)
e<caret>
end
6 changes: 6 additions & 0 deletions testData/completion/EndInEvents.after.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
classdef C
events
ToggledState
end
% blank
end
5 changes: 5 additions & 0 deletions testData/completion/EndInEvents.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classdef C
events
ToggledState
e<caret>
end
7 changes: 7 additions & 0 deletions testData/completion/EndInMethods.after.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
classdef C
methods
function f
end
end
% blank
end
6 changes: 6 additions & 0 deletions testData/completion/EndInMethods.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
classdef C
methods
function f
end
e<caret>
end
6 changes: 6 additions & 0 deletions testData/completion/EndInProperties.after.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
classdef C
properties
my_prop
end
% blank
end
5 changes: 5 additions & 0 deletions testData/completion/EndInProperties.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classdef C
properties
my_prop
e<caret>
end
4 changes: 4 additions & 0 deletions testData/completion/FunctionInMethods.after.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classdef C
methods
function
end
4 changes: 4 additions & 0 deletions testData/completion/FunctionInMethods.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
classdef C
methods
f<caret>
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CompletionTest : BasePlatformTestCase() {
fun testClassName() = doTestMultiFile("ClassNameAdd")
fun testFunction() = doTestMultiFile("FunctionAdd")
fun testFunctionWithParenth() = doTestMultiFile("FunctionWithParenthAdd")
fun testEndInProperties() = doTest("end")
fun testEndInMethods() = doTest("end")
fun testEndInEvents() = doTest("end")
fun testEndInEnumeration() = doTest("end")
fun testFunctionInMethods() = doTest("function")

private fun doTest(vararg completionVariants: String) {
myFixture.configureByFile(getTestFilePath())
Expand All @@ -34,7 +39,8 @@ class CompletionTest : BasePlatformTestCase() {
val afterFile = testDataPath + "/" + getTestName(false) + ".after.m"
if (File(afterFile).exists()) {
myFixture.finishLookup('\n')
UsefulTestCase.assertSameLinesWithFile(afterFile, myFixture.file.text)
val actual = myFixture.file.text.replace("(^|.*[^ ]) +$".toRegex(RegexOption.MULTILINE), "$0% blank")
UsefulTestCase.assertSameLinesWithFile(afterFile, actual)
}
}

Expand Down

0 comments on commit e9456ed

Please sign in to comment.