Skip to content

Commit

Permalink
feat: init basic completion
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 7, 2022
1 parent 6ffeab4 commit fafb650
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ Plugin based on the [IntelliJ Platform Plugin Template][template].

inspired and based on [https://github.com/intellij-rust/intellij-rust](https://github.com/intellij-rust/intellij-rust)

- MIT license. Copyright (c) 2015 Aleksey Kladov, Evgeny Kurbatsky, Alexey Kudinkin and contributors
- MIT license. Copyright (c) 2016 JetBrains

@2022 This code is distributed under the MPL license. See `LICENSE` in this directory.
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
package com.feakin.intellij.completion


import com.feakin.intellij.highlight.FkTokenTypeSets
import com.feakin.intellij.psi.FkNamedElement
import com.intellij.codeInsight.completion.*
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.project.DumbAware
import com.intellij.patterns.PlatformPatterns
import com.intellij.patterns.PlatformPatterns.psiElement
import com.intellij.patterns.StandardPatterns.instanceOf
import com.intellij.util.ProcessingContext


// refs: https://github.com/JetBrains/intellij-community/blob/master/plugins/kotlin/completion/impl-shared/src/org/jetbrains/kotlin/idea/completion/implCommon/KeywordCompletion.kt
class FkKeywordCompletionContributor : CompletionContributor(), DumbAware {
init {
val psiElement = PlatformPatterns.psiElement(FkNamedElement::class.java)
extend(CompletionType.BASIC, psiElement, object : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
parameters: CompletionParameters,
context: ProcessingContext,
result: CompletionResultSet
) {
FkTokenTypeSets.KEY_WORDS.types.forEach {
result.addElement(LookupElementBuilder.create(it.toString()))
}
extend(
CompletionType.BASIC, psiElement().inFile(instanceOf(FkFile::class.java)),
KeywordsCompletionProvider()
)
}

class KeywordsCompletionProvider : CompletionProvider<CompletionParameters>() {
override fun addCompletions(
parameters: CompletionParameters,
context: ProcessingContext,
result: CompletionResultSet
) {
FkTokenTypeSets.KEY_WORDS.types.forEach {
result.addElement(LookupElementBuilder.create(it.debugName).bold())
}
}
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ object FkTokenTypeSets {
FkElementTypes.TO_KEYWORD,
FkElementTypes.RECEIVE_KEYWORD,
FkElementTypes.FLOW_KEYWORD,
// FkElementTypes.FROM_KEYWORD,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.feakin.intellij.FkFile
import com.feakin.intellij.FkFileType
import com.feakin.intellij.psi.*
import com.feakin.intellij.resolve.ref.FkReferenceBase
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
Expand All @@ -25,7 +24,6 @@ class FkContextDeclReferenceImpl(
}
}


private val CONTEXT_NAME_INFERENCE_KEY: Key<CachedValue<List<FkElement>>> = Key.create("CONTEXT_NAME_INFERENCE_KEY")

typealias InferenceResult = List<FkElement>;
Expand Down Expand Up @@ -54,11 +52,11 @@ private fun inferContextName(
PsiTreeUtil.getChildrenOfType(it, FkContextMapDeclaration::class.java)?.toList()
}?.flatten()?.toTypedArray()

val mapBodys: Array<out FkContextMapBody>? = contextMaps?.mapNotNull {
val mapBodies: Array<out FkContextMapBody>? = contextMaps?.mapNotNull {
PsiTreeUtil.getChildrenOfType(it, FkContextMapBody::class.java)?.toList()
}?.flatten()?.toTypedArray()

mapBodys?.forEach { contextMapDeclaration ->
mapBodies?.forEach { contextMapDeclaration ->
PsiTreeUtil.getChildrenOfType(contextMapDeclaration, FkContextName::class.java)
?.forEach { contextName ->
if (contextName.text == element.name) {
Expand Down

0 comments on commit fafb650

Please sign in to comment.