Skip to content

Commit

Permalink
🔧 Fix annoying JuliaLS spitting numerous incorrect "missing refs" lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
iago-lito committed Oct 24, 2024
1 parent bc0f941 commit 5e7c75e
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 77 deletions.
1 change: 1 addition & 0 deletions src/AliasingDicts/AliasingDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ end
function Base.showerror(io::IO, e::AliasingError)
print(io, "In aliasing system for $(repr(e.name)): $(e.message)")
end
export AliasingError

# Useful APIs can be crafted out of nesting two aliased dicts together.
include("./nested_2D_api.jl")
Expand Down
3 changes: 1 addition & 2 deletions src/components/allometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
# This file just provides utils to deal with allometric parameters..
# ..based on the following allometry API.
include("./allometry_api.jl")
include("./allometry_identifiers.jl")
using .AllometryApi
# (reassure JuliaLS)
(false) && (local MetabolicClassDict, AliasingError, Allometry, parse_allometry_arguments)

# Check the given parameters against a template (typically a default value)
# so as to reject missing or unexpected values.
Expand Down
17 changes: 1 addition & 16 deletions src/components/allometry_api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,7 @@
module AllometryApi

using ..AliasingDicts

# (reassure JuliaLS)
#! format: off
if (false)
(local
AllometricParametersDict,
Allometry,
AllometryDict,
MetabolicClassDict,
parse_allometric_parameter_for_metabolic_class,
parse_allometry_arguments,
parse_metabolic_class_for_allometric_parameter,

var"")
end
#! format: on
include("./allometry_identifiers.jl")

# Convenience shorter aliases.
@aliasing_dict(
Expand Down
19 changes: 19 additions & 0 deletions src/components/allometry_identifiers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# JuliaLS incorrectly spits "missing refs" lints wrt generated allometry api identifiers.
# Include this no-op file to fix these lints where needed.

#! format: off
@static if (false)
include("../AliasingDicts/AliasingDicts.jl")
using .AliasingDicts
(local
AllometricParametersDict,
Allometry,
AllometryDict,
MetabolicClassDict,
parse_allometric_parameter_for_metabolic_class,
parse_allometry_arguments,
parse_metabolic_class_for_allometric_parameter,

var"")
end
#! format: on
55 changes: 9 additions & 46 deletions src/components/blueprint_modules.jl
Original file line number Diff line number Diff line change
@@ -1,58 +1,21 @@
# Factorize numerous imports useful within the blueprint submodules.
# To be `include`d from these modules.

include("./macros_keywords.jl")

# Reassure JuliaLS.
#! format: off
if (false)
(local
Species, _Species,
Foodweb, _Foodweb,

# Not found for some reason?
MetabolicClassDict,
AliasingError,

var"")
end
#! format: on

# TODO: These are mostly useless, except for JuliaLS.. ? :(
using SparseArrays
using EcologicalNetworksDynamics
const EN = EcologicalNetworksDynamics
const F = EcologicalNetworksDynamics.Framework
import EcologicalNetworksDynamics:
AliasingDicts,
Allometry,
BinAdjacency,
Blueprint,
Brought,
EcologicalNetworksDynamics,
F,
Internal,
Internals,
MetabolicClassDict,
SparseMatrix,
SparseVector,
Topologies,
check_template,
imap,
parse_allometry_arguments,
refs,
refspace,
sparse_nodes_allometry,
to_dense_vector,
to_size,
to_sparse_matrix,
to_sparse_vector,
to_template,
@GraphData,
@check_list_refs,
@check_size,
@check_symbol,
@check_template,
@expand_symbol,
@get,
@ref,
@set,
@tographdata
import .F: checkfails, checkrefails, @blueprint
import .AliasingDicts: AliasingError
@ref
import .F: @blueprint, checkfails, Brought, checkrefails
using .EN.AliasingDicts
using .EN.AllometryApi
using .EN.GraphDataInputs
19 changes: 19 additions & 0 deletions src/components/blueprint_modules_identifiers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Stupid shenanigans to trick JuliaLS into correctly finding references.
# and not clutter further code with "missing reference" warnings.
# All this code does nothing when actually executed.
# Its sole purpose is to solve these incorrect lints.

include("./macros_keywords.jl")

# https://discourse.julialang.org/t/lsp-missing-reference-woes/98231/11?u=iago-lito
@static if (false)
include("../GraphDataInputs/GraphDataInputs.jl")
using .GraphDataInputs
end

@static if (false)
include("../AliasingDicts/AliasingDicts.jl")
using .AliasingDicts
end

include("./allometry_identifiers.jl")
1 change: 1 addition & 0 deletions src/components/body_mass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

module BM
include("blueprint_modules.jl")
include("blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics: _Species, Species, _Foodweb, Foodweb

#-------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/components/foodweb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

module FoodwebBlueprints
include("blueprint_modules.jl")
import .EcologicalNetworksDynamics: _Species, Species
include("blueprint_modules_identifiers.jl")
import .EN: _Species, Species

#-------------------------------------------------------------------------------------------
# From matrix.
Expand Down
28 changes: 16 additions & 12 deletions src/components/growth_rate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
# (reassure JuliaLS)
(false) && (local GrowthRate, _GrowthRate)

# HERE: test after fixing JuliaLS.

# ==========================================================================================
# Blueprints.

module GR
include("blueprint_modules.jl")
include("blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics:
Species, _Species, BodyMass, MetabolicClass, _Temperature

Expand Down Expand Up @@ -111,12 +114,10 @@ end
@blueprint Allometric "allometric rates" depends(BodyMass, MetabolicClass)
export Allometric

F.early_check(bp::Allometric) = check_template(
:allometry,
bp.allometry,
miele2019_growth_allometry_rates(),
"growth rates",
)
function F.early_check(bp::Allometric)
(; allometry) = bp
@check_template allometry miele2019_growth_allometry_rates() "growth rates"
end

function F.expand!(raw, bp::Allometric)
M = @ref raw.M
Expand Down Expand Up @@ -149,12 +150,15 @@ end
)
export Temperature

F.early_check(bp::Temperature) = check_template(
:allometry,
bp.allometry,
binzer2016_growth_allometry_rates(),
"growth rates (from temperature)",
)
function F.early_check(bp::Temperature)
(; allometry) = bp
@check_template(
allometry,
binzer2016_growth_allometry_rates(),
"growth rates (from temperature)",
)
end

function F.expand!(raw, bp::Temperature)
(; E_a) = bp
T = @get raw.T
Expand Down
2 changes: 2 additions & 0 deletions src/components/metabolic_class.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

module MC
include("blueprint_modules.jl")
include("./blueprint_modules_identifiers.jl")
import .EcologicalNetworksDynamics: Species, _Species, Foodweb, _Foodweb
include("./allometry_identifiers.jl")

#-------------------------------------------------------------------------------------------
# From raw values.
Expand Down

0 comments on commit 5e7c75e

Please sign in to comment.