|
1 | 1 | function textDocument_didOpen_notification(params::DidOpenTextDocumentParams, server::LanguageServerInstance, conn) |
2 | | - JuliaWorkspaces.mark_current_diagnostics(server.workspace) |
3 | | - JuliaWorkspaces.mark_current_testitems(server.workspace) |
| 2 | + marked_versions = mark_current_diagnostics_testitems(server.workspace) |
4 | 3 |
|
5 | 4 | uri = params.textDocument.uri |
6 | 5 | if hasdocument(server, uri) |
@@ -33,16 +32,15 @@ function textDocument_didOpen_notification(params::DidOpenTextDocumentParams, se |
33 | 32 |
|
34 | 33 | parse_all(doc, server) |
35 | 34 | lint!(doc, server) |
36 | | - publish_diagnostics([get_uri(doc)], server, conn, "textDocument_didOpen_notification") |
37 | | - publish_tests(server) |
| 35 | + publish_diagnostics_testitems(server, marked_versions, [get_uri(doc)]) |
38 | 36 | end |
39 | 37 |
|
40 | 38 |
|
41 | 39 | function textDocument_didClose_notification(params::DidCloseTextDocumentParams, server::LanguageServerInstance, conn) |
42 | 40 | uri = params.textDocument.uri |
43 | 41 | doc = getdocument(server, uri) |
44 | 42 |
|
45 | | - JuliaWorkspaces.mark_current_testitems(server.workspace) |
| 43 | + marked_versions = mark_current_diagnostics_testitems(server.workspace) |
46 | 44 |
|
47 | 45 | if is_workspace_file(doc) |
48 | 46 | set_open_in_editor(doc, false) |
@@ -74,7 +72,7 @@ function textDocument_didClose_notification(params::DidCloseTextDocumentParams, |
74 | 72 | JuliaWorkspaces.remove_file!(server.workspace, uri) |
75 | 73 | end |
76 | 74 |
|
77 | | - publish_tests(server) |
| 75 | + publish_diagnostics_testitems(server, marked_versions, JuliaWorkspaces.URIs2.URI[]) |
78 | 76 | end |
79 | 77 |
|
80 | 78 | function textDocument_didSave_notification(params::DidSaveTextDocumentParams, server::LanguageServerInstance, conn) |
@@ -137,8 +135,7 @@ function measure_sub_operation(f, request_name, server) |
137 | 135 | end |
138 | 136 |
|
139 | 137 | function textDocument_didChange_notification(params::DidChangeTextDocumentParams, server::LanguageServerInstance, conn) |
140 | | - JuliaWorkspaces.mark_current_diagnostics(server.workspace) |
141 | | - JuliaWorkspaces.mark_current_testitems(server.workspace) |
| 138 | + marked_versions = mark_current_diagnostics_testitems(server.workspace) |
142 | 139 |
|
143 | 140 | uri = params.textDocument.uri |
144 | 141 |
|
@@ -186,8 +183,7 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams |
186 | 183 | lint!(doc, server) |
187 | 184 | end |
188 | 185 |
|
189 | | - publish_diagnostics([get_uri(doc)], server, conn, "textDocument_didChange_notification") |
190 | | - publish_tests(server) |
| 186 | + publish_diagnostics_testitems(server, marked_versions, [get_uri(doc)]) |
191 | 187 | end |
192 | 188 |
|
193 | 189 | function parse_all(doc::Document, server::LanguageServerInstance) |
@@ -398,97 +394,3 @@ function try_to_load_parents(child_path, server) |
398 | 394 | end |
399 | 395 | end |
400 | 396 | end |
401 | | - |
402 | | -function publish_diagnostics(uris::Vector{URI}, server, conn, source) |
403 | | - jw_diagnostics_updated, jw_diagnostics_deleted = JuliaWorkspaces.get_files_with_updated_diagnostics(server.workspace) |
404 | | - |
405 | | - all_uris_with_updates = Set{URI}() |
406 | | - |
407 | | - for uri in uris |
408 | | - push!(all_uris_with_updates, uri) |
409 | | - end |
410 | | - |
411 | | - for uri in jw_diagnostics_updated |
412 | | - push!(all_uris_with_updates, uri) |
413 | | - end |
414 | | - |
415 | | - diagnostics = Dict{URI,Vector{Diagnostic}}() |
416 | | - |
417 | | - for uri in all_uris_with_updates |
418 | | - diags = Diagnostic[] |
419 | | - diagnostics[uri] = diags |
420 | | - |
421 | | - if hasdocument(server, uri) |
422 | | - doc = getdocument(server, uri) |
423 | | - |
424 | | - if server.runlinter && (is_workspace_file(doc) || isunsavedfile(doc)) |
425 | | - pkgpath = getpath(doc) |
426 | | - if any(is_in_target_dir_of_package.(Ref(pkgpath), server.lint_disableddirs)) |
427 | | - filter!(!is_diag_dependent_on_env, doc.diagnostics) |
428 | | - end |
429 | | - append!(diags, doc.diagnostics) |
430 | | - end |
431 | | - end |
432 | | - |
433 | | - if JuliaWorkspaces.has_file(server.workspace, uri) |
434 | | - st = JuliaWorkspaces.get_text_file(server.workspace, uri).content |
435 | | - |
436 | | - new_diags = JuliaWorkspaces.get_diagnostic(server.workspace, uri) |
437 | | - |
438 | | - append!(diags, Diagnostic( |
439 | | - Range(st, i.range), |
440 | | - if i.severity==:error |
441 | | - DiagnosticSeverities.Error |
442 | | - elseif i.severity==:warning |
443 | | - DiagnosticSeverities.Warning |
444 | | - elseif i.severity==:info |
445 | | - DiagnosticSeverities.Information |
446 | | - else |
447 | | - error("Unknown severity $(i.severity)") |
448 | | - end, |
449 | | - missing, |
450 | | - missing, |
451 | | - i.source, |
452 | | - i.message, |
453 | | - missing, |
454 | | - missing |
455 | | - ) for i in new_diags) |
456 | | - end |
457 | | - end |
458 | | - |
459 | | - for (uri,diags) in diagnostics |
460 | | - version = get(server._open_file_versions, uri, missing) |
461 | | - params = PublishDiagnosticsParams(uri, version, diags) |
462 | | - JSONRPC.send(conn, textDocument_publishDiagnostics_notification_type, params) |
463 | | - end |
464 | | -end |
465 | | - |
466 | | -function publish_tests(server::LanguageServerInstance) |
467 | | - if !ismissing(server.initialization_options) && get(server.initialization_options, "julialangTestItemIdentification", false) |
468 | | - updated_files, deleted_files = JuliaWorkspaces.get_files_with_updated_testitems(server.workspace) |
469 | | - |
470 | | - for uri in updated_files |
471 | | - testitems_results = JuliaWorkspaces.get_test_items(server.workspace, uri) |
472 | | - st = JuliaWorkspaces.get_text_file(server.workspace, uri).content |
473 | | - |
474 | | - testitems = TestItemDetail[TestItemDetail(i.id, i.name, Range(st, i.range), i.code, Range(st, i.code_range), i.option_default_imports, string.(i.option_tags), string.(i.option_setup)) for i in testitems_results.testitems] |
475 | | - testsetups= TestSetupDetail[TestSetupDetail(string(i.name), string(i.kind), Range(st, i.range), i.code, Range(st, i.code_range), ) for i in testitems_results.testsetups] |
476 | | - testerrors = TestErrorDetail[TestErrorDetail(te.id, te.name, Range(st, te.range), te.message) for te in testitems_results.testerrors] |
477 | | - |
478 | | - version = get(server._open_file_versions, uri, missing) |
479 | | - |
480 | | - params = PublishTestsParams( |
481 | | - uri, |
482 | | - version, |
483 | | - testitems, |
484 | | - testsetups, |
485 | | - testerrors |
486 | | - ) |
487 | | - JSONRPC.send(server.jr_endpoint, textDocument_publishTests_notification_type, params) |
488 | | - end |
489 | | - |
490 | | - for uri in deleted_files |
491 | | - JSONRPC.send(server.jr_endpoint, textDocument_publishTests_notification_type, PublishTestsParams(uri, missing, TestItemDetail[], TestSetupDetail[], TestErrorDetail[])) |
492 | | - end |
493 | | - end |
494 | | -end |
0 commit comments