Skip to content

Commit

Permalink
Rearrange code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jul 20, 2024
1 parent fbde895 commit 14ab377
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 164 deletions.
26 changes: 1 addition & 25 deletions src/JuliaWorkspaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,6 @@ using .URIs2: filepath2uri, uri2filepath

using .URIs2: URI, @uri_str

export JuliaWorkspace,
add_file!,
remove_file!,
remove_all_children!,
TextFile, SourceText,
workspace_from_folders,
add_folder_from_disc!,
add_file_from_disc!,
update_file_from_disc!,
get_text_files,
get_julia_files,
has_file,
get_text_file,
get_julia_syntax_tree,
get_toml_syntax_tree,
get_diagnostic,
get_packages,
get_projects,
get_test_items,
get_test_env,
position_at,
TextFile,
SourceText,
Diagnostic

include("exception_types.jl")
include("types.jl")
include("sourcetext.jl")
Expand All @@ -52,5 +27,6 @@ include("layer_projects.jl")
include("layer_testitems.jl")
include("layer_diagnostics.jl")
include("fileio.jl")
include("public.jl")

end
2 changes: 0 additions & 2 deletions src/fileio.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


function our_isvalid(s)
return isvalid(s) && !occursin('\0', s)
end
Expand Down
23 changes: 0 additions & 23 deletions src/layer_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,3 @@ Salsa.@derived function derived_diagnostic_updated_since_mark(rt)

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_all_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, DiagnosticsMark(uuid4(), results))
end

function get_files_with_updated_diagnostics(jw::JuliaWorkspace)
return derived_diagnostic_updated_since_mark(jw.runtime)
end
68 changes: 0 additions & 68 deletions src/layer_files.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
function add_file!(jw::JuliaWorkspace, file::TextFile)
files = input_files(jw.runtime)

file.uri in files && throw(JWDuplicateFile("Duplicate file $(file.uri)"))

new_files = Set{URI}([files...;file.uri])

set_input_files!(jw.runtime, new_files)

set_input_text_file!(jw.runtime, file.uri, file)
end

function update_file!(jw::JuliaWorkspace, file::TextFile)
has_file(jw, file.uri) || throw(JWUnknownFile("Cannot update unknown file $(file.uri)."))

set_input_text_file!(jw.runtime, file.uri, file)
end

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

Expand All @@ -30,58 +12,8 @@ Salsa.@derived function derived_julia_files(rt)
return [file for file in files if endswith(string(file), ".jl")]
end

function get_text_files(jw::JuliaWorkspace)
return derived_text_files(jw.runtime)
end

function get_julia_files(jw::JuliaWorkspace)
return derived_julia_files(jw.runtime)
end

function get_files(jw::JuliaWorkspace)
return input_files(jw.runtime)
end

Salsa.@derived function derived_has_file(rt, uri)
files = input_files(rt)

return uri in files
end

function has_file(jw, uri)
return derived_has_file(jw.runtime, uri)
end

function get_text_file(jw::JuliaWorkspace, uri::URI)
files = input_files(jw.runtime)

uri in files || throw(JWUnknownFile("Unknown file $uri"))

return input_text_file(jw.runtime, uri)
end

function remove_file!(jw::JuliaWorkspace, uri::URI)
files = input_files(jw.runtime)

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

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

set_input_files!(jw.runtime, new_files)

delete_input_text_file!(jw.runtime, uri)
end

function remove_all_children!(jw::JuliaWorkspace, uri::URI)
files = get_files(jw)

uri_as_string = string(uri)

for file in files
file_as_string = string(file)

if startswith(file_as_string, uri_as_string)
remove_file!(jw, file)
end
end
end
8 changes: 0 additions & 8 deletions src/layer_projects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,3 @@ end
Salsa.@derived function derived_project_folders(rt)
return URI[i for i in keys(derived_potential_project_folders(rt)) if derived_project(rt, i)!==nothing]
end

function get_packages(jw::JuliaWorkspace)
return derived_package_folders(jw.runtime)
end

function get_projects(jw::JuliaWorkspace)
return derived_project_folders(jw.runtime)
end
8 changes: 0 additions & 8 deletions src/layer_syntax_trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,3 @@ Salsa.@derived function derived_toml_syntax_diagnostics(rt, uri)

return parse_result[2]
end

function get_julia_syntax_tree(jw::JuliaWorkspace, uri::URI)
return derived_julia_syntax_tree(jw.runtime, uri)
end

function get_toml_syntax_tree(jw::JuliaWorkspace, uri::URI)
return derived_toml_syntax_tree(jw.runtime, uri)
end
18 changes: 0 additions & 18 deletions src/layer_testitems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,3 @@ Salsa.@derived function derived_testitems_updated_since_mark(rt)
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, TestitemsMark(uuid4(), 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
173 changes: 173 additions & 0 deletions src/public.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
export JuliaWorkspace,
add_file!,
remove_file!,
remove_all_children!,
TextFile, SourceText,
workspace_from_folders,
add_folder_from_disc!,
add_file_from_disc!,
update_file_from_disc!,
get_text_files,
get_julia_files,
has_file,
get_text_file,
get_julia_syntax_tree,
get_toml_syntax_tree,
get_diagnostic,
get_packages,
get_projects,
get_test_items,
get_test_env,
position_at,
TextFile,
SourceText,
Diagnostic


# Files

function add_file!(jw::JuliaWorkspace, file::TextFile)
files = input_files(jw.runtime)

file.uri in files && throw(JWDuplicateFile("Duplicate file $(file.uri)"))

new_files = Set{URI}([files...;file.uri])

set_input_files!(jw.runtime, new_files)

set_input_text_file!(jw.runtime, file.uri, file)
end

function update_file!(jw::JuliaWorkspace, file::TextFile)
has_file(jw, file.uri) || throw(JWUnknownFile("Cannot update unknown file $(file.uri)."))

set_input_text_file!(jw.runtime, file.uri, file)
end

function get_text_files(jw::JuliaWorkspace)
return derived_text_files(jw.runtime)
end

function get_julia_files(jw::JuliaWorkspace)
return derived_julia_files(jw.runtime)
end

function get_files(jw::JuliaWorkspace)
return input_files(jw.runtime)
end

function has_file(jw, uri)
return derived_has_file(jw.runtime, uri)
end

function get_text_file(jw::JuliaWorkspace, uri::URI)
files = input_files(jw.runtime)

uri in files || throw(JWUnknownFile("Unknown file $uri"))

return input_text_file(jw.runtime, uri)
end

function remove_file!(jw::JuliaWorkspace, uri::URI)
files = input_files(jw.runtime)

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

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

set_input_files!(jw.runtime, new_files)

delete_input_text_file!(jw.runtime, uri)
end

function remove_all_children!(jw::JuliaWorkspace, uri::URI)
files = get_files(jw)

uri_as_string = string(uri)

for file in files
file_as_string = string(file)

if startswith(file_as_string, uri_as_string)
remove_file!(jw, file)
end
end
end

# Projects

function get_packages(jw::JuliaWorkspace)
return derived_package_folders(jw.runtime)
end

function get_projects(jw::JuliaWorkspace)
return derived_project_folders(jw.runtime)
end

# Syntax trees

function get_julia_syntax_tree(jw::JuliaWorkspace, uri::URI)
return derived_julia_syntax_tree(jw.runtime, uri)
end

function get_toml_syntax_tree(jw::JuliaWorkspace, uri::URI)
return derived_toml_syntax_tree(jw.runtime, uri)
end

# Diagnostics

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

function get_diagnostics(jw::JuliaWorkspace)
return derived_all_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, DiagnosticsMark(uuid4(), results))
end

function get_files_with_updated_diagnostics(jw::JuliaWorkspace)
return derived_diagnostic_updated_since_mark(jw.runtime)
end

# Test items

function get_test_items(jw::JuliaWorkspace, uri::URI)
derived_testitems(jw.runtime, uri)
end

function get_test_items(jw::JuliaWorkspace)
derived_all_testitems(jw.runtime)
end

function get_test_env(jw::JuliaWorkspace, uri::URI)
derived_testenv(jw.runtime, uri)
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, TestitemsMark(uuid4(), 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
12 changes: 0 additions & 12 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,3 @@ struct TestitemsMark
id::UUID
data::Dict{URI,TestDetails}
end

function get_test_items(jw::JuliaWorkspace, uri::URI)
derived_testitems(jw.runtime, uri)
end

function get_test_items(jw::JuliaWorkspace)
derived_all_testitems(jw.runtime)
end

function get_test_env(jw::JuliaWorkspace, uri::URI)
derived_testenv(jw.runtime, uri)
end

0 comments on commit 14ab377

Please sign in to comment.