Created
June 12, 2016 15:43
-
-
Save bgourlie/da6fe8aed93fa88c52c265d49e1e3aa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.rust.ide | |
import com.intellij.codeInsight.completion.* | |
import com.intellij.codeInsight.lookup.LookupElementBuilder | |
import com.intellij.patterns.PlatformPatterns | |
import com.intellij.util.ProcessingContext | |
import org.rust.lang.RustLanguage | |
import org.rust.lang.core.psi.RustOuterAttrElement | |
class DeriveCompletionContributor : CompletionContributor() { | |
init { | |
extend(CompletionType.BASIC, PlatformPatterns.psiElement(RustOuterAttrElement::class.java).withLanguage(RustLanguage), object : CompletionProvider<CompletionParameters>() { | |
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext?, result: CompletionResultSet) { | |
result.addElement(LookupElementBuilder.create("Clone")); | |
result.addElement(LookupElementBuilder.create("Copy")); | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To preface: I'm new both to Kotlin and IntelliJ plugin development, so please excuse any naivety!
I'm following the example here for creating a
CompletionContributor
. I'm having trouble getting this simple completion to trigger, presumably because I'm not passing the correct parameters toPlatformPatterns.psiElement()
.Ultimately, we'll want completion to trigger when the following conditions are met:
derive
attribute, specifically#[derive(C<carat>)]
Right now, I'm just trying to accomplish step one, which is to correctly identify the element.
FWIW, I've gotten this completion to trigger on
RustLiteral.Text
elements, simply to rule out any issues with getting the completion contributor registered.