Skip to content

Commit

Permalink
COMP: Show the trait of an method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jansen Jan committed May 5, 2017
1 parent 6ddafc0 commit 7589d94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ object CompletionEngine {
const val KEYWORD_PRIORITY = 10.0
}

private fun RsFunction.generateAppendTailText(): String {
val trait = parentOfType<RsImplItem>()?.traitRef?.text ?: return ""
return " by $trait"
}

fun RsCompositeElement.createLookupElement(scopeName: String): LookupElement {
val base = LookupElementBuilder.create(this, scopeName)
.withIcon(if (this is RsFile) RsIcons.MODULE else getIcon(0))
Expand All @@ -35,6 +40,7 @@ fun RsCompositeElement.createLookupElement(scopeName: String): LookupElement {
is RsFunction -> base
.withTypeText(retType?.typeReference?.text ?: "()")
.withTailText(valueParameterList?.text?.replace("\\s+".toRegex(), " ") ?: "()")
.appendTailText(generateAppendTailText(), false)
.withInsertHandler handler@ { context: InsertionContext, _: LookupElement ->
if (context.isInUseBlock) return@handler
if (context.alreadyHasParens) return@handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ class RsLookupElementTest : RsTestBase() {
}
""", tailText = "(&self, x: i32)", typeText = "()")

fun testTraitByMethod() = check("""
trait T {
fn foo(&self, x: i32);
}
struct S;
impl T for S {
fn foo(&self, x: i32) {
//^
unimplemented!()
}
}
""", tailText = "(&self, x: i32) by T", typeText = "()")

fun testConsItem() = check("""
const c: S = unimplemented!();
//^
Expand Down

0 comments on commit 7589d94

Please sign in to comment.