Skip to content

Commit f2d1eec

Browse files
committed
Add a show method for PkgFiles and update the README
1 parent 51dfd33 commit f2d1eec

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
CodeTracking is a minimal package designed to work with (a future version of)
44
[Revise.jl](https://github.com/timholy/Revise.jl).
5-
Its main purpose is to support packages that need to know the location
6-
(file and line number) of code that might move around as it's edited.
5+
Its main purpose is to support packages that need to interact with code that might move
6+
around as it's edited.
77

88
CodeTracking is a very lightweight dependency.
99

@@ -23,6 +23,29 @@ In this (ficticious) example, `sum` moved because I deleted a few lines higher i
2323
these didn't affect the functionality of `sum` (so we didn't need to redefine and recompile it),
2424
but it does change the starting line number of the file at which this method appears.
2525

26+
Other features:
27+
28+
```julia
29+
julia> using CodeTracking, ColorTypes
30+
31+
julia> pkgfiles(ColorTypes)
32+
PkgFiles(ColorTypes [3da002f7-5984-5a60-b8a6-cbb66c0b333f]):
33+
basedir: /home/tim/.julia/packages/ColorTypes/BsAWO
34+
files: ["src/ColorTypes.jl", "src/types.jl", "src/traits.jl", "src/conversions.jl", "src/show.jl", "src/operations.jl"]
35+
36+
julia> m = @which red(RGB(1,1,1))
37+
red(c::AbstractRGB) in ColorTypes at /home/tim/.julia/packages/ColorTypes/BsAWO/src/traits.jl:14
38+
39+
julia> definition(m)
40+
:(red(c::AbstractRGB) = begin
41+
#= /home/tim/.julia/packages/ColorTypes/BsAWO/src/traits.jl:14 =#
42+
c.r
43+
end)
44+
45+
julia> definition(m, String)
46+
"red(c::AbstractRGB ) = c.r\n"
47+
```
48+
2649
## A few details
2750

2851
CodeTracking won't do anything *useful* unless the user is also running Revise,
@@ -32,15 +55,12 @@ file/line info in the method itself if Revise isn't running.)
3255

3356
However, Revise is a fairly large (and fairly complex) package, and currently it's not
3457
easy to discover how to extract particular kinds of information from its internal storage.
35-
CodeTracking will be designed to be the new "query" part of Revise.jl.
58+
CodeTracking is designed to be the new "query" part of Revise.jl.
3659
The aim is to have a very simple API that developers can learn in a few minutes and then
3760
incorporate into their own packages; its lightweight nature means that they potentially gain
3861
a lot of functionality without being forced to take a big hit in startup time.
3962

40-
## Current state
63+
## Status
4164

42-
Currently this package is just a stub---it doesn't do anything useful,
43-
but neither should it hurt anything.
44-
Candidate users may wish to start `import`ing it and then file issues
45-
or submit PRs as they discover what kinds of functionality they need
46-
from CodeTracking.
65+
If you want CodeTracking to do anything useful, currently you have to check out the `teh/codetracking`
66+
branch of Revise.

src/CodeTracking.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module CodeTracking
33
using Base: PkgId
44
using Core: LineInfoNode
55

6+
export PkgFiles
67
export whereis, definition, pkgfiles
78

89
include("data.jl")

src/data.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ Base.PkgId(info::PkgFiles) = info.id
2626
srcfiles(info::PkgFiles) = info.files
2727
basedir(info::PkgFiles) = info.basedir
2828

29+
function Base.show(io::IO, info::PkgFiles)
30+
println(io, "PkgFiles(", info.id, "):")
31+
println(io, " basedir: ", info.basedir)
32+
print(io, " files: ")
33+
show(io, info.files)
34+
end
35+
2936
const method_locations = IdDict{Type,LineInfoNode}()
3037

3138
const method_definitions = IdDict{Type,Expr}()

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ include("script.jl")
2020
f2(x, y) = x + y
2121
"""
2222

23-
info = CodeTracking.PkgFiles(Base.PkgId(CodeTracking))
23+
info = PkgFiles(Base.PkgId(CodeTracking))
2424
@test Base.PkgId(info) === info.id
2525
@test CodeTracking.basedir(info) == dirname(@__DIR__)
26+
27+
io = IOBuffer()
28+
show(io, info)
29+
str = String(take!(io))
30+
@test startswith(str, "PkgFiles(CodeTracking [da1fd8a2-8d9e-5ec2-8556-3022fb5608a2]):\n basedir:")
2631
end

0 commit comments

Comments
 (0)