Macro support in scala-ide.

瀏覽次數:224 次
跳到第一則未讀訊息

Artem Nikiforov

未讀,
2014年6月23日 中午12:00:182014/6/23
收件者:scala-...@googlegroups.com、Eugene Burmako
Hi!
For the past month I've been working around the support of macros in scala-ide.

It works this way:
1) At first it generates annotations, where macros are found(in the squashed version compiler.analyzer.MacroExpansionAttachment are used)
2) When user clicks on the annotation icon macro is expanded inline. 
3) When clicking on "Unexpand macro annotation", or saving the document macro is collapsed into the previous text.
4) After saving the document all collapsed macros are reexpanded(I've turned this off, because found a bug)

Artem.

Artem Nikiforov

未讀,
2014年6月25日 凌晨2:14:442014/6/25
收件者:scala-...@googlegroups.com、xen...@gmail.com
And... Here is the screencast how it works now: https://drive.google.com/file/d/0B306f-U0vD41V3puM2lwdmh4Szg/edit?usp=sharing
And... Here is the squash commit: https://github.com/lnxmnx/scala-ide/tree/squash-for-review2

Now save is implemented this way: we collapse all expanded macros, give each of the collapsed macro a marker. Perform save, add a listener on editor's annotation model. When macros are found with ImplicitHighlightingPresenter, listener is notified, it finds all collapsed macro markers and if there is a macroAttachment, that can be expanded, expands it.

Any ideas how this can be implemented in the other way?

Could you review the code, please? Any comments on how to improve?

iulian dragos

未讀,
2014年6月25日 凌晨3:47:482014/6/25
收件者:scala-ide-dev、Eugene Burmako
Hi Artem,

This looks quite amazing! Could you please open a pull request? I think that's the simplest way to review your code.

cheers,
iulian



--
You received this message because you are subscribed to the Google Groups "Scala IDE Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-dev/0edefb57-3ce0-4c95-a5b0-10cbf15269dc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

Artem Nikiforov

未讀,
2014年6月25日 清晨6:12:312014/6/25
收件者:scala-...@googlegroups.com、xen...@gmail.com
I've opened the pull request

среда, 25 июня 2014 г., 11:47:48 UTC+4 пользователь Iulian Dragos написал:
Hi Artem,

This looks quite amazing! Could you please open a pull request? I think that's the simplest way to review your code.

cheers,
iulian

Artem Nikiforov

未讀,
2014年7月14日 清晨7:59:572014/7/14
收件者:scala-...@googlegroups.com、xen...@gmail.com
Hi!
I'm working around the macro expansion in eclipse IDE. Now it's implemented as an inline expansion into the document contents, and that's bad, because:
1) When saving the document macros are collapsed and then reexpanded(we shouldn't save the expansion of a macro)
2) There is a big chance of messing the document content when expanding macros this way.

Trying to solve above mentioned problem I've tryed to make an inter layer between store, line tracker and the document. This approach seemed to work(snippet for adding a simple one line string to a document), it showed added text, but when editing the document content a huge amount of errors drops down to log.

So, the question is: any ideas how macro expansion can be implemented in the other way?

For now I will continue experimenting to make macro implementations work this way.
Artem.

Eugene Burmako

未讀,
2014年7月16日 清晨5:03:552014/7/16
收件者:scala-...@googlegroups.com、xen...@gmail.com
Maybe you could elaborate more on your solution? How does it work in more detail? What are the key pieces of code that implement it? What are the errors that you're getting?

Artem Nikiforov

未讀,
2014年8月11日 下午1:20:232014/8/11
收件者:scala-...@googlegroups.com、xen...@gmail.com
Hi!

Scala macros are functions called by the compiler during program
compilation. For the past time I've been working around the support of
macros in scala-ide.


The screencast shows, that macros can be turned off by clicking on the
icon, M1+M2+M(Ctrl-Shift-M) shortcut or through preference page.

Now there are two different macros API in ASTrees. First is the
default MacroExpansionAttachment The second one is the Palladium
API. If Palladium API is available macro expansions are made of its
attachments. But if Palladium attachments are unavailable , then

After Getting the sources annotations are constructed. As shown
previously macro support in Scala ide is designed through a custom
action accompanied by a custom gutter icon that expands/collapses
macro applications inline. On images above one can see such a gutter
icon in two states: collapsed (red) and expanded (grey).

When clicking on such an icon macros on line get expanded or collapsed
respectively.

Expansions are done into the source code itself. So the document
content changes. But from the users point of view, when expanding the
macros document shouldn't be modified. That's why replaceWithDirty
state is used. It replaces the internal dirtyState variable through a

After expanding to the source code presentation compiler analizes
sources and all the semantic services (syntax highlighting, error
detections, go to definitions functionality, e.t.c) works out of the
box.

Through createLineNumberRulerColumn function we integrate line number
column for custom line numbering. It internally stores regions, where
macros are and change line numbers where neccesary.

Macros are expanded inline, so their expansions definitely shouldn’t
be saved to disk. When triggering save command performSave function of
ScalaSourceFileEditor is called. Before actual save every macro is
erased with its expandee, so that source file doesn't contain any
macro applications. After saving the document macros are expanded with
the state that they were before save happened.


Could you review the code? Anything to change, fix, clarify?
I absolutely sure, that lost/forgot some things to fix from previous PR.
Artem.

Artem Nikiforov

未讀,
2014年11月28日 上午8:22:592014/11/28
收件者:scala-...@googlegroups.com、xen...@gmail.com
Hi all, again :)
Recently I've made another PR

The difference between previous version is that on disabling macroExpansions(through icon, preference page or M1+M2+M) all macro expansions are erased. All other functionality is mentioned in previous message.
回覆所有人
回覆作者
轉寄
0 則新訊息