sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Support macros when analyzer is used as a library

Open davidmorgan opened this issue 1 year ago • 1 comments

I noticed that ContextBuilder currently passes through null macroSupport by default, with no way to provide one. (Unless you cast to ContextBuilderImpl).

So people using the analyzer as a library and using ContextBuilder will currently get no macros.

As discussed we probably want macros to work with some reasonable default settings "out of the box".

So, here is an issue for that :)

davidmorgan avatar Jun 28 '24 09:06 davidmorgan

A hint for anyone else who's trying this: make sure you pass in KernelMacroSupport() and not MacroSupport() :)

Which is a good reminder that we'll have to think about different ways the code could be running.

davidmorgan avatar Jun 28 '24 10:06 davidmorgan

@bwilkerson , @scheglov

keertip avatar Jul 08 '24 13:07 keertip

While I agree that we need this longer term, I think there's work that needs to be done first before we support this kind of usage. Minimally we need to do some API design work.

bwilkerson avatar Jul 08 '24 15:07 bwilkerson

tl;dr we do support macros

People using package:analyzer/dart/analysis/context_builder.dart should migrate to AnalysisContextCollection, which provides default way to run macros.

https://github.com/dart-lang/sdk/blob/5e68eee8c33c55efc687cab3516fa7fef4b2ecd9/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart#L89

In general, ContextBuilder is an older attempt to API, and should be removed.

scheglov avatar Jul 08 '24 19:07 scheglov

Thanks @scheglov, it did occur to me that there are probably multiple ways to set up the analyzer as a library, which might handle macros differently today. That's fine.

For the macros launch do you think it should be / will be the case that all ways to set up the analyzer support macros by default? e.g. do you think ContextBuilder will be removed by then? Thanks.

davidmorgan avatar Jul 15 '24 07:07 davidmorgan