Skip to content

Commit 606d927

Browse files
aviateskclaude
andauthored
full-analysis: Refactor analysis entry lookup with server-initiated progress (#345)
Split analysis entry lookup into two phases to enable dedicated progress reporting for environment instantiation and analysis. Phase 1 (`lookup_analysis_entry`) performs a non-blocking check that returns: - `AnalysisEntry` directly if no instantiation is needed (cached or no env) - `InstantiationRequest` if instantiation is required - `OutOfScope` if the file is out of analysis scope Phase 2 (`do_instantiation` or `do_instantiation_with_progress`) performs the actual instantiation when needed. This design allows the server to issue separate progress tokens for instantiation and analysis phases, providing users with earlier and more accurate progress feedback. The `InstantiationProgressCaller` is non-cancellable since instantiation cannot be cancelled, while `AnalysisProgressCaller` remains cancellable. Also consolidate the entry point: replace separate `request_analysis_on_open!` and `request_analysis_on_save!` functions with a unified `request_analysis!` that handles both cases via the `onsave` parameter. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1b14614 commit 606d927

File tree

8 files changed

+473
-289
lines changed

8 files changed

+473
-289
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4444
Revise assumes it's loaded from a REPL session. Revise is now a direct
4545
dependency that's conditionally loaded at compile time based on the
4646
`JETLS_DEV_MODE` flag.
47+
- Significantly refactored the full-analysis pipeline implementation. Modified
48+
the full-analysis pipeline behavior to output more detailed logs when
49+
`JETLS_DEV_MODE` is enabled.
4750

4851
## 2025-11-28
4952

src/JETLS.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ struct ResponseMessageDispatcher
331331
end
332332
function (dispatcher::ResponseMessageDispatcher)(server::Server, msg::Dict{Symbol,Any})
333333
(; cancel_flag, request_caller) = dispatcher
334-
if request_caller isa RequestAnalysisCaller
335-
handle_request_analysis_response(server, request_caller, cancel_flag)
334+
if request_caller isa InstantiationProgressCaller
335+
handle_instantiation_progress_response(server, request_caller)
336+
elseif request_caller isa AnalysisProgressCaller
337+
handle_analysis_progress_response(server, request_caller, cancel_flag)
336338
elseif request_caller isa ShowDocumentRequestCaller
337339
handle_show_document_response(server, msg, request_caller)
338340
elseif request_caller isa SetDocumentContentCaller

src/analysis/full-analysis.jl

Lines changed: 401 additions & 282 deletions
Large diffs are not rendered by default.

src/document-synchronization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function handle_DidOpenTextDocumentNotification(server::Server, msg::DidOpenText
5050
update_testsetinfos!(server, uri, fi)
5151
cache_saved_file_info!(server.state, uri, parsed_stream)
5252

53-
request_analysis_on_open!(server, uri)
53+
request_analysis!(server, uri, #=onsave=#false)
5454
end
5555

5656
function handle_DidChangeTextDocumentNotification(server::Server, msg::DidChangeTextDocumentNotification)
@@ -85,7 +85,7 @@ function handle_DidSaveTextDocumentNotification(server::Server, msg::DidSaveText
8585
end
8686
cache_saved_file_info!(server.state, uri, text)
8787

88-
request_analysis_on_save!(server, uri)
88+
request_analysis!(server, uri, #=onsave=#true)
8989
end
9090

9191
function handle_DidCloseTextDocumentNotification(server::Server, msg::DidCloseTextDocumentNotification)

test/test_completions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function with_completion_request(
260260
else
261261
JETLS.cache_file_info!(server.state, uri, 1, clean_code)
262262
JETLS.cache_saved_file_info!(server.state, uri, clean_code)
263-
JETLS.request_analysis!(server, uri; notify_diagnostics=false)
263+
JETLS.request_analysis!(server, uri, #=onsave=#false; wait=true, notify_diagnostics=false)
264264
end
265265

266266
for (i, pos) in enumerate(positions)

test/test_lookup_analysis_entry.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module test_lookup_analysis_entry
2+
3+
using Test
4+
using Pkg
5+
using JETLS
6+
using JETLS: lookup_analysis_entry, ScriptInEnvAnalysisEntry, entryenvpath
7+
using JETLS.URIs2: filepath2uri
8+
9+
@testset "lookup_analysis_entry for docs" begin
10+
mktempdir() do temp_root
11+
proj_dir = joinpath(temp_root, "TestPkg")
12+
mkpath(proj_dir)
13+
env_path = joinpath(proj_dir, "Project.toml")
14+
write(env_path, """
15+
name = "TestPkg"
16+
uuid = "12345678-1234-1234-1234-123456789012"
17+
version = "0.1.0"
18+
""")
19+
20+
src_dir = joinpath(proj_dir, "src")
21+
docs_dir = joinpath(proj_dir, "docs")
22+
mkpath(src_dir)
23+
mkpath(docs_dir)
24+
mkpath(joinpath(docs_dir, "src"))
25+
26+
write(joinpath(src_dir, "TestPkg.jl"), "module TestPkg end")
27+
write(joinpath(docs_dir, "make.jl"), "# docs make script")
28+
29+
# Test docs with docs/Project.toml
30+
let docs_env_path = joinpath(docs_dir, "Project.toml")
31+
write(docs_env_path, """
32+
[deps]
33+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34+
""")
35+
36+
filepath = joinpath(docs_dir, "make.jl")
37+
uri = filepath2uri(filepath)
38+
server = Server()
39+
server.state.root_path = proj_dir
40+
entry = lookup_analysis_entry(server, uri)
41+
@test entry isa ScriptInEnvAnalysisEntry
42+
@test entryenvpath(entry) == docs_env_path
43+
end
44+
45+
# Test docs without docs/Project.toml (falls back to root Project.toml)
46+
let docs_env_path = joinpath(docs_dir, "Project.toml")
47+
rm(docs_env_path; force=true)
48+
49+
filepath = joinpath(docs_dir, "make.jl")
50+
uri = filepath2uri(filepath)
51+
server = Server()
52+
server.state.root_path = proj_dir
53+
entry = lookup_analysis_entry(server, uri)
54+
@test entry isa ScriptInEnvAnalysisEntry
55+
@test entryenvpath(entry) == env_path
56+
end
57+
end
58+
end
59+
60+
end # module test_lookup_analysis_entry

test/test_lowering_diagnostics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ end
310310
withserver() do (; writereadmsg, id_counter, server)
311311
JETLS.cache_file_info!(server.state, uri, 1, script)
312312
JETLS.cache_saved_file_info!(server.state, uri, script)
313-
JETLS.request_analysis!(server, uri; notify_diagnostics=false)
313+
JETLS.request_analysis!(server, uri, #=onsave=#false; wait=true, notify_diagnostics=false)
314314

315315
id = id_counter[] += 1
316316
(; raw_res) = writereadmsg(DocumentDiagnosticRequest(;

test/test_resolver.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function analyze_and_resolve(s::AbstractString; kwargs...)
1414
fileinfo = JETLS.cache_file_info!(state, uri, 1, text)
1515
JETLS.cache_saved_file_info!(state, uri, text)
1616
JETLS.start_analysis_workers!(server)
17-
JETLS.request_analysis!(server, uri; notify_diagnostics=false)
17+
JETLS.request_analysis!(server, uri, #=onsave=#false; wait=true, notify_diagnostics=false)
1818

1919
(; mod, analyzer) = JETLS.get_context_info(state, uri, position)
2020

0 commit comments

Comments
 (0)