~technomancy/fennel#247: 
Accessing the AST of the current macro and its uses (`assert-compile`)

This is a continuation from a conversation in the #fennel:matrix.org channel.

Some macros, e.g. no parameters, primitive parameters, etc., do not have an AST to pass to assert-compile, which limits its utility. Anecdotally, this limitation has meant that with several macros I've written, fennel-ls raises compile errors with code hints on the line where the macros are imported (import-macros), seemingly because it's unsure what line is relevant. My guess is that the primary use of assert-compile is to validate that the macro its called in is correctly structured as well, so I'm wondering if there are ways for us maximize for the presumably most common case.

Two potential options:

  1. The AST of the macro that is being evaluated is available for itself on the compile global environment, such that ast-source will give you the line and col numbers. This could then be passed into assert-compile if desired.
  2. If no AST is provided to a assert-compile call, it will default to the AST source of the macro from which it is called.

The nuances of whether or not we can expose AST information like that and what the consequences would be are beyond my scope of understanding, but I wanted to drop this in here for posterity. : )

Status
REPORTED
Submitter
~pinkstringmachine
Assigned to
No-one
Submitted
2 months ago
Updated
a month ago
Labels
enhancement

~technomancy a month ago

I think I may have been mixed up when we talked about this in chat. The compiler seems to already do the right thing for this; calls to assert-compile are already highlighting the whole call to the macro. (Honestly looking at the code, I'm not sure how! But it is.)

It does look like fennel-ls is highlighting the definition or import of the macro rather than the call. This seems like a bug if fennel-ls rather than a bug in the compiler.

Let me know if I'm misunderstanding; if you can find a case where the compiler highlight is wrong I can reinvestigate!

Register here or Log in to comment, or comment via email.