# Listing all functions in /src that are directly called by a given function, and vice versa

**URL:** <https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521>\
**Category:** General Usage\
**Tags:** documentation\
**Created:** [December 6, 2024, 12:34am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521 "2024-12-06T00:34:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [December 6, 2024, 12:34am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/1 "2024-12-06T00:34:02Z")

</div>

I manually generated the `See also` section in the docstring below:

```julia
"""
    update_lgTble!(lg_table, comms, idx1, idx2)

Updates the lg_table vector based on game results stored in Comms.

# Arguments
- `lg_table :: MVector{nteams::Int, TeamStats}` : The league table (Place, Team Names, Wins, etc) for this league
- `comms :: Tuple{Comms, Comms}` : Pair of Comms structs containing results of the last game
- `idx1 :: Int` : Index of league table for the home team
- `idx2 :: Int` : Index of league table for the away team

# See also 
- Uses : [`Comms`](@ref)
- Used by : [`playgames!`](@ref)
- Similar : [`init_lgtble`](@ref), [`lgrank!`](@ref)
"""
function update_lgTble!(lg_table, comms, idx1, idx2)
    gls = SVector{2}(sum(comms[1].Gls), sum(comms[2].Gls))
    gdiff = gls[1] - gls[2]
    idx = SVector(idx1, idx2)

    if gdiff == 0
        lg_table[idx1] = @set $(lg_table[idx1]).D += Int16(1)
        lg_table[idx2] = @set $(lg_table[idx2]).D += Int16(1)
    elseif gdiff > 0
        lg_table[idx1] = @set $(lg_table[idx1]).W += Int16(1)
        lg_table[idx2] = @set $(lg_table[idx2]).L += Int16(1)
    else
        lg_table[idx1] = @set $(lg_table[idx1]).L += Int16(1)
        lg_table[idx2] = @set $(lg_table[idx2]).W += Int16(1)
    end

    lg_table[idx1] = @set $(lg_table[idx1]).GA += gls[2]
    lg_table[idx2] = @set $(lg_table[idx2]).GA += gls[1]
    for i in 1:2
        lg_table[idx[i]] = @set $(lg_table[idx[i]]).P += Int16(1)
        lg_table[idx[i]] = @set $(lg_table[idx[i]]).GF += gls[i]
        lg_table[idx[i]] = @set $(lg_table[idx[i]]).GD = lg_table[idx[i]].GF - lg_table[idx[i]].GA
        lg_table[idx[i]] = @set $(lg_table[idx[i]]).Pts = 3*lg_table[idx[i]].W + lg_table[idx[i]].D
    end
end

```

Is there a way to autofill a template like that? I only want to include functions/structs directly called and found in the same `/src` directory. Eg, I wouldn’t expect `Comms` or the `Similar` functions to show up automatically. Then find any other functions that directly call _this_ function.

Bonus, is there a way to autofill the names + types of the `Arguments` section as well?

**Edit**  
Here is another example:

```julia
"""
    TeamStats(Pl, Team, P, W, D, L, GF, GA, GD, Pts)

Immutable struct containing the league table values for a single team.

# Fields
- `Pl :: Int16 ` : Place
- `Team :: String15` : Team Name
- `P :: Int16 ` : Games Played
- `W :: Int16 ` : Wins
- `D :: Int16 ` : Draws
- `L :: Int16 ` : Losses
- `GF :: Int16 ` : Goals For
- `GA :: Int16 ` : Goals Against
- `GD :: Int16 ` : Goal Difference
- `Pts :: Int16 ` : Points (3*W + D)

# See also 
- Used by : [`init_lgtble`](@ref)
"""
@with_kw struct TeamStats
    Pl :: Int16 = 0
    Team :: String15 = ""
    P :: Int16 = 0
    W :: Int16 = 0
    D :: Int16 = 0
    L :: Int16 = 0
    GF :: Int16 = 0
    GA :: Int16 = 0
    GD :: Int16 = 0
    Pts :: Int16 = 0
end

"""
    init_lgtble(teams)

Initializes a league table based on the team names

# Arguments
- `teams :: Vector{String}` : Vector of team names

# See also 
- Uses : [`TeamStats`](@ref)
- Similar : [`update_lgtble!`](@ref), [`lgrank!`](@ref)
"""
function init_lgtble(teams)
    nteams = length(teams)
    lg_table = MVector{nteams}((TeamStats() for i in eachindex(teams)))
    for i in eachindex(lg_table) 
      lg_table[i] = @set $(lg_table[i]).Team = teams[i] 
    end
    return lg_table
end

```

**Edit 2**  
Fixed some copy/paste, etc typos in the docs. But that just kind of proves the point it would be nice to automate this.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [December 6, 2024, 3:31am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/2 "2024-12-06T03:31:43Z")

</div>

Your best bet is probably some coding LLM tool. Your task is too unspecified for other direct tools I think and I am also not aware of anything close to what you ask.

---

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [December 6, 2024, 3:45am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/3 "2024-12-06T03:45:44Z")

</div>

I must have described it poorly then, I don’t see why it would be much harder than eg, syntax highlighting by an editor.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [December 6, 2024, 3:50am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/4 "2024-12-06T03:50:36Z")

</div>

Sorry I somehow missed the specification in between the examples. Then I agree that it is possible in theory, though in practice it will likely require implementing it in the VSCode extension for Julia using the tools of the language server. I don’t think that is done easily. So for a short term solution some coding LLM-based solution is probably close enough to the correct result to be useful and would much quicker to realize.

---

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [December 6, 2024, 6:16am UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/5 "2024-12-06T06:16:25Z")

</div>

Looks like this is close:

> **[VS DocBlockr - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=jeremyljackson.vs-docblock)**
>
> Extension for Visual Studio Code - Manages docblocks with Visual Studio Code

---

<div class="post-metadata">

**Author:** ![Tetrakai](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Post date:** [December 7, 2024, 11:36pm UTC](https://discourse.julialang.org/t/listing-all-functions-in-src-that-are-directly-called-by-a-given-function-and-vice-versa/123521/6 "2024-12-07T23:36:00Z")

</div>

I was able to modify the template here to suit my needs, then use the LSP-Julia package in Sublime Text to quickly list the referencing functions:

> **[GitHub - baggepinnen/AutomaticDocstrings.jl: Automatically generated docstring stubs](https://github.com/baggepinnen/AutomaticDocstrings.jl)**
>
> Automatically generated docstring stubs

It would be nice to auto-fill with a callgraph, but it isn’t too bad.
