Skip to content

Commit

Permalink
Remove warnings when descending automatically in vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
Zentrik committed Jun 17, 2023
1 parent d1f843b commit d1dbf04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
43 changes: 27 additions & 16 deletions src/codeview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,16 @@ function cthulhu_typed(io::IO, debuginfo::Symbol,
if TypedSyntax.isvscode()
type_hints = Dict{String, Vector{TypedSyntax.InlayHint}}()
warn_diagnostics = TypedSyntax.WarnUnstable[]
descended_mis = Set{Tuple{Symbol, Int}}()

descend_into_callsites!(lambda_io, type_hints, warn_diagnostics, Set{Tuple{Symbol, Int}}(), mi; iswarn, hide_type_stable, optimize, type_annotations, annotate_source, interp)
if istruncated
printstyled(lambda_io, tsn; type_annotations, iswarn, hide_type_stable, idxend, vscode_integration=false)
else
printstyled(lambda_io, tsn, type_hints, warn_diagnostics; type_annotations, iswarn, hide_type_stable, idxend, hide_inlay_types_vscode=true, hide_warn_diagnostics_vscode=true)
push!(descended_mis, (mi.def.file, mi.def.line))
end

descend_into_callsites!(lambda_io, type_hints, warn_diagnostics, descended_mis, mi; iswarn, hide_type_stable, optimize, type_annotations, annotate_source, interp)
if !hide_warn_diagnostics_vscode
display(Main.VSCodeServer.InlineDisplay(false), warn_diagnostics)
end
Expand Down Expand Up @@ -295,23 +303,26 @@ function descend_into_callsites!(io, type_hints, warn_diagnostics, descended_mis
hide_type_stable::Bool=false, optimize::Bool=true,
type_annotations::Bool=true, annotate_source::Bool=false,
interp::AbstractInterpreter=CthulhuInterpreter())
if !isnothing(called_mi) && (mi == called_mi || !occursin(r"REPL.*", string(called_mi.def.file))) && called_mi.def.file == mi.def.file
if (called_mi.def.file, called_mi.def.line) in descended_mis
return nothing
end
tsn, _ = get_typed_sourcetext(called_mi)
if !isnothing(tsn)
sig, body = children(tsn)
# We empty the body when filling kwargs
istruncated = isempty(children(body))
idxend = istruncated ? JuliaSyntax.last_byte(sig) : lastindex(tsn.source)
if !istruncated # If method only fills in default arguments
printstyled(io, tsn, type_hints, warn_diagnostics; type_annotations, iswarn, hide_type_stable, idxend, hide_inlay_types_vscode=true, hide_warn_diagnostics_vscode=true)
push!(descended_mis, (called_mi.def.file, called_mi.def.line))
elseif mi == called_mi
printstyled(io, tsn; type_annotations, iswarn, hide_type_stable, idxend, vscode_integration=false)
if !isnothing(called_mi) && called_mi.def.file == mi.def.file && !occursin(r"REPL.*", string(called_mi.def.file))
# This does prevent us from descending into f with code `map(f, x)`` but it would probably be quite slow to descend into every function in case it calls a function defined in the source file
if mi !== called_mi
if (called_mi.def.file, called_mi.def.line) in descended_mis
return nothing
end

tsn, _ = get_typed_sourcetext(called_mi; warn=false)
if !isnothing(tsn)
sig, body = children(tsn)
# We empty the body when filling kwargs
istruncated = isempty(children(body))
idxend = istruncated ? JuliaSyntax.last_byte(sig) : lastindex(tsn.source)
if !istruncated # If method only fills in default arguments
printstyled(io, tsn, type_hints, warn_diagnostics; type_annotations, iswarn, hide_type_stable, idxend, hide_inlay_types_vscode=true, hide_warn_diagnostics_vscode=true)
push!(descended_mis, (called_mi.def.file, called_mi.def.line))
end
end
end

for callsite in find_callsites(interp, called_mi, optimize, annotate_source)[1]
callsite_mi = callsite.info isa MultiCallInfo ? nothing : get_mi(callsite)
descend_into_callsites!(devnull, type_hints, warn_diagnostics, descended_mis, mi, callsite_mi; iswarn, hide_type_stable, optimize, type_annotations, annotate_source, interp)
Expand Down
7 changes: 0 additions & 7 deletions src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ function find_callsites(interp::AbstractInterpreter, mi::Core.MethodInstance, op
@assert length(src.code) == length(infos)
end

if any(iszero, src.codelocs)
@warn "Some line information is missing, type-assignment may be incomplete"
end
if src.slottypes === nothing
@warn "Inference terminated in an incomplete state due to argument-type changes during recursion"
end

return find_callsites(interp, src, infos, mi, slottypes, optimize & !annotate_source, annotate_source)
end

Expand Down

0 comments on commit d1dbf04

Please sign in to comment.