···1212val check : Base.server -> L.DocumentUri.t -> unit
13131414val build_once :
1515- env: Forester_frontend.Forest_reader.env ->
1615 Base.server ->
1716 unit ->
1817 unit
+12-1
lib/language_server/Forester_lsp.ml
···6969 `SemanticTokensOptions
7070 (L.SemanticTokensOptions.create ~legend: Semantic_tokens.legend ~full ())
7171 in
7272+ let documentLinkProvider =
7373+ L.DocumentLinkOptions.create
7474+ ~resolveProvider: true
7575+ ~workDoneProgress: false
7676+ ()
7777+ in
7878+ let workspaceSymbolProvider =
7979+ `WorkspaceSymbolOptions (L.WorkspaceSymbolOptions.create ())
8080+ in
7281 (* [NOTE: Position Encodings]
7382 For various historical reasons, the spec states that we are _required_ to support UTF-16.
7483 This causes more trouble than it's worth, so we always select UTF-8 as our encoding, even
···8897 ~completionProvider
8998 ~definitionProvider
9099 ~semanticTokensProvider
100100+ ~documentLinkProvider
101101+ ~workspaceSymbolProvider
91102 ()
9210393104let supports_utf8_encoding (init_params : L.InitializeParams.t) =
···193204 should_shutdown = false;
194205 }
195206 in
196196- Analysis.build_once ~env init ();
207207+ Analysis.build_once init ();
197208 Server.run ~init @@
198209 fun () ->
199210 begin
+98-1
lib/language_server/LspServer.ml
···102102103103(* [TODO: Reed M, 12/12/2022] No code actions for now. *)
104104let code_action (_params : L.CodeActionParams.t) : L.CodeActionResult.t =
105105- None
105105+ let action = L.CodeAction.create ~title: "find tree" () in
106106+ Some [`CodeAction action]
106107107108let completion
108109 (params : L.CompletionParams.t)
···281282 code
282283 |> Option.some
283284285285+(* TODO: handle external links as well? *)
286286+let document_link (params : L.DocumentLinkParams.t) =
287287+ match params with
288288+ | { textDocument; _ } ->
289289+ let server = State.get () in
290290+ let links =
291291+ match Hashtbl.find_opt server.codes textDocument with
292292+ | Some tree ->
293293+ begin
294294+ tree.code
295295+ |> List.filter_map
296296+ (
297297+ fun node ->
298298+ match Range.(node.value) with
299299+ | Code.Group (Squares, [{ value = Text addr; _ }])
300300+ | Code.Group (Parens, [{ value = Text addr; _ }])
301301+ | Code.Group (Braces, [{ value = Text addr; _ }]) ->
302302+ (* TODO: Need to analyse syn *)
303303+ let range = (LspShims.Loc.lsp_range_of_range node.loc) in
304304+ let iri = (Iri_scheme.user_iri ~host: server.config.host addr) in
305305+ let* target = Hashtbl.find_opt server.resolver iri in
306306+ let* { frontmatter; _ } = F.get_article iri in
307307+ let* tooltip = Option.map PT.string_of_content frontmatter.title in
308308+ let link =
309309+ L.DocumentLink.create
310310+ ~range
311311+ ~target: target.uri
312312+ ~tooltip
313313+ ()
314314+ in
315315+ Some link
316316+ | _ ->
317317+ None
318318+ )
319319+ end
320320+ | None ->
321321+ []
322322+ in
323323+ Some links
324324+325325+(* I don't understand this request...*)
326326+let document_link_resolve (params : L.DocumentLink.t) =
327327+ match params with
328328+ | link ->
329329+ link
330330+331331+let workspace_symbol (_params : L.WorkspaceSymbolParams.t) =
332332+ (* let _s = L.WorkspaceSymbol.create ~name: "test" () in *)
333333+ let server = State.get () in
334334+ let symbols =
335335+ server.codes
336336+ |> Hashtbl.to_seq
337337+ |> Seq.map
338338+ (
339339+ fun ((ident : L.TextDocumentIdentifier.t), _) ->
340340+ let location =
341341+ L.Location.{
342342+ range = L.Range.{
343343+ end_ = { character = 0; line = 0; };
344344+ start = { character = 0; line = 0; };
345345+ };
346346+ uri = ident.uri
347347+ }
348348+ in
349349+ let iri =
350350+ ident.uri
351351+ |> Lsp.Uri.to_path
352352+ |> String.split_on_char '/'
353353+ |> List.rev
354354+ |> List.hd
355355+ |> Filename.chop_extension
356356+ |> Iri_scheme.user_iri ~host: server.config.host
357357+ in
358358+ let title =
359359+ match F.get_article iri with
360360+ | None -> "untitled"
361361+ | Some { frontmatter; _ } ->
362362+ begin
363363+ match frontmatter.title with
364364+ | None -> "untitled"
365365+ | Some content ->
366366+ PT.string_of_content content
367367+ end
368368+ in
369369+ L.SymbolInformation.create ~kind: File ~location ~name: title ()
370370+ )
371371+ |> List.of_seq
372372+ in
373373+ Some symbols
374374+284375module Request = struct
285376 type 'resp t = 'resp Lsp.Client_request.t
286377 type packed = Lsp_Request.packed
···306397 Semantic_tokens.on_delta_request params
307398 | SemanticTokensFull params ->
308399 Semantic_tokens.on_full_request params
400400+ | TextDocumentLink params ->
401401+ document_link params
402402+ | TextDocumentLinkResolve params ->
403403+ document_link_resolve params
404404+ | WorkspaceSymbol params ->
405405+ workspace_symbol params
309406 | _ ->
310407 raise @@ LspError (UnknownRequest mthd)
311408