CodeTracking.CodeTracking
— ModuleCodeTracking can be thought of as an extension of InteractiveUtils, and pairs well with Revise.jl.
code_string
,@code_string
: fetch the source code (as a string) for a method definitioncode_expr
,@code_expr
: fetch the expression for a method definitiondefinition
: a lower-level variant of the abovepkgfiles
: return information about the source files that define a packagewhereis
: Return location information about methods (with Revise, it updates as you edit files)signatures_at
: return the signatures of all methods whose definition spans the specified location
CodeTracking.PkgFiles
— TypePkgFiles encodes information about the current location of a package. Fields:
id
: thePkgId
of the packagebasedir
: the current base directory of the packagefiles
: a list of files (relative path tobasedir
) that define the package.
Note that basedir
may be subsequently updated by Pkg operations such as add
and dev
.
CodeTracking.code_expr
— Methodcode_expr(f, types)
Returns the expression for the method definition for f
with the specified types.
May return nothing
if Revise isn't loaded. In such cases, calling Meta.parse(code_string(f, types))
can sometimes be an alternative.
CodeTracking.code_string
— Methodcode_string(f, types)
Returns the code-string for the method definition for f
with the specified types.
CodeTracking.definition
— Methodex = definition(Expr, method::Method)
ex = definition(method::Method)
Return an expression that defines method
. If the definition can't be found, returns nothing
.
See also code_expr
.
CodeTracking.definition
— Methodsrc, line1 = definition(String, method::Method)
Return a string with the code that defines method
. Also return the first line of the definition, including the signature (which may not be the same line number returned by whereis
). If the method can't be located (line number 0), then definition
instead returns nothing.
Note this may not be terribly useful for methods that are defined inside @eval
statements; see definition(Expr, method::Method)
instead.
See also code_string
.
CodeTracking.maybe_fix_path
— Methodpath = maybe_fix_path(path)
Return a normalized, absolute path for a source file path
.
CodeTracking.maybe_fixup_stdlib_path
— Methodpath = maybe_fixup_stdlib_path(path::String)
Return path
corrected for julia issue #26314 if applicable. Otherwise, return the input path
unchanged.
Due to the issue mentioned above, location info for methods defined one of Julia's standard libraries are, for non source Julia builds, given as absolute paths on the worker that built the julia
executable. This function corrects such a path to instead refer to the local path on the users drive.
CodeTracking.pkgfiles
— Methodinfo = pkgfiles(name::AbstractString)
info = pkgfiles(name::AbstractString, uuid::UUID)
Return a CodeTracking.PkgFiles
structure with information about the files that define the package specified by name
and uuid
. Returns nothing
if this package has not been loaded.
CodeTracking.pkgfiles
— Methodinfo = pkgfiles(mod::Module)
Return a CodeTracking.PkgFiles
structure with information about the files that were loaded to define the package that defined mod
.
CodeTracking.signatures_at
— Methodsigs = signatures_at(filename, line)
Return the signatures of all methods whose definition spans the specified location. Prior to Julia 1.5, line
must correspond to a line in the method body (not the signature or final end
).
Returns nothing
if there are no methods at that location.
CodeTracking.signatures_at
— Methodsigs = signatures_at(mod::Module, relativepath, line)
For a package that defines module mod
, return the signatures of all methods whose definition spans the specified location. relativepath
indicates the path of the file relative to the packages top-level directory, e.g., "src/utils.jl"
. line
must correspond to a line in the method body (not the signature or final end
).
Returns nothing
if there are no methods at that location.
CodeTracking.src_from_file_or_REPL
— Methodsrc = src_from_file_or_REPL(origin::AbstractString, repl = Base.active_repl)
Read the source for a function from origin
, which is either the name of a file or "REPL[i]", where i
is an integer specifying the particular history entry. Methods defined at the REPL use strings of this form in their file
field.
If you happen to have a file where the name matches REPL[$i]
, first pass it through abspath
.
CodeTracking.whereis
— Methodfilepath, line = whereis(lineinfo, method::Method)
Return the file and line number associated with a specific statement in method
. lineinfo.line
should contain the line number of the statement at the time method
was compiled. The current location is returned.
CodeTracking.whereis
— Methodloc = whereis(sf::StackFrame)
Return location information for a single frame of a stack trace. If sf
corresponds to a frame that was inlined, loc
will be nothing
. Otherwise loc
will be (filepath, line)
.
CodeTracking.whereis
— Methodfilepath, line = whereis(method::Method)
Return the file and line of the definition of method
. The meaning of line
depends on the Julia version: on Julia 1.5 and higher it is the line number of the method declaration, otherwise it is the first line of the method's body.