Skip to content
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

Merged
merged 1 commit into from Apr 6, 2018
Merged

Conversation

vlad20012
Copy link
Member

The epic work begins here

@vlad20012 vlad20012 force-pushed the macro-expansion branch 2 times, most recently from 2c36713 to 4e64740 Compare February 27, 2018 01:56
@vlad20012
Copy link
Member Author

vlad20012 commented Feb 27, 2018

Ok, now we can expand error_chain

@vlad20012 vlad20012 force-pushed the macro-expansion branch 9 times, most recently from e979e84 to f8ab87d Compare March 4, 2018 00:04
@vlad20012 vlad20012 force-pushed the macro-expansion branch 4 times, most recently from 3d46a2c to 0d42bcd Compare March 23, 2018 13:17
@vlad20012 vlad20012 force-pushed the macro-expansion branch 5 times, most recently from 1d267d5 to 657dfdb Compare April 4, 2018 18:45

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
Copy link
Member

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")
Copy link
Member

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)) {
Copy link
Member

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()) {
Copy link
Member

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?

Copy link
Member Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed)

Copy link
Member Author

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>>
)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@vlad20012 vlad20012 force-pushed the macro-expansion branch 2 times, most recently from 15ed9c7 to 66c61a2 Compare April 5, 2018 15:21
@vlad20012 vlad20012 changed the title WIP Advanced macro expansion Advanced macro expansion Apr 5, 2018
@Undin
Copy link
Member

Undin commented Apr 6, 2018

bors r+

bors bot added a commit that referenced this pull request Apr 6, 2018
2331: Advanced macro expansion r=Undin a=vlad20012

The epic work begins here
@bors
Copy link
Contributor

bors bot commented Apr 6, 2018

Build failed

@vlad20012
Copy link
Member Author

bors r=undin

bors bot added a commit that referenced this pull request Apr 6, 2018
2331: Advanced macro expansion r=undin a=vlad20012

The epic work begins here
@bors
Copy link
Contributor

bors bot commented Apr 6, 2018

Build succeeded

@bors bors bot merged commit 0220e1d into intellij-rust:master Apr 6, 2018
@alexander-irbis
Copy link

🎉

This was referenced Apr 6, 2018
@vasily-kirichenko
Copy link
Contributor

wow!

@vlad20012 vlad20012 deleted the macro-expansion branch April 13, 2018 16:56
@avkonst
Copy link

avkonst commented May 25, 2018

Has it been packaged to latest rust plugin release? I am using latest plugin version but error_chain expansion still does not work

@avkonst avkonst mentioned this pull request Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants