From d1dbf040af4be0f305971153b30d6100eef36147 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Sat, 17 Jun 2023 11:06:06 +0100 Subject: [PATCH] Remove warnings when descending automatically in vscode --- src/codeview.jl | 43 +++++++++++++++++++++++++++---------------- src/reflection.jl | 7 ------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/codeview.jl b/src/codeview.jl index fa8705b6..fca635dc 100644 --- a/src/codeview.jl +++ b/src/codeview.jl @@ -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 @@ -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) diff --git a/src/reflection.jl b/src/reflection.jl index c17b61ce..bbbcfeb9 100644 --- a/src/reflection.jl +++ b/src/reflection.jl @@ -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