@@ -10,7 +10,7 @@ type 'a or_error = ('a, Error.t) result
1010module E = CCResult
1111module IO = Linol. Blocking_IO
1212module L = Linol.Jsonrpc2. Make (IO )
13- module LT = Lsp. Types
13+ module LT = Linol. Lsp.Types
1414module Log = (val Logs. src_log Logs.Src. (create " lsp" ))
1515
1616type loc = Loc .t
@@ -21,12 +21,14 @@ type processed_buf = {
2121 defs : Definitions .t or_error ;
2222}
2323
24- let range_of_loc_ (l : loc ) : Lsp.Types.Range.t =
24+ let uri_to_string = LT.DocumentUri. to_string
25+
26+ let range_of_loc_ (l : loc ) : Linol.Lsp.Types.Range.t =
2527 let mk_pos_ p =
2628 let line, col = Loc.Pos. to_line_col l.input p in
27- Lsp.Types.Position. create ~line: (line - 1 ) ~character: col
29+ Linol. Lsp.Types.Position. create ~line: (line - 1 ) ~character: col
2830 in
29- Lsp.Types.Range. create ~start: (mk_pos_ l.start) ~end_: (mk_pos_ l.stop)
31+ Linol. Lsp.Types.Range. create ~start: (mk_pos_ l.start) ~end_: (mk_pos_ l.stop)
3032
3133let diag_of_error ~uri (e0 : Error.t ) : LT.Diagnostic.t list =
3234 let e, ctx = Error. unwrap_ctx e0 in
@@ -46,12 +48,12 @@ let diag_of_error ~uri (e0 : Error.t) : LT.Diagnostic.t list =
4648
4749 match errs with
4850 | [] ->
49- Log. err (fun k -> k " in %s: err with no loc:@ %a" uri Error. pp e0);
51+ Log. err (fun k -> k " in %s: err with no loc:@ %a" (uri_to_string uri) Error. pp e0);
5052 []
5153 | (msg0 , loc0 ) :: ctx_errs ->
5254 let d =
5355 LT.Diagnostic. create ~severity: LT.DiagnosticSeverity. Error
54- ~range: (range_of_loc_ loc0) ~message: msg0
56+ ~range: (range_of_loc_ loc0) ~message: ( `String msg0)
5557 ~related Information:(List. map tr_ctx_err_ ctx_errs)
5658 ()
5759 in
@@ -68,7 +70,7 @@ let diagnostics ~uri (p : processed_buf) : _ list =
6870 in
6971 let errors = List. rev_append (Stanza. errors l) defs_errors in
7072 Log. debug (fun k ->
71- k " in %s: ok, %d stanzas, %d errors" uri (List. length l)
73+ k " in %s: ok, %d stanzas, %d errors" (uri_to_string uri) (List. length l)
7274 (List. length errors));
7375 CCList. flat_map (diag_of_error ~uri ) errors
7476 | Error e0 -> diag_of_error ~uri e0
@@ -100,9 +102,11 @@ class blsp =
100102 inherit L. server
101103
102104 (* one env per document *)
103- val buffers : (Lsp.Types.DocumentUri .t , processed_buf ) Hashtbl .t Lock .t =
105+ val buffers : (Linol. Lsp.Types.DocumentUri.t , processed_buf ) Hashtbl .t Lock .t =
104106 Lock .create @@ Hashtbl .create 32
105107
108+ method spawn_query_handler f = ignore (Thread. create (fun () -> f () ) () )
109+
106110 method! config_hover = Some (`Bool true )
107111 method! config_definition = Some (`Bool true )
108112
@@ -114,10 +118,10 @@ class blsp =
114118 method! config_sync_opts =
115119 let change = LT.TextDocumentSyncKind. Incremental in
116120 LT.TextDocumentSyncOptions. create ~open Close:true ~change
117- ~save: (LT.SaveOptions. create ~include Text:false () )
121+ ~save: (`SaveOptions ( LT.SaveOptions. create ~include Text:false () ))
118122 ()
119123
120- method! on_req_hover ~notify_back: _ ~id: _ ~uri ~pos (_ : L.doc_state )
124+ method! on_req_hover ~notify_back: _ ~id: _ ~uri ~pos ~work DoneToken:_ (_ : L.doc_state )
121125 : LT.Hover. t option =
122126 let pos = Loc.Pos. of_line_col pos.L.Position. line pos.character in
123127 match Lock. with_ buffers (fun b -> CCHashtbl. get b uri) with
@@ -142,7 +146,7 @@ class blsp =
142146 Some h))
143147 | _ -> None
144148
145- method! on_req_definition ~notify_back: _ ~id: _ ~uri ~pos (_ : L.doc_state )
149+ method! on_req_definition ~notify_back: _ ~id: _ ~uri ~pos ~work DoneToken:_ ~partial ResultToken:_ (_ : L.doc_state )
146150 : LT.Locations. t option =
147151 let pos = Loc.Pos. of_line_col pos.L.Position. line pos.character in
148152 match Lock. with_ buffers (fun b -> CCHashtbl. get b uri) with
@@ -165,13 +169,13 @@ class blsp =
165169
166170 (* FIXME: completion is never useful on a parsable buffer, and
167171 buffers that do not parse have no definitions *)
168- method! on_req_completion ~notify_back: _ ~id: _ ~uri ~pos ~ctx: _
172+ method! on_req_completion ~notify_back: _ ~id: _ ~uri ~pos ~ctx: _ ~work DoneToken:_ ~partial ResultToken:_
169173 (_ : L.doc_state )
170174 : [ `CompletionList of LT.CompletionList. t
171175 | `List of LT.CompletionItem. t list ]
172176 option =
173177 Log. debug (fun k ->
174- k " completion request in '%s' at pos: %d line, %d col" uri pos.line
178+ k " completion request in '%s' at pos: %d line, %d col" (uri_to_string uri) pos.line
175179 pos.character);
176180 let pos = Loc.Pos. of_line_col pos.line pos.character in
177181 match Lock. with_ buffers (fun b -> CCHashtbl. get b uri) with
@@ -203,12 +207,12 @@ class blsp =
203207 - return the diagnostics from the new state
204208 *)
205209 method private _on_doc ~(notify_back : L.notify_back )
206- (uri : Lsp.Types.DocumentUri.t ) (contents : string ) =
207- Log. debug (fun k -> k " on doc %s" uri);
210+ (uri : Linol. Lsp.Types.DocumentUri.t ) (contents : string ) =
211+ Log. debug (fun k -> k " on doc %s" (uri_to_string uri) );
208212 let open E.Infix in
209213 let stanzas =
210214 catch_e @@ fun () ->
211- Stanza. parse_string ~reify_errors: true ~filename: uri contents
215+ Stanza. parse_string ~reify_errors: true ~filename: (uri_to_string uri) contents
212216 in
213217 let defs =
214218 let * stanzas = stanzas in
@@ -217,7 +221,7 @@ class blsp =
217221 let pdoc = { stanzas; defs; text = contents } in
218222 Lock. with_ buffers (fun b -> Hashtbl. replace b uri pdoc);
219223 let diags = diagnostics ~uri pdoc in
220- Log. debug (fun k -> k " send diags for %s" uri);
224+ Log. debug (fun k -> k " send diags for %s" (uri_to_string uri) );
221225 notify_back#send_diagnostic diags
222226
223227 (* We now override the [on_notify_doc_did_open] method that will be called
@@ -237,7 +241,7 @@ class blsp =
237241 hashtable state, to avoid leaking memory. *)
238242 method on_notif_doc_did_close ~notify_back: _
239243 (d : LT.TextDocumentIdentifier.t ) : unit IO. t =
240- Log. debug (fun k -> k " close %s" d.uri);
244+ Log. debug (fun k -> k " close %s" (uri_to_string d.uri) );
241245 Lock. with_ buffers (fun b -> Hashtbl. remove b d.uri);
242246 IO. return ()
243247 end
0 commit comments