···9393 (dirs : Eio.Fs.dir_ty Eio.Path.t List.t) : Eio.Fs.dir_ty Eio.Path.t Seq.t =
9494 let@ path = Seq.filter_map @~ Dir_scanner.scan_directories dirs in
9595 let path_str = Eio.Path.native_exn path in
9696- let uri = URI_scheme.path_to_uri ~base:config.url path_str in
9696+ let uri = URI.path_to_uri ~base:config.url path_str in
9797 let last_modified = Eio.Path.(stat ~follow:true path).mtime in
9898 (* "flipped" bind, by default returns the current path. IDK, I am being lazy. *)
9999 let ( let* ) o f = match o with None -> Some path | Some v -> f v in
+1-1
lib/compiler/Dir_scanner.ml
···5959 let matches =
6060 let@ () = S.run in
6161 let@ fp = List.iter @~ dirs in
6262- let@ name = Option.iter @~ URI_scheme.name uri in
6262+ let@ name = Option.iter @~ URI.name uri in
6363 process_dir (matching_basename name) fp
6464 in
6565 try
+3-5
lib/compiler/Driver.ml
···3333 assert (Eio.Path.is_directory tree_dir);
3434 let@ tree = Seq.iter @~ Phases.load tree_dir in
3535 let lsp_uri = Tree.lsp_uri tree in
3636- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
3636+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
3737 URI.Tbl.replace forest.resolver uri (Lsp.Uri.to_path lsp_uri);
3838 forest.={uri} <- Tree tree
3939- (*lsp_documents ;*)
4040- (*Logs.debug (fun m -> m "loaded %d trees" (Seq.length lsp_documents))*)
4139 in
4240 (Parse_all, forest)
4341 | Parse_all ->
···120118 | Load_tree path ->
121119 let doc = Imports.load_tree path in
122120 let lsp_uri = Tree.lsp_uri doc in
123123- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
121121+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
124122 forest.={uri} <- Tree doc;
125123 (Parse lsp_uri, forest)
126124 | Parse uri ->
127125 Logs.debug (fun m -> m "Reparsing");
128128- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri in
126126+ let uri = URI.of_lsp_uri ~base:forest.config.url uri in
129127 begin match Option.bind forest.={uri} Tree.to_doc with
130128 | Some doc -> begin
131129 match Parse.parse_document doc with
+6-10
lib/compiler/Phases.ml
···2828 let@ uri, result =
2929 List.partition_map
3030 @~
3131- let@ uri, Tree tree = List.filter_map @~ trees in
3232- match tree with
3333- | {phase; tree; _} -> begin
3434- match phase with
3535- | Parsed | Expanded | Evaluated -> None
3636- | Loaded -> begin Some (uri, Parse.parse_document tree) end
3737- end
3131+ let@ uri, tree = List.filter_map @~ trees in
3232+ match Tree.to_doc tree with
3333+ | Some document -> Some (uri, Parse.parse_document document)
3434+ | None -> None
3835 in
3936 match result with Ok tree -> Right (uri, tree) | Error e -> Left (uri, e)
40374138let reparse (doc : Lsp.Text_document.t) (forest : State.t) =
4239 Logs.debug (fun m -> m "reparsing");
4340 let uri =
4444- URI_scheme.lsp_uri_to_uri ~base:forest.config.url
4545- @@ Lsp.Text_document.documentUri doc
4141+ URI.of_lsp_uri ~base:forest.config.url @@ Lsp.Text_document.documentUri doc
4642 in
4743 begin match Parse.parse_document doc with
4844 | Ok code ->
···10399 match guess_uri (Error.tex_range tex_error) with
104100 | None -> assert false
105101 | Some uri ->
106106- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri in
102102+ let uri = URI.of_lsp_uri ~base:forest.config.url uri in
107103 forest.?{uri} <- [Error.of_tex_error tex_error]
108104 end
109105 end
+1-1
lib/compiler/URI_util.ml
···2929 @@
3030 let@ uri = Seq.filter_map @~ addrs in
3131 if URI.host config.url = URI.host uri then
3232- let@ prefix', key = Option.bind @@ URI_scheme.split_addr uri in
3232+ let@ prefix', key = Option.bind @@ URI.split_addr uri in
3333 if prefix = prefix' then Some key else None
3434 else None
3535 in
+1-1
lib/compiler/test/Test_compiler.ml
···108108 |> Driver.run_until_done Load_all_configured_dirs
109109 in
110110 let reparse_addr = "t8.tree" in
111111- let reparse_uri = URI_scheme.path_to_uri ~base:config.url reparse_addr in
111111+ let reparse_uri = URI.path_to_uri ~base:config.url reparse_addr in
112112 let vtx = T.Uri_vertex reparse_uri in
113113 Alcotest.(check int)
114114 "Number of vertices before reparsing" 8
-1
lib/core/Forester_core.ml
···1313(**@closed*)
14141515module URI = URI
1616-module URI_scheme = URI_scheme
1716module Config = Config
18171918(** {1 Vertices}
+27-1
lib/core/URI.ml
···97979898let last_segment = String.split_on_char '/' >>> List.rev >>> List.hd
9999100100-let of_document ~(base : t) =
100100+let name (uri : t) : string option =
101101+ uri |> path_components
102102+ |> List.filter (fun x -> not (x = ""))
103103+ |> List.rev |> List.nth_opt @~ 0
104104+105105+let split_addr (uri : t) : (string option * int) option =
106106+ let@ name = Option.bind @@ name uri in
107107+ (* primitively check for address of form YYYY-MM-DD *)
108108+ let date_regex =
109109+ Str.regexp {|^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$|}
110110+ in
111111+ if Str.string_match date_regex name 0 then None
112112+ else
113113+ match String.rindex_opt name '-' with
114114+ | Some i ->
115115+ let prefix = String.sub name 0 i
116116+ and suffix = String.sub name (i + 1) (String.length name - i - 1) in
117117+ let@ key = Option.map @~ BaseN.Base36.int_of_string suffix in
118118+ (Some prefix, key)
119119+ | _ ->
120120+ let@ key = Option.map @~ BaseN.Base36.int_of_string name in
121121+ (None, key)
122122+123123+let of_lsp_uri ~(base : t) =
101124 Lsp.Uri.to_path >>> Filename.chop_extension >>> last_segment
102125 >>> named_uri ~base
126126+127127+let path_to_uri ~(base : t) =
128128+ last_segment >>> Filename.chop_extension >>> named_uri ~base
+4
lib/core/URI.mli
···40404141val named_uri : base:t -> string -> t
42424343+val name : t -> string option
4444+val split_addr : t -> (string option * int) option
4545+val of_lsp_uri : base:t -> Lsp.Uri.t -> t
4646+val path_to_uri : base:t -> string -> t
4347val last_segment : string -> string
-41
lib/core/URI_scheme.ml
···11-(*
22- * SPDX-FileCopyrightText: 2024 The Forester Project Contributors
33- *
44- * SPDX-License-Identifier: GPL-3.0-or-later
55- *)
66-77-open Forester_prelude
88-99-let name (uri : URI.t) : string option =
1010- uri
1111- |> URI.path_components
1212- |> List.filter (fun x -> not (x = ""))
1313- |> List.rev
1414- |> List.nth_opt @~ 0
1515-1616-let split_addr (uri : URI.t) : (string option * int) option =
1717- let@ name = Option.bind @@ name uri in
1818- (* primitively check for address of form YYYY-MM-DD *)
1919- let date_regex =
2020- Str.regexp {|^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$|}
2121- in
2222- if Str.string_match date_regex name 0 then None
2323- else
2424- match String.rindex_opt name '-' with
2525- | Some i ->
2626- let prefix = String.sub name 0 i
2727- and suffix = String.sub name (i + 1) (String.length name - i - 1) in
2828- let@ key = Option.map @~ BaseN.Base36.int_of_string suffix in
2929- (Some prefix, key)
3030- | _ ->
3131- let@ key = Option.map @~ BaseN.Base36.int_of_string name in
3232- (None, key)
3333-3434-let lsp_uri_to_uri ~(base : URI.t) =
3535- Lsp.Uri.to_path
3636- >>> Filename.chop_extension
3737- >>> URI.last_segment
3838- >>> URI.named_uri ~base
3939-4040-let path_to_uri ~(base : URI.t) =
4141- URI.last_segment >>> Filename.chop_extension >>> URI.named_uri ~base
···3131 in
3232 match item with
3333 | {uri; _} ->
3434- let uri = URI_scheme.path_to_uri ~base:config.url (Lsp.Uri.to_path uri) in
3434+ let uri = URI.path_to_uri ~base:config.url (Lsp.Uri.to_path uri) in
3535 let vertex = T.Uri_vertex uri in
3636 let run_query = Forest.run_datalog_query forest.graphs in
3737 let fwdlinks = run_query @@ Builtin_queries.fwdlinks_datalog vertex in
···6161 in
6262 match item with
6363 | {uri; _} ->
6464- let uri = URI_scheme.path_to_uri ~base:config.url (Lsp.Uri.to_path uri) in
6464+ let uri = URI.path_to_uri ~base:config.url (Lsp.Uri.to_path uri) in
6565 let vertex = T.Uri_vertex uri in
6666 let run_query = Forest.run_datalog_query forest.graphs in
6767 let backlinks = run_query @@ Builtin_queries.backlinks_datalog vertex in
···7878 let Lsp_state.{forest; _} = Lsp_state.get () in
7979 match params with
8080 | {position; textDocument; _} -> (
8181- let uri =
8282- URI_scheme.lsp_uri_to_uri ~base:forest.config.url textDocument.uri
8383- in
8181+ let uri = URI.of_lsp_uri ~base:forest.config.url textDocument.uri in
8482 match Imports.resolve_uri_to_code ~forest uri with
8583 | Error _ -> None
8684 | Ok tree ->
+3-3
lib/language_server/Completion.ml
···297297 Some (`String content)
298298 in
299299 let@ uri = Option.bind @@ frontmatter.uri in
300300- let@ uri_name = Option.bind @@ URI_scheme.name uri in
300300+ let@ uri_name = Option.bind @@ URI.name uri in
301301 let title_text = render title in
302302 Option.some
303303 @@ L.CompletionItem.create ?documentation
···330330 ({context; position; textDocument = {uri}; _} : L.CompletionParams.t) : _ =
331331 Logs.debug (fun m ->
332332 m "when computing completions for %s" (Lsp.Uri.to_string uri));
333333- let triggerCharacter =
333333+ let _triggerCharacter =
334334 match context with
335335 | Some {triggerCharacter; _} -> triggerCharacter
336336 | None -> None
···338338 let Lsp_state.{forest; _} = Lsp_state.get () in
339339 let config = forest.config in
340340 let base = config.url in
341341- let uri = URI_scheme.lsp_uri_to_uri ~base uri in
341341+ let uri = URI.of_lsp_uri ~base uri in
342342 let* tree = forest.={uri} in
343343 let* code = Tree.to_code tree in
344344 let completion_types = completion_types ~position tree in
+1-3
lib/language_server/Definitions.ml
···16161717let compute (params : L.DefinitionParams.t) =
1818 let Lsp_state.{forest; _} = Lsp_state.get () in
1919- let uri =
2020- URI_scheme.lsp_uri_to_uri ~base:forest.config.url params.textDocument.uri
2121- in
1919+ let uri = URI.of_lsp_uri ~base:forest.config.url params.textDocument.uri in
2220 let@ tree = Option.bind forest.={uri} in
2321 let@ nodes = Option.bind Tree.(Option.map nodes @@ to_code tree) in
2422 let@ {value = str; _} =
+1-1
lib/language_server/Diagnostics.ml
···2222let compute (document : Lsp.Text_document.t) =
2323 let Lsp_state.{forest; _} = Lsp_state.get () in
2424 let lsp_uri = Lsp.Text_document.documentUri document in
2525- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
2525+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
2626 match forest.?{uri} with
2727 | [] ->
2828 Eio.traceln "Clearing diagnostics for %s" (Lsp.Uri.to_path lsp_uri);
+2-9
lib/language_server/Did_change.ml
···1717let compute (params : L.DidChangeTextDocumentParams.t) =
1818 let Lsp_state.{forest; _} = Lsp_state.get () in
1919 let lsp_uri = params.textDocument.uri in
2020- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
2020+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
2121 let@ tree = Option.iter @~ forest.={uri} in
2222 match Tree.to_doc tree with
2323- | None ->
2424- Logs.debug (fun m ->
2525- m
2626- "Did_change.compute fatal error, could not find tree with uri %a \
2727- from LSP uri %s"
2828- URI.pp uri
2929- (Lsp.Uri.to_string lsp_uri));
3030- assert false
2323+ | None -> assert false
3124 | Some doc ->
3225 let updated =
3326 Tree.of_doc
+1-1
lib/language_server/Did_create_files.ml
···2020 begin
2121 let@ {uri} = List.iter @~ files in
2222 let lsp_uri = L.DocumentUri.of_string uri in
2323- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
2323+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
2424 let path = Eio.Path.(env#fs / L.DocumentUri.to_path lsp_uri) in
2525 let doc = Imports.load_tree path in
2626 forest.={uri} <- Tree doc
+1-1
lib/language_server/Did_open.ml
···1818 let path = Lsp.Uri.to_path lsp_uri in
1919 let Lsp_state.{forest; _} = Lsp_state.get () in
2020 let document = Lsp.Text_document.make ~position_encoding:`UTF16 params in
2121- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
2121+ let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in
2222 forest.={uri} <-
2323 Tree {tree = document; source = Some (`File path); phase = Loaded};
2424 Lsp_state.modify (fun ({forest; _} as lsp_state) ->
+1-4
lib/language_server/Document_link.ml
···2424 let config = forest.config in
2525 let Lsp_state.{forest; _} = Lsp_state.get () in
2626 let links =
2727- let uri =
2828- URI_scheme.lsp_uri_to_uri ~base:config.url params.textDocument.uri
2929- in
3030- (* match Imports.resolve_uri_to_code forest uri with *)
2727+ let uri = URI.of_lsp_uri ~base:config.url params.textDocument.uri in
3128 match Option.bind forest.={uri} Tree.to_code with
3229 | None -> []
3330 | Some tree -> (
+1-4
lib/language_server/Document_symbols.ml
···1919 [> `DocumentSymbol of L.DocumentSymbol.t list] option =
2020 let uri = params.textDocument.uri in
2121 let Lsp_state.{forest; _} = Lsp_state.get () in
2222- match
2323- State.get_code forest
2424- @@ URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri
2525- with
2222+ match State.get_code forest @@ URI.of_lsp_uri ~base:forest.config.url uri with
2623 | None -> assert false
2724 | Some {tree; _} ->
2825 let symbols : L.DocumentSymbol.t list =
+1-3
lib/language_server/Highlight.ml
···15151616let compute (params : L.DocumentHighlightParams.t) =
1717 let Lsp_state.{forest; _} = Lsp_state.get () in
1818- let uri =
1919- URI_scheme.lsp_uri_to_uri ~base:forest.config.url params.textDocument.uri
2020- in
1818+ let uri = URI.of_lsp_uri ~base:forest.config.url params.textDocument.uri in
2119 let@ tree = Option.map @~ State.get_code forest uri in
2220 let@ Range.{range; value} = List.filter_map @~ Tree.nodes tree in
2321 let@ range = Option.map @~ range in
+1-3
lib/language_server/Hover.ml
···2121let compute ({position; textDocument; _} : L.HoverParams.t) =
2222 let Lsp_state.{forest; _} = Lsp_state.get () in
2323 let render = Plain_text_client.string_of_content ~forest in
2424- let uri =
2525- URI_scheme.lsp_uri_to_uri ~base:forest.config.url textDocument.uri
2626- in
2424+ let uri = URI.of_lsp_uri ~base:forest.config.url textDocument.uri in
2725 let@ content =
2826 Option.map
2927 @~
+1-3
lib/language_server/Inlay_hint.ml
···4949let compute (params : L.InlayHintParams.t) : L.InlayHint.t list option =
5050 let Lsp_state.{forest; _} = Lsp_state.get () in
5151 let config = forest.config in
5252- let uri =
5353- URI_scheme.lsp_uri_to_uri ~base:config.url params.textDocument.uri
5454- in
5252+ let uri = URI.of_lsp_uri ~base:config.url params.textDocument.uri in
5553 let@ {tree = {nodes; _}; _} =
5654 Option.map @~ Option.bind forest.={uri} Tree.to_syn
5755 in
+1-1
lib/language_server/Publish.ml
···3838 in
3939 let source =
4040 let Lsp_state.{forest; _} = Lsp_state.get () in
4141- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri in
4141+ let uri = URI.of_lsp_uri ~base:forest.config.url uri in
4242 let@ doc =
4343 Option.map @~ Option.bind (State.find_opt forest uri) Tree.to_doc
4444 in
+2-4
lib/language_server/Semantic_tokens.ml
···267267let tokenize_document (identifier : L.TextDocumentIdentifier.t) :
268268 L.SemanticTokens.t option =
269269 let Lsp_state.{forest; _} = Lsp_state.get () in
270270- let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url identifier.uri in
270270+ let uri = URI.of_lsp_uri ~base:forest.config.url identifier.uri in
271271 Result.to_option
272272 @@
273273 let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in
···283283let tokenize_document_delta (textDocument : L.TextDocumentIdentifier.t) :
284284 L.SemanticTokensDelta.t option =
285285 let Lsp_state.{forest; _} = Lsp_state.get () in
286286- let uri =
287287- URI_scheme.lsp_uri_to_uri ~base:forest.config.url textDocument.uri
288288- in
286286+ let uri = URI.of_lsp_uri ~base:forest.config.url textDocument.uri in
289287 Result.to_option
290288 @@
291289 let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in