@@ -113,9 +113,36 @@ function comp(x::CSTParser.EXPR, y::CSTParser.EXPR)
113113 all (comp (x[i], y[i]) for i = 1 : length (x))
114114end
115115
116+ function measure_sub_operation (f, request_name, server)
117+ start_time = string (Dates. unix2datetime (time ()), " Z" )
118+ tic = time_ns ()
119+ f ()
120+ toc = time_ns ()
121+ duration = (toc - tic) / 1e+6
122+
123+ @static if VERSION >= v " 1.11-"
124+ JSONRPC. send (
125+ server. jr_endpoint,
126+ telemetry_event_notification_type,
127+ Dict (
128+ " command" => " request_metric" ,
129+ " operationId" => string (uuid4 ()),
130+ " operationParentId" => g_operationId[],
131+ " name" => request_name,
132+ " duration" => duration,
133+ " time" => start_time
134+ )
135+ )
136+ end
137+ end
138+
116139function textDocument_didChange_notification (params:: DidChangeTextDocumentParams , server:: LanguageServerInstance , conn)
117- JuliaWorkspaces. mark_current_diagnostics (server. workspace)
118- JuliaWorkspaces. mark_current_testitems (server. workspace)
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
119146
120147 uri = params. textDocument. uri
121148
@@ -127,43 +154,60 @@ function textDocument_didChange_notification(params::DidChangeTextDocumentParams
127154 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) ." )
128155 end
129156
130- new_text_document = apply_text_edits (get_text_document (doc), params. contentChanges, params. textDocument. version)
131- set_text_document! (doc, new_text_document)
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)
132160
133- if ! haskey (server. _open_file_versions, uri)
134- error (" This should not happen" )
135- end
161+ if ! haskey (server. _open_file_versions, uri)
162+ error (" This should not happen" )
163+ end
136164
137- if server. _open_file_versions[uri]> params. textDocument. version
138- error (" Outdated version: server $(server. _open_file_versions[uri]) params $(params. textDocument. version) " )
139- end
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
140168
141- # We originally applied each text edit individually, but that doesn't work because
142- # we need to convert the LS positions to Julia indices after each text edit update
143- # For now we just use the new text that we already created for the legacy TextDocument
144- new_text_file = JuliaWorkspaces. TextFile (uri, JuliaWorkspaces. SourceText (get_text (new_text_document), get_language_id (doc)))
145- JuliaWorkspaces. update_file! (server. workspace, new_text_file)
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)
174+ end
146175
147176 if get_language_id (doc) in (" markdown" , " juliamarkdown" )
148- parse_all (doc, server)
149- lint! (doc, server)
150- elseif get_language_id (doc) == " julia"
151- cst0, cst1 = getcst (doc), CSTParser. parse (get_text (doc), true )
152- r1, r2, r3 = CSTParser. minimal_reparse (s0, get_text (doc), cst0, cst1, inds = true )
153- for i in setdiff (1 : length (cst0. args), r1 , r3) # clean meta from deleted expr
154- StaticLint. clear_meta (cst0[i])
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)
155182 end
156- setcst (doc, EXPR (cst0. head, EXPR[cst0. args[r1]; cst1. args[r2]; cst0. args[r3]], nothing ))
157- sizeof (get_text (doc)) == getcst (doc). fullspan || @error " CST does not match input string length."
158- headof (doc. cst) === :file ? set_doc (doc. cst, doc) : @info " headof(doc) isn't :file for $(doc. _path) "
183+ 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) "
193+
194+ target_exprs = getcst (doc). args[last (r1) .+ (1 : length (r2))]
159195
160- target_exprs = getcst (doc). args[last (r1) .+ (1 : length (r2))]
161- semantic_pass (getroot (doc), target_exprs)
162- lint! (doc, server)
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
163203 end
164204
165- publish_diagnostics ([get_uri (doc)], server, conn, " textDocument_didChange_notification" )
166- publish_tests (server)
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
167211end
168212
169213function parse_all (doc:: Document , server:: LanguageServerInstance )
0 commit comments