KT-8979 Completion of non-imported extension with "!" character corrupts code
#KT-8979 Fixed
This commit is contained in:
+3
-1
@@ -34,7 +34,9 @@ class WithExpressionPrefixInsertHandler(val prefix: String) : InsertHandler<Look
|
||||
}
|
||||
|
||||
fun postHandleInsert(context: InsertionContext) {
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments()
|
||||
val psiDocumentManager = PsiDocumentManager.getInstance(context.project)
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(context.document)
|
||||
psiDocumentManager.commitAllDocuments()
|
||||
|
||||
val offset = context.getStartOffset()
|
||||
val token = context.getFile().findElementAt(offset)!!
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package qqqq
|
||||
|
||||
import a
|
||||
import b
|
||||
|
||||
fun foo() {
|
||||
"".isX<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package foo
|
||||
|
||||
val String.isXXX: Boolean
|
||||
get() = true
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package qqqq
|
||||
|
||||
import a
|
||||
import b
|
||||
import foo.isXXX
|
||||
|
||||
fun foo() {
|
||||
!"".isXXX<caret>
|
||||
}
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.test.handlers;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.kotlin.idea.completion.test.KotlinCompletionTestCase;
|
||||
import org.jetbrains.kotlin.idea.completion.test.TestPackage;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CompletionMultifileHandlerTest extends KotlinCompletionTestCase {
|
||||
public void testExtensionFunctionImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionPropertyImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testImportAlreadyImportedObject() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testJetClassCompletionImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopLevelFunctionImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopLevelFunctionInQualifiedExpr() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTopLevelPropertyImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoParenthesisInImports() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKeywordExtensionFunctionName() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInfixExtensionCallImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testClassWithClassObject() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testGlobalFunctionImportInLambda() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testObjectInStringTemplate() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void doTest() throws Exception {
|
||||
String fileName = getTestName(false);
|
||||
|
||||
configureByFiles(null, fileName + "-1.kt", fileName + "-2.kt");
|
||||
complete(2);
|
||||
if (myItems != null) {
|
||||
TestCase.assertTrue("Multiple items in completion", myItems.length == 1);
|
||||
selectItem(myItems[0]);
|
||||
}
|
||||
checkResultByFile(fileName + ".kt.after");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(TestPackage.getCOMPLETION_TEST_DATA_BASE_PATH(), "/handlers/multifile/").getPath() + File.separator;
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion.test.handlers
|
||||
|
||||
import org.jetbrains.kotlin.idea.completion.test.COMPLETION_TEST_DATA_BASE_PATH
|
||||
import org.jetbrains.kotlin.idea.completion.test.KotlinCompletionTestCase
|
||||
import java.io.File
|
||||
|
||||
class CompletionMultiFileHandlerTest : KotlinCompletionTestCase() {
|
||||
fun testExtensionFunctionImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testExtensionPropertyImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testImportAlreadyImportedObject() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testJetClassCompletionImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testTopLevelFunctionImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testTopLevelFunctionInQualifiedExpr() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testTopLevelPropertyImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testNoParenthesisInImports() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testKeywordExtensionFunctionName() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testInfixExtensionCallImport() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testClassWithClassObject() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testGlobalFunctionImportInLambda() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testObjectInStringTemplate() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testExclCharInsertImport() {
|
||||
doTest('!')
|
||||
}
|
||||
|
||||
fun doTest(completionChar: Char = '\n') {
|
||||
val fileName = getTestName(false)
|
||||
|
||||
configureByFiles(null, fileName + "-1.kt", fileName + "-2.kt")
|
||||
complete(2)
|
||||
if (myItems != null) {
|
||||
val item = myItems.singleOrNull() ?: error("Multiple items in completion")
|
||||
selectItem(item, completionChar)
|
||||
}
|
||||
checkResultByFile(fileName + ".kt.after")
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = File(COMPLETION_TEST_DATA_BASE_PATH, "/handlers/multifile/").path + File.separator
|
||||
}
|
||||
Reference in New Issue
Block a user