Keyword completion: do not suggest const except inside top level or object
#KT-23026 Fixed #KT-29840 Fixed
This commit is contained in:
committed by
Alexander Podkhalyuzin
parent
7d809bc1d5
commit
8cdf901538
@@ -407,11 +407,27 @@ object KeywordCompletion {
|
|||||||
|
|
||||||
is KtObjectDeclaration -> if (ownerDeclaration.isObjectLiteral()) KotlinTarget.OBJECT_LITERAL else KotlinTarget.OBJECT
|
is KtObjectDeclaration -> if (ownerDeclaration.isObjectLiteral()) KotlinTarget.OBJECT_LITERAL else KotlinTarget.OBJECT
|
||||||
|
|
||||||
else -> return true
|
else -> return keywordTokenType != CONST_KEYWORD
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ModifierCheckerCore.isPossibleParentTarget(keywordTokenType, parentTarget, languageVersionSettings)) return false
|
if (!ModifierCheckerCore.isPossibleParentTarget(keywordTokenType, parentTarget, languageVersionSettings)) return false
|
||||||
|
|
||||||
|
if (keywordTokenType == CONST_KEYWORD) {
|
||||||
|
return when (parentTarget) {
|
||||||
|
KotlinTarget.OBJECT -> true
|
||||||
|
KotlinTarget.FILE -> {
|
||||||
|
val prevSiblings = elementAt.parent.siblings(withItself = false, forward = false)
|
||||||
|
val hasLineBreak = prevSiblings
|
||||||
|
.takeWhile { it is PsiWhiteSpace || it.isSemicolon() }
|
||||||
|
.firstOrNull { it.text.contains("\n") || it.isSemicolon() } != null
|
||||||
|
hasLineBreak || prevSiblings.none {
|
||||||
|
it !is PsiWhiteSpace && !it.isSemicolon() && it !is KtImportList && it !is KtPackageDirective
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,6 +439,8 @@ object KeywordCompletion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun PsiElement.isSemicolon() = node.elementType == KtTokens.SEMICOLON
|
||||||
|
|
||||||
private fun isErrorElementBefore(token: PsiElement): Boolean {
|
private fun isErrorElementBefore(token: PsiElement): Boolean {
|
||||||
for (leaf in token.prevLeafs) {
|
for (leaf in token.prevLeafs) {
|
||||||
if (leaf is PsiWhiteSpace || leaf is PsiComment) continue
|
if (leaf is PsiWhiteSpace || leaf is PsiComment) continue
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class Foo <caret> {
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: constructor
|
||||||
@@ -39,7 +39,6 @@ class MouseMovedEventArgs
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class A {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ annotation class Test {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public class Test {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class TestClass {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ enum class Test {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: fun
|
// EXIST: fun
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ interface Test {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -17,6 +17,5 @@ class TestSample(<caret>)
|
|||||||
// EXIST: actual
|
// EXIST: actual
|
||||||
/* TODO: keywords below should not be here*/
|
/* TODO: keywords below should not be here*/
|
||||||
// EXIST: abstract
|
// EXIST: abstract
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: lateinit var
|
// EXIST: lateinit var
|
||||||
// NOTHING_ELSE
|
// NOTHING_ELSE
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Some {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ class Some {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class Some {
|
|||||||
// EXIST: tailrec
|
// EXIST: tailrec
|
||||||
// EXIST: external
|
// EXIST: external
|
||||||
// EXIST: annotation class
|
// EXIST: annotation class
|
||||||
// EXIST: const val
|
|
||||||
// EXIST: suspend
|
// EXIST: suspend
|
||||||
// EXIST: typealias
|
// EXIST: typealias
|
||||||
// EXIST: expect
|
// EXIST: expect
|
||||||
|
|||||||
+5
@@ -25,6 +25,11 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
|
|||||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AfterClassName.kt")
|
||||||
|
public void testAfterClassName() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/keywords/AfterClassName.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("AfterClassProperty.kt")
|
@TestMetadata("AfterClassProperty.kt")
|
||||||
public void testAfterClassProperty() throws Exception {
|
public void testAfterClassProperty() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/keywords/AfterClassProperty.kt");
|
runTest("idea/idea-completion/testData/keywords/AfterClassProperty.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user