From bad360d7db854cf2a8b8e03d67352178592e8c2a Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Wed, 28 Aug 2024 14:39:57 +0200 Subject: [PATCH 1/2] Copy project files tracking code into function --- src/requests/misc.jl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/requests/misc.jl b/src/requests/misc.jl index 054f3b18..3052381f 100644 --- a/src/requests/misc.jl +++ b/src/requests/misc.jl @@ -117,6 +117,41 @@ function julia_activateenvironment_notification(params::NamedTuple{(:envPath,),T end end +function track_project_files!(server::LanguageServerInstance) + # 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 +end + julia_refreshLanguageServer_notification(_, server::LanguageServerInstance, conn) = trigger_symbolstore_reload(server) From 6a66fb9c48945a5e435872f6ccfd9c271d4c35f7 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Wed, 28 Aug 2024 14:43:14 +0200 Subject: [PATCH 2/2] Substitute by function calls --- src/requests/init.jl | 33 +-------------------------------- src/requests/misc.jl | 26 +------------------------- 2 files changed, 2 insertions(+), 57 deletions(-) diff --git a/src/requests/init.jl b/src/requests/init.jl index 7e845f3e..062604b8 100644 --- a/src/requests/init.jl +++ b/src/requests/init.jl @@ -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) JuliaWorkspaces.set_input_fallback_test_project!(server.workspace.runtime, isempty(server.env_path) ? nothing : filepath2uri(server.env_path)) diff --git a/src/requests/misc.jl b/src/requests/misc.jl index 3052381f..5dc7175b 100644 --- a/src/requests/misc.jl +++ b/src/requests/misc.jl @@ -82,31 +82,7 @@ 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 - - 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 - push!(server._extra_tracked_files, filepath2uri(file_full_path)) - end - end - end + track_project_files!(server) JuliaWorkspaces.set_input_fallback_test_project!(server.workspace.runtime, isempty(server.env_path) ? nothing : filepath2uri(server.env_path))