Disable completion binding context caching by default
Now it opt-in in internal mode, due duplication problems #KT-19191 fixed
This commit is contained in:
+11
@@ -58,6 +58,8 @@ class CompletionBindingContextProvider(project: Project) {
|
|||||||
companion object {
|
companion object {
|
||||||
fun getInstance(project: Project): CompletionBindingContextProvider
|
fun getInstance(project: Project): CompletionBindingContextProvider
|
||||||
= project.getComponent(CompletionBindingContextProvider::class.java)
|
= project.getComponent(CompletionBindingContextProvider::class.java)
|
||||||
|
|
||||||
|
var ENABLED = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CompletionData(
|
private class CompletionData(
|
||||||
@@ -86,6 +88,15 @@ class CompletionBindingContextProvider(project: Project) {
|
|||||||
|
|
||||||
|
|
||||||
fun getBindingContext(position: PsiElement, resolutionFacade: ResolutionFacade): BindingContext {
|
fun getBindingContext(position: PsiElement, resolutionFacade: ResolutionFacade): BindingContext {
|
||||||
|
return if (ENABLED) {
|
||||||
|
_getBindingContext(position, resolutionFacade)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance<KtElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun _getBindingContext(position: PsiElement, resolutionFacade: ResolutionFacade): BindingContext {
|
||||||
assert(!position.isPhysical) // position is in synthetic file
|
assert(!position.isPhysical) // position is in synthetic file
|
||||||
|
|
||||||
val inStatement = position.findStatementInBlock()
|
val inStatement = position.findStatementInBlock()
|
||||||
|
|||||||
+54
-49
@@ -37,64 +37,69 @@ abstract class AbstractCompletionIncrementalResolveTest : KotlinLightCodeInsight
|
|||||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
protected fun doTest(testPath: String) {
|
protected fun doTest(testPath: String) {
|
||||||
val file = File(testPath)
|
CompletionBindingContextProvider.ENABLED = true
|
||||||
val hasCaretMarker = FileUtil.loadFile(file, true).contains("<caret>")
|
try {
|
||||||
myFixture.configureByFile(testPath)
|
val file = File(testPath)
|
||||||
|
val hasCaretMarker = FileUtil.loadFile(file, true).contains("<caret>")
|
||||||
|
myFixture.configureByFile(testPath)
|
||||||
|
|
||||||
val document = myFixture.editor.document
|
val document = myFixture.editor.document
|
||||||
val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER)
|
val beforeMarkerOffset = document.text.indexOf(BEFORE_MARKER)
|
||||||
assertTrue("\"$BEFORE_MARKER\" is missing in file \"$testPath\"", beforeMarkerOffset >= 0)
|
assertTrue("\"$BEFORE_MARKER\" is missing in file \"$testPath\"", beforeMarkerOffset >= 0)
|
||||||
|
|
||||||
val changeMarkerOffset = document.text.indexOf(CHANGE_MARKER)
|
val changeMarkerOffset = document.text.indexOf(CHANGE_MARKER)
|
||||||
assertTrue("\"$CHANGE_MARKER\" is missing in file \"$testPath\"", changeMarkerOffset >= 0)
|
assertTrue("\"$CHANGE_MARKER\" is missing in file \"$testPath\"", changeMarkerOffset >= 0)
|
||||||
|
|
||||||
val textToType = InTextDirectivesUtils.findArrayWithPrefixes(document.text, TYPE_DIRECTIVE_PREFIX).singleOrNull()
|
val textToType = InTextDirectivesUtils.findArrayWithPrefixes(document.text, TYPE_DIRECTIVE_PREFIX).singleOrNull()
|
||||||
?.let { StringUtil.unquoteString(it) }
|
?.let { StringUtil.unquoteString(it) }
|
||||||
val backspaceCount = InTextDirectivesUtils.getPrefixedInt(document.text, BACKSPACES_DIRECTIVE_PREFIX)
|
val backspaceCount = InTextDirectivesUtils.getPrefixedInt(document.text, BACKSPACES_DIRECTIVE_PREFIX)
|
||||||
assertTrue("At least one of \"$TYPE_DIRECTIVE_PREFIX\" and \"$BACKSPACES_DIRECTIVE_PREFIX\" should be defined",
|
assertTrue("At least one of \"$TYPE_DIRECTIVE_PREFIX\" and \"$BACKSPACES_DIRECTIVE_PREFIX\" should be defined",
|
||||||
textToType != null || backspaceCount != null)
|
textToType != null || backspaceCount != null)
|
||||||
|
|
||||||
val beforeMarker = document.createRangeMarker(beforeMarkerOffset, beforeMarkerOffset + BEFORE_MARKER.length)
|
val beforeMarker = document.createRangeMarker(beforeMarkerOffset, beforeMarkerOffset + BEFORE_MARKER.length)
|
||||||
val changeMarker = document.createRangeMarker(changeMarkerOffset, changeMarkerOffset + CHANGE_MARKER.length)
|
val changeMarker = document.createRangeMarker(changeMarkerOffset, changeMarkerOffset + CHANGE_MARKER.length)
|
||||||
changeMarker.isGreedyToRight = true
|
changeMarker.isGreedyToRight = true
|
||||||
|
|
||||||
project.executeWriteCommand("") {
|
project.executeWriteCommand("") {
|
||||||
document.deleteString(beforeMarker.startOffset, beforeMarker.endOffset)
|
document.deleteString(beforeMarker.startOffset, beforeMarker.endOffset)
|
||||||
document.deleteString(changeMarker.startOffset, changeMarker.endOffset)
|
document.deleteString(changeMarker.startOffset, changeMarker.endOffset)
|
||||||
}
|
|
||||||
|
|
||||||
val caretMarker = if (hasCaretMarker)
|
|
||||||
document.createRangeMarker(editor.caretModel.offset, editor.caretModel.offset)
|
|
||||||
else
|
|
||||||
null
|
|
||||||
editor.caretModel.moveToOffset(beforeMarker.startOffset)
|
|
||||||
|
|
||||||
val testLog = StringBuilder()
|
|
||||||
CompletionBindingContextProvider.getInstance(project).TEST_LOG = testLog
|
|
||||||
|
|
||||||
myFixture.complete(CompletionType.BASIC)
|
|
||||||
|
|
||||||
project.executeWriteCommand("") {
|
|
||||||
if (backspaceCount != null) {
|
|
||||||
document.deleteString(changeMarker.startOffset - backspaceCount, changeMarker.startOffset)
|
|
||||||
}
|
}
|
||||||
if (textToType != null) {
|
|
||||||
document.insertString(changeMarker.startOffset, textToType)
|
val caretMarker = if (hasCaretMarker)
|
||||||
|
document.createRangeMarker(editor.caretModel.offset, editor.caretModel.offset)
|
||||||
|
else
|
||||||
|
null
|
||||||
|
editor.caretModel.moveToOffset(beforeMarker.startOffset)
|
||||||
|
|
||||||
|
val testLog = StringBuilder()
|
||||||
|
CompletionBindingContextProvider.getInstance(project).TEST_LOG = testLog
|
||||||
|
|
||||||
|
myFixture.complete(CompletionType.BASIC)
|
||||||
|
|
||||||
|
project.executeWriteCommand("") {
|
||||||
|
if (backspaceCount != null) {
|
||||||
|
document.deleteString(changeMarker.startOffset - backspaceCount, changeMarker.startOffset)
|
||||||
|
}
|
||||||
|
if (textToType != null) {
|
||||||
|
document.insertString(changeMarker.startOffset, textToType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (caretMarker != null) {
|
if (caretMarker != null) {
|
||||||
editor.caretModel.moveToOffset(caretMarker.startOffset)
|
editor.caretModel.moveToOffset(caretMarker.startOffset)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
editor.caretModel.moveToOffset(changeMarker.endOffset)
|
editor.caretModel.moveToOffset(changeMarker.endOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
testCompletion(FileUtil.loadFile(file, true),
|
testCompletion(FileUtil.loadFile(file, true),
|
||||||
JvmPlatform,
|
JvmPlatform,
|
||||||
{ completionType, count -> myFixture.complete(completionType, count) },
|
{ completionType, count -> myFixture.complete(completionType, count) },
|
||||||
additionalValidDirectives = listOf(TYPE_DIRECTIVE_PREFIX, BACKSPACES_DIRECTIVE_PREFIX))
|
additionalValidDirectives = listOf(TYPE_DIRECTIVE_PREFIX, BACKSPACES_DIRECTIVE_PREFIX))
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(file.parent, file.nameWithoutExtension + ".log"), testLog.toString())
|
KotlinTestUtils.assertEqualsToFile(File(file.parent, file.nameWithoutExtension + ".log"), testLog.toString())
|
||||||
|
} finally {
|
||||||
|
CompletionBindingContextProvider.ENABLED = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,6 +146,10 @@
|
|||||||
text="Local scenario"/>
|
text="Local scenario"/>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
|
<action id="CompletionBindingContextCachingToggleAction"
|
||||||
|
class="org.jetbrains.kotlin.idea.actions.internal.CompletionBindingContextCachingToggleAction"
|
||||||
|
text="Enable completion binding context caching"/>
|
||||||
|
|
||||||
<action id="CheckComponentsUsageSearchAction" class="org.jetbrains.kotlin.idea.actions.internal.CheckComponentsUsageSearchAction"
|
<action id="CheckComponentsUsageSearchAction" class="org.jetbrains.kotlin.idea.actions.internal.CheckComponentsUsageSearchAction"
|
||||||
text="Check Component Functions Usage Search"/>
|
text="Check Component Functions Usage Search"/>
|
||||||
|
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 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.actions.internal
|
||||||
|
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||||
|
import com.intellij.openapi.actionSystem.ToggleAction
|
||||||
|
import org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider
|
||||||
|
|
||||||
|
class CompletionBindingContextCachingToggleAction : ToggleAction() {
|
||||||
|
override fun isSelected(e: AnActionEvent?): Boolean =
|
||||||
|
CompletionBindingContextProvider.ENABLED
|
||||||
|
|
||||||
|
|
||||||
|
override fun setSelected(e: AnActionEvent?, state: Boolean) {
|
||||||
|
CompletionBindingContextProvider.ENABLED = state
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun update(e: AnActionEvent) {
|
||||||
|
e.presentation.isEnabledAndVisible = KotlinInternalMode.enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user