@@ -266,6 +266,35 @@ function strip_indexing(x, inside::Bool=false)
266
266
end
267
267
end
268
268
269
+ " Module so I don't pollute the whole ExpressionExplorer scope"
270
+ module MacroHasSpecialHeuristicInside
271
+ import ... Pluto
272
+ import .. ExpressionExplorer, .. SymbolsState
273
+
274
+ """
275
+ Uses `cell_precedence_heuristic` to determine if we need to include the contents of this macro in the symstate.
276
+ This helps with things like a Pkg.activate() that's in a macro, so Pluto still understands to disable nbpkg.
277
+ """
278
+ function macro_has_special_heuristic_inside (; symstate:: SymbolsState , expr:: Expr ):: Bool
279
+ # Also, because I'm lazy and don't want to copy any code, imma use cell_precedence_heuristic here.
280
+ # Sad part is, that this will also include other symbols used in this macro... but come'on
281
+ local fake_cell = Pluto. Cell ()
282
+ local fake_reactive_node = Pluto. ReactiveNode (symstate)
283
+ local fake_expranalysiscache = Pluto. ExprAnalysisCache (
284
+ parsedcode= expr,
285
+ module_usings_imports= ExpressionExplorer. compute_usings_imports (expr),
286
+ )
287
+ local fake_topology = Pluto. NotebookTopology (
288
+ nodes= Pluto. DefaultDict (Pluto. ReactiveNode, Dict (fake_cell => fake_reactive_node)),
289
+ codes= Pluto. DefaultDict (Pluto. ExprAnalysisCache, Dict (fake_cell => fake_expranalysiscache))
290
+ )
291
+
292
+ return Pluto. cell_precedence_heuristic (fake_topology, fake_cell) < 8
293
+ end
294
+ # Having written this... I know I said I was lazy... I was wrong
295
+ end
296
+
297
+
269
298
# ##
270
299
# MAIN RECURSIVE FUNCTION
271
300
# ##
@@ -381,7 +410,16 @@ function explore!(ex::Expr, scopestate::ScopeState)::SymbolsState
381
410
# "You should make a new function for that" they said, knowing I would take the lazy route.
382
411
for arg in ex. args[begin + 1 : end ]
383
412
macro_symstate = explore! (arg, ScopeState ())
384
- union! (symstate, SymbolsState (macrocalls= macro_symstate. macrocalls))
413
+
414
+ # Also, when this macro has something special inside like `Pkg.activate()`,
415
+ # we're going to treat it as normal code (so these heuristics trigger later)
416
+ # (Might want to also not let this to @eval macro, as an extra escape hatch if you
417
+ # really don't want pluto to see your Pkg.activate() call)
418
+ if arg isa Expr && MacroHasSpecialHeuristicInside. macro_has_special_heuristic_inside (symstate= macro_symstate, expr= arg)
419
+ union! (symstate, macro_symstate)
420
+ else
421
+ union! (symstate, SymbolsState (macrocalls= macro_symstate. macrocalls))
422
+ end
385
423
end
386
424
387
425
# Some macros can be expanded on the server process
0 commit comments