Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3792: MACRO&RES: delegate references from macro call bodies to expansions r=Undin a=vlad20012 Depends on #3640 Closes #2898 This makes work most of navigations actions inside macro calls (go-to-declaration, go-to-implementation, go-to-type-declaration, etc) and also rename (!), find usages, usage highlighting and more. Quick demo: ![Peek 2019-05-05 18-34](https://user-images.githubusercontent.com/3221931/57196351-d441b700-6f64-11e9-89b6-19034b1dc7db.gif) This works only if new macro expansion engine is enabled (see #3628 for details). Co-authored-by: vlad20012 <beskvlad@gmail.com>
- Loading branch information
Showing
26 changed files
with
357 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/org/rust/lang/core/psi/ext/RsMacroBodyIdent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.lang.core.psi.ext | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.psi.PsiElement | ||
import org.rust.lang.core.psi.RsMacroBodyIdent | ||
import org.rust.lang.core.resolve.ref.RsMacroBodyReferenceDelegateImpl | ||
import org.rust.lang.core.resolve.ref.RsReference | ||
|
||
abstract class RsMacroBodyIdentMixin(node: ASTNode) : RsElementImpl(node), RsMacroBodyIdent { | ||
override val referenceNameElement: PsiElement | ||
get() = identifier | ||
|
||
override fun getReference(): RsReference? = RsMacroBodyReferenceDelegateImpl(this) | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/org/rust/lang/core/psi/ext/RsMacroBodyQuoteIdent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.lang.core.psi.ext | ||
|
||
import com.intellij.lang.ASTNode | ||
import com.intellij.psi.PsiElement | ||
import org.rust.lang.core.psi.RsMacroBodyQuoteIdent | ||
import org.rust.lang.core.resolve.ref.RsMacroBodyReferenceDelegateImpl | ||
import org.rust.lang.core.resolve.ref.RsReference | ||
|
||
abstract class RsMacroBodyQuoteIdentMixin(node: ASTNode) : RsElementImpl(node), RsMacroBodyQuoteIdent { | ||
override val referenceNameElement: PsiElement | ||
get() = quoteIdentifier | ||
|
||
override fun getReference(): RsReference? = RsMacroBodyReferenceDelegateImpl(this) | ||
} |
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
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
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
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
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/org/rust/lang/core/resolve/ref/RsMacroBodyReferenceDelegateImpl.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Use of this source code is governed by the MIT license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
package org.rust.lang.core.resolve.ref | ||
|
||
import com.intellij.psi.PsiElement | ||
import org.rust.lang.core.macros.findExpansionElements | ||
import org.rust.lang.core.psi.ext.RsElement | ||
import org.rust.lang.core.psi.ext.RsReferenceElementBase | ||
import org.rust.lang.core.psi.ext.ancestors | ||
|
||
class RsMacroBodyReferenceDelegateImpl( | ||
element: RsReferenceElementBase | ||
) : RsReferenceBase<RsReferenceElementBase>(element) { | ||
override val RsReferenceElementBase.referenceAnchor: PsiElement? | ||
get() = element.referenceNameElement | ||
|
||
private val delegates: List<RsReference> | ||
get() { | ||
return element.findExpansionElements()?.mapNotNull { delegated -> | ||
delegated.ancestors | ||
.mapNotNull { it.reference } | ||
.firstOrNull() as? RsReference | ||
}.orEmpty() | ||
} | ||
|
||
override fun isReferenceTo(element: PsiElement): Boolean { | ||
return delegates.any { it.isReferenceTo(element) } | ||
} | ||
|
||
override fun multiResolve(): List<RsElement> = | ||
delegates.flatMap { it.multiResolve() }.distinct() | ||
} |
Oops, something went wrong.