New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advanced macro expansion #2331
Advanced macro expansion #2331
Conversation
2c36713
to
4e64740
Compare
Ok, now we can expand |
e979e84
to
f8ab87d
Compare
3d46a2c
to
0d42bcd
Compare
1d267d5
to
657dfdb
Compare
|
||
fun expandMacro(def: RsMacroDefinition, call: RsMacroCall): List<ExpansionResult>? { | ||
// All std macros contain the only `impl`s which are not supported for now, so ignoring them | ||
if(def.containingCargoTarget?.pkg?.origin == PackageOrigin.STDLIB) return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
field.isAccessible = true | ||
val set = field.get(null) as MutableSet<String> | ||
set.add("JMX") | ||
set.add("RMI") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to drop this code
|
||
val expandedText = expansion.joinToString("\n") { it.text } | ||
|
||
if(StringUtils.deleteWhitespace(expandedText) != StringUtils.deleteWhitespace(expectedExpansion)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
) { | ||
fun match(arg: PsiBuilder): MacroSubstitution? { | ||
return matchPartial(arg)?.let { result -> | ||
if (!arg.eof()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe return result from PsiBuilder.skipWhitespace()
and use it instead of eof
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we just checking that we didn't reach the end of file (macro call body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm. eof
is more informative in this case, i guess
private data class MacroSubstitution( | ||
val variables: Map<String, String>, | ||
val groups: List<List<MacroSubstitution>> | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some docs about it. Especially about groups
property
def: RsMacroDefinition, | ||
call: RsMacroCall | ||
): Pair<RsMacroDefinitionCase, MacroSubstitution>? { | ||
val arg = createPsiBuilder(call, call.macroBody ?: return null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like arg
name - it doesn't contain any useful info
|
||
private fun createPsiBuilder(context: PsiElement, text: String): PsiBuilder { | ||
val psiMgr = PsiManager.getInstance(project) | ||
val result = DummyHolderFactory.createHolder(psiMgr, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you can inline result
15ed9c7
to
66c61a2
Compare
66c61a2
to
0220e1d
Compare
bors r+ |
Build failed |
bors r=undin |
🎉 |
wow! |
Has it been packaged to latest rust plugin release? I am using latest plugin version but error_chain expansion still does not work |
The epic work begins here