From e9456ed877bd6a9f6e7b48bb51158589832484ea Mon Sep 17 00:00:00 2001 From: Liudmila Kornilova Date: Mon, 21 Dec 2020 18:58:33 +0300 Subject: [PATCH] #94 Better keywords completion inside classdef --- .../MatlabKeywordCompletionContributor.kt | 13 ++++++++++++- testData/completion/EndInEnumeration.after.m | 6 ++++++ testData/completion/EndInEnumeration.m | 5 +++++ testData/completion/EndInEvents.after.m | 6 ++++++ testData/completion/EndInEvents.m | 5 +++++ testData/completion/EndInMethods.after.m | 7 +++++++ testData/completion/EndInMethods.m | 6 ++++++ testData/completion/EndInProperties.after.m | 6 ++++++ testData/completion/EndInProperties.m | 5 +++++ testData/completion/FunctionInMethods.after.m | 4 ++++ testData/completion/FunctionInMethods.m | 4 ++++ .../matlab/completion/CompletionTest.kt | 8 +++++++- 12 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 testData/completion/EndInEnumeration.after.m create mode 100644 testData/completion/EndInEnumeration.m create mode 100644 testData/completion/EndInEvents.after.m create mode 100644 testData/completion/EndInEvents.m create mode 100644 testData/completion/EndInMethods.after.m create mode 100644 testData/completion/EndInMethods.m create mode 100644 testData/completion/EndInProperties.after.m create mode 100644 testData/completion/EndInProperties.m create mode 100644 testData/completion/FunctionInMethods.after.m create mode 100644 testData/completion/FunctionInMethods.m diff --git a/src/com/github/kornilova203/matlab/completion/MatlabKeywordCompletionContributor.kt b/src/com/github/kornilova203/matlab/completion/MatlabKeywordCompletionContributor.kt index 374e3a1..6522d51 100644 --- a/src/com/github/kornilova203/matlab/completion/MatlabKeywordCompletionContributor.kt +++ b/src/com/github/kornilova203/matlab/completion/MatlabKeywordCompletionContributor.kt @@ -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 { @@ -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 { diff --git a/testData/completion/EndInEnumeration.after.m b/testData/completion/EndInEnumeration.after.m new file mode 100644 index 0000000..e4a7f32 --- /dev/null +++ b/testData/completion/EndInEnumeration.after.m @@ -0,0 +1,6 @@ +classdef C + enumeration + Error (1, 0, 0) + end + % blank +end \ No newline at end of file diff --git a/testData/completion/EndInEnumeration.m b/testData/completion/EndInEnumeration.m new file mode 100644 index 0000000..ad80ad5 --- /dev/null +++ b/testData/completion/EndInEnumeration.m @@ -0,0 +1,5 @@ +classdef C + enumeration + Error (1, 0, 0) + e +end \ No newline at end of file diff --git a/testData/completion/EndInEvents.after.m b/testData/completion/EndInEvents.after.m new file mode 100644 index 0000000..603297f --- /dev/null +++ b/testData/completion/EndInEvents.after.m @@ -0,0 +1,6 @@ +classdef C + events + ToggledState + end + % blank +end \ No newline at end of file diff --git a/testData/completion/EndInEvents.m b/testData/completion/EndInEvents.m new file mode 100644 index 0000000..64f6dac --- /dev/null +++ b/testData/completion/EndInEvents.m @@ -0,0 +1,5 @@ +classdef C + events + ToggledState + e +end \ No newline at end of file diff --git a/testData/completion/EndInMethods.after.m b/testData/completion/EndInMethods.after.m new file mode 100644 index 0000000..cf8b77d --- /dev/null +++ b/testData/completion/EndInMethods.after.m @@ -0,0 +1,7 @@ +classdef C + methods + function f + end + end + % blank +end \ No newline at end of file diff --git a/testData/completion/EndInMethods.m b/testData/completion/EndInMethods.m new file mode 100644 index 0000000..2a054a2 --- /dev/null +++ b/testData/completion/EndInMethods.m @@ -0,0 +1,6 @@ +classdef C + methods + function f + end + e +end \ No newline at end of file diff --git a/testData/completion/EndInProperties.after.m b/testData/completion/EndInProperties.after.m new file mode 100644 index 0000000..0136033 --- /dev/null +++ b/testData/completion/EndInProperties.after.m @@ -0,0 +1,6 @@ +classdef C + properties + my_prop + end + % blank +end \ No newline at end of file diff --git a/testData/completion/EndInProperties.m b/testData/completion/EndInProperties.m new file mode 100644 index 0000000..edc344b --- /dev/null +++ b/testData/completion/EndInProperties.m @@ -0,0 +1,5 @@ +classdef C + properties + my_prop + e +end \ No newline at end of file diff --git a/testData/completion/FunctionInMethods.after.m b/testData/completion/FunctionInMethods.after.m new file mode 100644 index 0000000..a914e2e --- /dev/null +++ b/testData/completion/FunctionInMethods.after.m @@ -0,0 +1,4 @@ +classdef C + methods + function +end \ No newline at end of file diff --git a/testData/completion/FunctionInMethods.m b/testData/completion/FunctionInMethods.m new file mode 100644 index 0000000..0293356 --- /dev/null +++ b/testData/completion/FunctionInMethods.m @@ -0,0 +1,4 @@ +classdef C + methods + f +end \ No newline at end of file diff --git a/tests/com/github/kornilova203/matlab/completion/CompletionTest.kt b/tests/com/github/kornilova203/matlab/completion/CompletionTest.kt index 7732772..38bd96a 100644 --- a/tests/com/github/kornilova203/matlab/completion/CompletionTest.kt +++ b/tests/com/github/kornilova203/matlab/completion/CompletionTest.kt @@ -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()) @@ -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) } }