Skip to content

Commit

Permalink
Use different version if Revise is tracking proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Feb 19, 2024
1 parent b1849da commit ec4d645
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/ProtoStruct.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@

const revise_uuid = Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe")
const revise_pkgid = Base.PkgId(revise_uuid, "Revise")

function checkrev()
revise_pkgid in keys(Base.loaded_modules) || return false
d = @__DIR__
f = splitpath(@__FILE__)[end]

Check warning on line 8 in src/ProtoStruct.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtoStruct.jl#L7-L8

Added lines #L7 - L8 were not covered by tests

watched_files = getproperty(Base.loaded_modules[revise_pkgid], :watched_files)
d in keys(watched_files) || return false

Check warning on line 11 in src/ProtoStruct.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtoStruct.jl#L10-L11

Added lines #L10 - L11 were not covered by tests

trackedfiles = watched_files[d].trackedfiles
return f in keys(trackedfiles)

Check warning on line 14 in src/ProtoStruct.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtoStruct.jl#L13-L14

Added lines #L13 - L14 were not covered by tests
end

macro proto(expr)
if checkrev()
@eval __module__ $(_proto(expr))
return

Check warning on line 20 in src/ProtoStruct.jl

View check run for this annotation

Codecov / codecov/patch

src/ProtoStruct.jl#L19-L20

Added lines #L19 - L20 were not covered by tests
else
return esc(_proto(expr))
end
end

function _proto(expr)
if expr.head == :macrocall && expr.args[1] == Symbol("@kwdef")
expr = expr.args[3]
end
Expand Down Expand Up @@ -230,6 +254,6 @@ macro proto(expr)
end
end
end
return esc(ex)
return ex
end

0 comments on commit ec4d645

Please sign in to comment.