Skip to content

Commit

Permalink
Add outdated marking
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jul 19, 2024
1 parent b02ceef commit f3a02bd
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ Salsa.@declare_input input_files(rt)::Set{URI}
Salsa.@declare_input input_text_file(rt, uri)::TextFile
Salsa.@declare_input input_notebook_file(rt, uri)::NotebookFile
Salsa.@declare_input input_fallback_test_project(rt)::Union{URI,Nothing}
Salsa.@declare_input input_marked_diagnostics(rt)::Dict{URI,Vector{Diagnostic}}
Salsa.@declare_input input_marked_testitems(rt)::Dict{URI,TestDetails}
41 changes: 40 additions & 1 deletion src/layer_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,53 @@ Salsa.@derived function derived_diagnostics(rt)
for f in files
append!(results, derived_diagnostics(rt, f))
end

return results
end

Salsa.@derived function derived_diagnostic_updated_since_mark(rt)
marked_versions = input_marked_diagnostics(rt)

old_text_files = keys(marked_versions)
current_text_files = derived_text_files(rt)

deleted_files = setdiff(old_text_files, current_text_files)
updated_files = Set{URI}()

for uri in current_text_files
if !(uri in old_text_files)
push!(updated_files, uri)
else
new_diag = derived_diagnostics(rt, uri)

if hash(marked_versions[uri]) != hash(new_diag)
push!(updated_files, uri)
end
end
end

return updated_files, deleted_files
end

function get_diagnostic(jw::JuliaWorkspace, uri::URI)
return derived_diagnostics(jw.runtime, uri)
end

function get_diagnostics(jw::JuliaWorkspace)
return derived_diagnostics(jw.runtime)
end

function mark_current_diagnostics(jw::JuliaWorkspace)
files = derived_text_files(jw.runtime)

results = Dict{URI,Vector{Diagnostic}}()

for f in files
results[f] = derived_diagnostics(jw.runtime, f)
end
set_input_marked_diagnostics!(jw.runtime, results)
end

function get_files_with_updated_diagnostics(jw::JuliaWorkspace)
return derived_diagnostic_updated_since_mark(jw.runtime)
end
6 changes: 3 additions & 3 deletions src/layer_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Salsa.@derived function derived_text_files(rt)
end

Salsa.@derived function derived_julia_files(rt)
files = input_files(rt)
files = derived_text_files(rt)

# TODO Actually filter this properly
return [file for file in files if endswith(string(file), ".jl")]
Expand Down Expand Up @@ -65,9 +65,9 @@ function remove_file!(jw::JuliaWorkspace, uri::URI)

uri in files || throw(JWUnknownFile("Trying to remove non-existing file $uri"))

pop!(files, uri)
new_files = filter(i->i!=uri, files)

set_input_files!(jw.runtime, files)
set_input_files!(jw.runtime, new_files)

delete_input_text_file!(jw.runtime, uri)
end
Expand Down
51 changes: 47 additions & 4 deletions src/layer_testitems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ Salsa.@derived function derived_testitems(rt, uri)

TestItemDetection.find_test_detail!(syntax_tree, testitems, testsetups, testerrors)

return (
testitems=[TestItemDetail(
return TestDetails(
[TestItemDetail(
uri,
"$uri:$i",
ti.name,
Expand All @@ -74,14 +74,14 @@ Salsa.@derived function derived_testitems(rt, uri)
ti.option_tags,
ti.option_setup
) for (i,ti) in enumerate(testitems)],
testsetups=[TestSetupDetail(
[TestSetupDetail(
uri,
i.name,
i.kind,
i.range,
i.code_range
) for i in testsetups],
testerrors=[TestErrorDetail(
[TestErrorDetail(
uri,
"$uri:error$i",
te.name,
Expand Down Expand Up @@ -139,3 +139,46 @@ Salsa.@derived function derived_testenv(rt, uri)

return JuliaTestEnv(package_name, package_uri, project_uri, env_content_hash)
end

Salsa.@derived function derived_testitems_updated_since_mark(rt)
current_text_files = derived_julia_files(rt)
marked_versions = input_marked_testitems(rt)

old_text_files = collect(keys(marked_versions))

deleted_files = setdiff(old_text_files, current_text_files)
updated_files = Set{URI}()

for uri in current_text_files
if !(uri in old_text_files)
push!(updated_files, uri)
else
new_diag = derived_testitems(rt, uri)

if hash(marked_versions[uri]) != hash(new_diag)
push!(updated_files, uri)
end
end
end

return updated_files, deleted_files
end

function mark_current_testitems(jw::JuliaWorkspace)
files = derived_julia_files(jw.runtime)

results = Dict{URI,TestDetails}()

for f in files
results[f] = derived_testitems(jw.runtime, f)
end

set_input_marked_testitems!(jw.runtime, results)
end

function get_files_with_updated_testitems(jw::JuliaWorkspace)
# @info "get_files_with_updated_testitems" string.(input_files(jw.runtime))
# graph = Salsa.Inspect.build_graph(jw.runtime)
# println(stderr, graph)
return derived_testitems_updated_since_mark(jw.runtime)
end
6 changes: 6 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ end
range::UnitRange{Int}
end

@auto_hash_equals struct TestDetails
testitems::Vector{TestItemDetail}
testsetups::Vector{TestSetupDetail}
testerrors::Vector{TestErrorDetail}
end

@auto_hash_equals struct JuliaPackage
project_file_uri::URI
name::String
Expand Down

0 comments on commit f3a02bd

Please sign in to comment.