FIR IDE: add basic keyword completion
This commit is contained in:
committed by
TeamCityServer
parent
62fe3930ff
commit
1f93eb0841
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
|
||||
object FirKeywordCompletion {
|
||||
private val keywordCompletion = KeywordCompletion(object : KeywordCompletion.LanguageVersionSettingProvider {
|
||||
override fun getLanguageVersionSetting(element: PsiElement) = LanguageVersionSettingsImpl.DEFAULT // TODO
|
||||
override fun getLanguageVersionSetting(module: Module) = LanguageVersionSettingsImpl.DEFAULT // TODO
|
||||
})
|
||||
|
||||
fun completeKeywords(result: CompletionResultSet, position: PsiElement, prefixMatcher: PrefixMatcher, isJvmModule: Boolean) {
|
||||
keywordCompletion.complete(position, prefixMatcher, isJvmModule) { lookupElement ->
|
||||
result.addElement(lookupElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -26,8 +26,10 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSymbolWithVisibility
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtClassType
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
||||
|
||||
@@ -140,8 +142,12 @@ private class KotlinCommonCompletionProvider(
|
||||
@OptIn(InvalidWayOfUsingAnalysisSession::class)
|
||||
fun addCompletions(parameters: CompletionParameters, result: CompletionResultSet) {
|
||||
val originalFile = parameters.originalFile as? KtFile ?: return
|
||||
val isJvmModule = TargetPlatformDetector.getPlatform(originalFile).isJvm()
|
||||
|
||||
recordOriginalFile(parameters)
|
||||
|
||||
FirKeywordCompletion.completeKeywords(result, parameters.position, prefixMatcher, isJvmModule = isJvmModule)
|
||||
|
||||
val reference = (parameters.position.parent as? KtSimpleNameExpression)?.mainReference ?: return
|
||||
val nameExpression = reference.expression.takeIf { it !is KtLabelReferenceExpression } ?: return
|
||||
|
||||
|
||||
+1
-2
@@ -16,6 +16,7 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.isTextAt
|
||||
import org.jetbrains.kotlin.idea.core.asFqNameWithRootPrefixIfNeeded
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.analyse
|
||||
@@ -395,8 +396,6 @@ private object ShortNamesRenderer {
|
||||
"${if (param.isVararg) "vararg " else ""}${param.name.asString()}: ${param.annotatedType.type.render()}"
|
||||
}
|
||||
|
||||
private fun Document.isTextAt(offset: Int, text: String) =
|
||||
offset + text.length <= textLength && getText(TextRange(offset, offset + text.length)) == text
|
||||
|
||||
private fun CharSequence.skipSpaces(index: Int): Int =
|
||||
(index until length).firstOrNull { val c = this[it]; c != ' ' && c != '\t' } ?: this.length
|
||||
|
||||
Reference in New Issue
Block a user