Skip to content

Commit 05259e1

Browse files
committed
Extract project file tracking into function
1 parent 0da181a commit 05259e1

File tree

2 files changed

+36
-56
lines changed

2 files changed

+36
-56
lines changed

src/requests/init.jl

+1-32
Original file line numberDiff line numberDiff line change
@@ -245,38 +245,7 @@ function initialized_notification(params::InitializedParams, server::LanguageSer
245245
end
246246
end
247247

248-
# Add project files separately in case they are not in a workspace folder
249-
if server.env_path != ""
250-
for file in ["Project.toml", "JuliaProject.toml", "Manifest.toml", "JuliaManifest.toml"]
251-
file_full_path = joinpath(server.env_path, file)
252-
uri = filepath2uri(file_full_path)
253-
if isfile(file_full_path)
254-
@static if Sys.iswindows()
255-
# Normalize drive letter to lowercase
256-
if length(file_full_path) > 1 && isletter(file_full_path[1]) && file_full_path[2] == ':'
257-
file_full_path = lowercasefirst(file_full_path)
258-
end
259-
end
260-
# Only add again if outside of the workspace folders
261-
if all(i->!startswith(file_full_path, i), server.workspaceFolders)
262-
if haskey(server._files_from_disc, uri)
263-
error("This should not happen")
264-
end
265-
266-
text_file = JuliaWorkspaces.read_text_file_from_uri(uri, return_nothing_on_io_error=true)
267-
text_file === nothing && continue
268-
269-
server._files_from_disc[uri] = text_file
270-
271-
if !haskey(server._open_file_versions, uri)
272-
JuliaWorkspaces.add_file!(server.workspace, text_file)
273-
end
274-
end
275-
# But we do want to track, in case the workspace folder is removed
276-
push!(server._extra_tracked_files, filepath2uri(file_full_path))
277-
end
278-
end
279-
end
248+
track_project_files!(server)
280249

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

src/requests/misc.jl

+35-24
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,49 @@ function julia_activateenvironment_notification(params::NamedTuple{(:envPath,),T
8282

8383
empty!(server._extra_tracked_files)
8484

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

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

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

102-
if !haskey(server._open_file_versions, uri)
103-
JuliaWorkspaces.add_file!(server.workspace, text_file)
104-
end
92+
trigger_symbolstore_reload(server)
93+
end
94+
end
95+
96+
function track_project_files!(server::LanguageServerInstance)
97+
# Add project files separately in case they are not in a workspace folder
98+
if server.env_path != ""
99+
for file in ["Project.toml", "JuliaProject.toml", "Manifest.toml", "JuliaManifest.toml"]
100+
file_full_path = joinpath(server.env_path, file)
101+
uri = filepath2uri(file_full_path)
102+
if isfile(file_full_path)
103+
@static if Sys.iswindows()
104+
# Normalize drive letter to lowercase
105+
if length(file_full_path) > 1 && isletter(file_full_path[1]) && file_full_path[2] == ':'
106+
file_full_path = lowercasefirst(file_full_path)
105107
end
106-
push!(server._extra_tracked_files, filepath2uri(file_full_path))
107108
end
108-
end
109-
end
109+
# Only add again if outside of the workspace folders
110+
if all(i->!startswith(file_full_path, i), server.workspaceFolders)
111+
if haskey(server._files_from_disc, uri)
112+
error("This should not happen")
113+
end
110114

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

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

116-
trigger_symbolstore_reload(server)
120+
if !haskey(server._open_file_versions, uri)
121+
JuliaWorkspaces.add_file!(server.workspace, text_file)
122+
end
123+
end
124+
# But we do want to track, in case the workspace folder is removed
125+
push!(server._extra_tracked_files, filepath2uri(file_full_path))
126+
end
127+
end
117128
end
118129
end
119130

0 commit comments

Comments
 (0)