Skip to content

Detect when evaluated by JETLS #641

Description

@EdsterG

Pre-submission checklist

Description

I'ld like to write code that looks like this:

macro add_definition(fn)
    def = ExprTools.splitdef(fn)
    name = def[:name]
    if isdefined(MyMacros, name) && !IS_JETLS_LOADED[])
        # Forbid overwriting macros when not evaluated by JETLS.
        error(name, " macro already defined, cannot redefine")
    end
    ...
end

For Revise I can do something like this:

IS_REVISE_LOADED::ScopedValue{Bool} = ScopedValue(false)

function __init__()
    if haskey(Base.loaded_modules,
              Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise"))
        global IS_REVISE_LOADED = ScopedValue(true)
    end
end

but this pattern doesn't seem to work for JETLS.

Is there any way to identify from within a macro whether or not it's currently being evaluated by JETLS?

Additional context (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions