Skip to content

Commit f4e015f

Browse files
authored
chore: improve metrics (#1013)
semantic highlighting, folding, diagnostics, completion Signed-off-by: Rudi Grinberg <[email protected]>
1 parent 956047b commit f4e015f

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

ocaml-lsp-server/src/compl.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ module Complete_by_prefix = struct
204204
let complete doc prefix pos ~deprecated ~resolve =
205205
let+ (completion : Query_protocol.completions) =
206206
let logical_pos = Position.logical pos in
207-
Document.Merlin.with_pipeline_exn doc (dispatch_cmd ~prefix logical_pos)
207+
Document.Merlin.with_pipeline_exn
208+
~name:"completion-prefix"
209+
doc
210+
(dispatch_cmd ~prefix logical_pos)
208211
in
209212
process_dispatch_resp ~deprecated ~resolve doc pos completion
210213
end
@@ -315,7 +318,10 @@ let complete (state : State.t)
315318
{ ci with CompletionItem.preselect = Some true } :: rest)
316319
in
317320
let+ construct_cmd_resp, compl_by_prefix_resp =
318-
Document.Merlin.with_pipeline_exn merlin (fun pipeline ->
321+
Document.Merlin.with_pipeline_exn
322+
~name:"completion"
323+
merlin
324+
(fun pipeline ->
319325
let construct_cmd_resp =
320326
Complete_with_construct.dispatch_cmd position pipeline
321327
in

ocaml-lsp-server/src/diagnostics.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ let merlin_diagnostics diagnostics merlin =
284284
let command =
285285
Query_protocol.Errors { lexing = true; parsing = true; typing = true }
286286
in
287-
Document.Merlin.with_pipeline_exn merlin (fun pipeline ->
287+
Document.Merlin.with_pipeline_exn
288+
~name:"diagnostics"
289+
merlin
290+
(fun pipeline ->
288291
match Query_commands.dispatch pipeline command with
289292
| exception Merlin_extend.Extend_main.Handshake.Error error ->
290293
let message =

ocaml-lsp-server/src/document.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ module Single_pipeline : sig
122122
val create : Lev_fiber.Thread.t -> t
123123

124124
val use :
125-
t
125+
?name:string
126+
-> t
126127
-> doc:Text_document.t
127128
-> config:Merlin_config.t
128129
-> f:(Mpipeline.t -> 'a)
@@ -132,7 +133,7 @@ end = struct
132133

133134
let create thread = { thread }
134135

135-
let use t ~doc ~config ~f =
136+
let use ?name t ~doc ~config ~f =
136137
let* config = Merlin_config.config config in
137138
let make_pipeline =
138139
let source = Msource.make (Text_document.text doc) in
@@ -158,9 +159,11 @@ end = struct
158159
let module Event = Chrome_trace.Event in
159160
let dur = Event.Timestamp.of_float_seconds (stop -. start) in
160161
let fields =
162+
let name = Option.value name ~default:"unknown" in
161163
Event.common_fields
164+
~cat:[ "merlin" ]
162165
~ts:(Event.Timestamp.of_float_seconds start)
163-
~name:"merlin"
166+
~name
164167
()
165168
in
166169
Event.complete ~dur fields
@@ -245,13 +248,13 @@ module Merlin = struct
245248

246249
let kind t = Kind.of_fname (Uri.to_path (uri (Merlin t)))
247250

248-
let with_pipeline (t : t) f =
249-
Single_pipeline.use t.pipeline ~doc:t.tdoc ~config:t.merlin_config ~f
251+
let with_pipeline ?name (t : t) f =
252+
Single_pipeline.use ?name t.pipeline ~doc:t.tdoc ~config:t.merlin_config ~f
250253

251254
let mconfig (t : t) = Merlin_config.config t.merlin_config
252255

253-
let with_pipeline_exn doc f =
254-
let+ res = with_pipeline doc f in
256+
let with_pipeline_exn ?name doc f =
257+
let+ res = with_pipeline ?name doc f in
255258
match res with
256259
| Ok s -> s
257260
| Error exn -> Exn_with_backtrace.reraise exn

ocaml-lsp-server/src/document.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module Merlin : sig
5353

5454
val timer : t -> Lev_fiber.Timer.Wheel.task
5555

56-
val with_pipeline_exn : t -> (Mpipeline.t -> 'a) -> 'a Fiber.t
56+
val with_pipeline_exn : ?name:string -> t -> (Mpipeline.t -> 'a) -> 'a Fiber.t
5757

5858
val dispatch :
5959
t -> 'a Query_protocol.t -> ('a, Exn_with_backtrace.t) result Fiber.t

ocaml-lsp-server/src/folding_range.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ let compute (state : State.t) (params : FoldingRangeParams.t) =
305305
| `Other -> Fiber.return None
306306
| `Merlin m ->
307307
let+ ranges =
308-
Document.Merlin.with_pipeline_exn m (fun pipeline ->
308+
Document.Merlin.with_pipeline_exn
309+
~name:"folding range"
310+
m
311+
(fun pipeline ->
309312
let parsetree = Mpipeline.reader_parsetree pipeline in
310313
fold_over_parsetree parsetree)
311314
in

ocaml-lsp-server/src/semantic_highlighting.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,10 @@ let gen_new_id =
857857

858858
let compute_tokens doc =
859859
let+ parsetree, source =
860-
Document.Merlin.with_pipeline_exn doc (fun p ->
861-
(Mpipeline.reader_parsetree p, Mpipeline.raw_source p))
860+
Document.Merlin.with_pipeline_exn
861+
~name:"semantic highlighting"
862+
doc
863+
(fun p -> (Mpipeline.reader_parsetree p, Mpipeline.raw_source p))
862864
in
863865
let module Fold = Parsetree_fold (struct
864866
let source = Msource.text source

0 commit comments

Comments
 (0)