Skip to content

Commit

Permalink
Extract project file tracking into function
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Aug 27, 2024
1 parent 0da181a commit 05259e1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 56 deletions.
33 changes: 1 addition & 32 deletions src/requests/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,38 +245,7 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
end
end

# Add project files separately in case they are not in a workspace folder
if server.env_path != ""
for file in ["Project.toml", "JuliaProject.toml", "Manifest.toml", "JuliaManifest.toml"]
file_full_path = joinpath(server.env_path, file)
uri = filepath2uri(file_full_path)
if isfile(file_full_path)
@static if Sys.iswindows()
# Normalize drive letter to lowercase
if length(file_full_path) > 1 && isletter(file_full_path[1]) && file_full_path[2] == ':'
file_full_path = lowercasefirst(file_full_path)
end
end
# Only add again if outside of the workspace folders
if all(i->!startswith(file_full_path, i), server.workspaceFolders)
if haskey(server._files_from_disc, uri)
error("This should not happen")
end

text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true)
text_file === nothing && continue

server._files_from_disc[uri] = text_file

if !haskey(server._open_file_versions, uri)
JuliaWorkspaces.add_file!(server.workspace, text_file)
end
end
# But we do want to track, in case the workspace folder is removed
push!(server._extra_tracked_files, filepath2uri(file_full_path))
end
end
end
track_project_files!(server)

Check warning on line 248 in src/requests/init.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/init.jl#L248

Added line #L248 was not covered by tests

JuliaWorkspaces.set_input_fallback_test_project!(server.workspace.runtime, isempty(server.env_path) ? nothing : filepath2uri(server.env_path))

Expand Down
59 changes: 35 additions & 24 deletions src/requests/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,49 @@ function julia_activateenvironment_notification(params::NamedTuple{(:envPath,),T

empty!(server._extra_tracked_files)

# Add project files separately in case they are not in a workspace folder
if server.env_path != ""
for file in ["Project.toml", "JuliaProject.toml", "Manifest.toml", "JuliaManifest.toml"]
file_full_path = joinpath(server.env_path, file)
uri = filepath2uri(file_full_path)
if isfile(file_full_path)
# Only add again if outside of the workspace folders
if all(i->!startswith(file_full_path, i), server.workspaceFolders)
if haskey(server._files_from_disc, uri)
error("This should not happen")
end
track_project_files!(server)

Check warning on line 85 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L85

Added line #L85 was not covered by tests

text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true)
text_file===nothing || continue
JuliaWorkspaces.set_input_fallback_test_project!(server.workspace.runtime, isempty(server.env_path) ? nothing : filepath2uri(server.env_path))

Check warning on line 87 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L87

Added line #L87 was not covered by tests

server._files_from_disc[uri] = text_file
# We call this here to remove project and manifest files that were not in the workspace
gc_files_from_workspace(server)

Check warning on line 90 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L90

Added line #L90 was not covered by tests

if !haskey(server._open_file_versions, uri)
JuliaWorkspaces.add_file!(server.workspace, text_file)
end
trigger_symbolstore_reload(server)

Check warning on line 92 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L92

Added line #L92 was not covered by tests
end
end

function track_project_files!(server::LanguageServerInstance)

Check warning on line 96 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L96

Added line #L96 was not covered by tests
# Add project files separately in case they are not in a workspace folder
if server.env_path != ""
for file in ["Project.toml", "JuliaProject.toml", "Manifest.toml", "JuliaManifest.toml"]
file_full_path = joinpath(server.env_path, file)
uri = filepath2uri(file_full_path)
if isfile(file_full_path)
@static if Sys.iswindows()

Check warning on line 103 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L98-L103

Added lines #L98 - L103 were not covered by tests
# Normalize drive letter to lowercase
if length(file_full_path) > 1 && isletter(file_full_path[1]) && file_full_path[2] == ':'
file_full_path = lowercasefirst(file_full_path)

Check warning on line 106 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L105-L106

Added lines #L105 - L106 were not covered by tests
end
push!(server._extra_tracked_files, filepath2uri(file_full_path))
end
end
end
# Only add again if outside of the workspace folders
if all(i->!startswith(file_full_path, i), server.workspaceFolders)
if haskey(server._files_from_disc, uri)
error("This should not happen")

Check warning on line 112 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L110-L112

Added lines #L110 - L112 were not covered by tests
end

JuliaWorkspaces.set_input_fallback_test_project!(server.workspace.runtime, isempty(server.env_path) ? nothing : filepath2uri(server.env_path))
text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true)
text_file === nothing && continue

Check warning on line 116 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L115-L116

Added lines #L115 - L116 were not covered by tests

# We call this here to remove project and manifest files that were not in the workspace
gc_files_from_workspace(server)
server._files_from_disc[uri] = text_file

Check warning on line 118 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L118

Added line #L118 was not covered by tests

trigger_symbolstore_reload(server)
if !haskey(server._open_file_versions, uri)
JuliaWorkspaces.add_file!(server.workspace, text_file)

Check warning on line 121 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L120-L121

Added lines #L120 - L121 were not covered by tests
end
end
# But we do want to track, in case the workspace folder is removed
push!(server._extra_tracked_files, filepath2uri(file_full_path))

Check warning on line 125 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L125

Added line #L125 was not covered by tests
end
end

Check warning on line 127 in src/requests/misc.jl

View check run for this annotation

Codecov / codecov/patch

src/requests/misc.jl#L127

Added line #L127 was not covered by tests
end
end

Expand Down

0 comments on commit 05259e1

Please sign in to comment.