@@ -137,12 +137,8 @@ function measure_sub_operation(f, request_name, server)
137137end
138138
139139function textDocument_didChange_notification (params:: DidChangeTextDocumentParams , server:: LanguageServerInstance , conn)
140- measure_sub_operation (" JuliaWorkspaces.mark_current_diagnostics" , server) do
141- JuliaWorkspaces. mark_current_diagnostics (server. workspace)
142- end
143- measure_sub_operation (" JuliaWorkspaces.mark_current_testitems" , server) do
144- JuliaWorkspaces. mark_current_testitems (server. workspace)
145- end
140+ JuliaWorkspaces. mark_current_diagnostics (server. workspace)
141+ JuliaWorkspaces. mark_current_testitems (server. workspace)
146142
147143 uri = params. textDocument. uri
148144
@@ -154,60 +150,44 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams
154150 error (" The client and server have different textDocument versions for $(get_uri (doc)) . LS version is $(get_version (doc)) , request version is $(params. textDocument. version) ." )
155151 end
156152
157- measure_sub_operation (" File edits" , server) do
158- new_text_document = apply_text_edits (get_text_document (doc), params. contentChanges, params. textDocument. version)
159- set_text_document! (doc, new_text_document)
153+ new_text_document = apply_text_edits (get_text_document (doc), params. contentChanges, params. textDocument. version)
154+ set_text_document! (doc, new_text_document)
160155
161- if ! haskey (server. _open_file_versions, uri)
162- error (" This should not happen" )
163- end
164-
165- if server. _open_file_versions[uri]> params. textDocument. version
166- error (" Outdated version: server $(server. _open_file_versions[uri]) params $(params. textDocument. version) " )
167- end
156+ if ! haskey (server. _open_file_versions, uri)
157+ error (" This should not happen" )
158+ end
168159
169- # We originally applied each text edit individually, but that doesn't work because
170- # we need to convert the LS positions to Julia indices after each text edit update
171- # For now we just use the new text that we already created for the legacy TextDocument
172- new_text_file = JuliaWorkspaces. TextFile (uri, JuliaWorkspaces. SourceText (get_text (new_text_document), get_language_id (doc)))
173- JuliaWorkspaces. update_file! (server. workspace, new_text_file)
160+ if server. _open_file_versions[uri]> params. textDocument. version
161+ error (" Outdated version: server $(server. _open_file_versions[uri]) params $(params. textDocument. version) " )
174162 end
175163
164+ # We originally applied each text edit individually, but that doesn't work because
165+ # we need to convert the LS positions to Julia indices after each text edit update
166+ # For now we just use the new text that we already created for the legacy TextDocument
167+ new_text_file = JuliaWorkspaces. TextFile (uri, JuliaWorkspaces. SourceText (get_text (new_text_document), get_language_id (doc)))
168+ JuliaWorkspaces. update_file! (server. workspace, new_text_file)
169+
176170 if get_language_id (doc) in (" markdown" , " juliamarkdown" )
177- measure_sub_operation (" parse_all md" , server) do
178- parse_all (doc, server)
179- end
180- measure_sub_operation (" lint! md" , server) do
181- lint! (doc, server)
182- end
171+ parse_all (doc, server)
172+ lint! (doc, server)
183173 elseif get_language_id (doc) == " julia"
184- measure_sub_operation (" overall tree diff" , server) do
185- cst0, cst1 = getcst (doc), CSTParser. parse (get_text (doc), true )
186- r1, r2, r3 = CSTParser. minimal_reparse (s0, get_text (doc), cst0, cst1, inds = true )
187- for i in setdiff (1 : length (cst0. args), r1 , r3) # clean meta from deleted expr
188- StaticLint. clear_meta (cst0[i])
189- end
190- setcst (doc, EXPR (cst0. head, EXPR[cst0. args[r1]; cst1. args[r2]; cst0. args[r3]], nothing ))
191- sizeof (get_text (doc)) == getcst (doc). fullspan || @error " CST does not match input string length."
192- headof (doc. cst) === :file ? set_doc (doc. cst, doc) : @info " headof(doc) isn't :file for $(doc. _path) "
174+ cst0, cst1 = getcst (doc), CSTParser. parse (get_text (doc), true )
175+ r1, r2, r3 = CSTParser. minimal_reparse (s0, get_text (doc), cst0, cst1, inds = true )
176+ for i in setdiff (1 : length (cst0. args), r1 , r3) # clean meta from deleted expr
177+ StaticLint. clear_meta (cst0[i])
178+ end
179+ setcst (doc, EXPR (cst0. head, EXPR[cst0. args[r1]; cst1. args[r2]; cst0. args[r3]], nothing ))
180+ sizeof (get_text (doc)) == getcst (doc). fullspan || @error " CST does not match input string length."
181+ headof (doc. cst) === :file ? set_doc (doc. cst, doc) : @info " headof(doc) isn't :file for $(doc. _path) "
193182
194- target_exprs = getcst (doc). args[last (r1) .+ (1 : length (r2))]
183+ target_exprs = getcst (doc). args[last (r1) .+ (1 : length (r2))]
195184
196- measure_sub_operation (" semantic_pass" , server) do
197- semantic_pass (getroot (doc), target_exprs)
198- end
199- measure_sub_operation (" lint!" , server) do
200- lint! (doc, server)
201- end
202- end
185+ semantic_pass (getroot (doc), target_exprs)
186+ lint! (doc, server)
203187 end
204188
205- measure_sub_operation (" publish_diagnostics" , server) do
206- publish_diagnostics ([get_uri (doc)], server, conn, " textDocument_didChange_notification" )
207- end
208- measure_sub_operation (" publish_tests" , server) do
209- publish_tests (server)
210- end
189+ publish_diagnostics ([get_uri (doc)], server, conn, " textDocument_didChange_notification" )
190+ publish_tests (server)
211191end
212192
213193function parse_all (doc:: Document , server:: LanguageServerInstance )
@@ -420,9 +400,7 @@ function try_to_load_parents(child_path, server)
420400end
421401
422402function publish_diagnostics (uris:: Vector{URI} , server, conn, source)
423- jw_diagnostics_updated, jw_diagnostics_deleted = measure_sub_operation (" publish_diagnostics - get_files_with_updated_diagnostics" , server) do
424- JuliaWorkspaces. get_files_with_updated_diagnostics (server. workspace)
425- end
403+ JuliaWorkspaces. get_files_with_updated_diagnostics (server. workspace)
426404
427405 all_uris_with_updates = Set {URI} ()
428406
@@ -436,49 +414,45 @@ function publish_diagnostics(uris::Vector{URI}, server, conn, source)
436414
437415 diagnostics = Dict {URI,Vector{Diagnostic}} ()
438416
439- measure_sub_operation (" publish_diagnostics - loop over updates" , server) do
440- for uri in all_uris_with_updates
441- diags = Diagnostic[]
442- diagnostics[uri] = diags
417+ for uri in all_uris_with_updates
418+ diags = Diagnostic[]
419+ diagnostics[uri] = diags
443420
444- if hasdocument (server, uri)
445- doc = getdocument (server, uri)
421+ if hasdocument (server, uri)
422+ doc = getdocument (server, uri)
446423
447- if server. runlinter && (is_workspace_file (doc) || isunsavedfile (doc))
448- pkgpath = getpath (doc)
449- if any (is_in_target_dir_of_package .(Ref (pkgpath), server. lint_disableddirs))
450- filter! (! is_diag_dependent_on_env, doc. diagnostics)
451- end
452- append! (diags, doc. diagnostics)
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)
453428 end
429+ append! (diags, doc. diagnostics)
454430 end
431+ end
455432
456- if JuliaWorkspaces. has_file (server. workspace, uri)
457- st = JuliaWorkspaces. get_text_file (server. workspace, uri). content
433+ if JuliaWorkspaces. has_file (server. workspace, uri)
434+ st = JuliaWorkspaces. get_text_file (server. workspace, uri). content
458435
459- new_diags = measure_sub_operation (" publish_diagnostics - get_diagnostic" , server) do
460- JuliaWorkspaces. get_diagnostic (server. workspace, uri)
461- end
436+ JuliaWorkspaces. get_diagnostic (server. workspace, uri)
462437
463- append! (diags, Diagnostic (
464- Range (st, i. range),
465- if i. severity== :error
466- DiagnosticSeverities. Error
467- elseif i. severity== :warning
468- DiagnosticSeverities. Warning
469- elseif i. severity== :info
470- DiagnosticSeverities. Information
471- else
472- error (" Unknown severity $(i. severity) " )
473- end ,
474- missing ,
475- missing ,
476- i. source,
477- i. message,
478- missing ,
479- missing
480- ) for i in new_diags)
481- end
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)
482456 end
483457 end
484458
0 commit comments