···3131 let () =
3232 let@ tree_dir = List.iter @~ paths in
3333 assert (Eio.Path.is_directory tree_dir);
3434- let@ tree_src = Seq.iter @~ Phases.load tree_dir in
3535- let lsp_uri = Lsp.Text_document.documentUri tree_src in
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
3737 URI.Tbl.replace forest.resolver uri (Lsp.Uri.to_path lsp_uri);
3838- forest.={uri} <- Document tree_src
3838+ forest.={uri} <- Tree tree
3939 (*lsp_documents ;*)
4040 (*Logs.debug (fun m -> m "loaded %d trees" (Seq.length lsp_documents))*)
4141 in
···4343 | Parse_all ->
4444 let errors, codes = Phases.parse forest in
4545 let () =
4646- let@ code = List.iter @~ codes in
4747- let@ uri = Option.iter @~ Tree.(identity_to_uri code.identity) in
4848- forest.={uri} <- Parsed code;
4646+ let@ uri, code = List.iter @~ codes in
4747+ forest.={uri} <- Tree code;
4948 forest.?{uri} <- []
5049 in
5150 if List.length errors = 0 then
5251 assert (Seq.for_all Tree.is_parsed (URI.Tbl.to_seq_values forest.index));
5352 let () =
5454- let@ error = List.iter @~ errors in
5555- let@ uri =
5656- Option.iter
5757- @~ Option.map
5858- (URI_scheme.lsp_uri_to_uri ~base:forest.config.url)
5959- (Phases.guess_uri error.range)
6060- in
5353+ let@ uri, error = List.iter @~ errors in
6154 forest.?{uri} <- [Error.parse_error error]
6255 in
6356 ( report
6464- ~errors:(List.map Error.parse_error errors)
5757+ ~errors:(List.map (snd >>> Error.parse_error) errors)
6558 ~and_then:Build_import_graph,
6659 forest )
6760 | Build_import_graph ->
···7871 | None -> assert false
7972 | Some code ->
8073 let result, errors = Phases.expand forest code in
8181- forest.={uri} <- Expanded result;
7474+ forest.={uri} <- Tree result;
8275 (report ~errors ~and_then:(Eval uri), forest)
8376 end
8477 | Eval_all ->
···126119 (Done, forest)
127120 | Load_tree path ->
128121 let doc = Imports.load_tree path in
129129- Logs.debug (fun m -> m "%s" (Lsp.Text_document.text doc));
130130- let lsp_uri = Lsp.Text_document.documentUri doc in
122122+ let lsp_uri = Tree.lsp_uri doc in
131123 let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
132132- forest.={uri} <- Document doc;
124124+ forest.={uri} <- Tree doc;
133125 (Parse lsp_uri, forest)
134126 | Parse uri ->
135127 Logs.debug (fun m -> m "Reparsing");
136128 let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri in
137129 begin match Option.bind forest.={uri} Tree.to_doc with
138130 | Some doc -> begin
139139- match Parse.parse_document ~config:forest.config doc with
131131+ match Parse.parse_document doc with
140132 | Ok code ->
141141- forest.={uri} <- Parsed code;
133133+ forest.={uri} <- Tree code;
142134 forest.?{uri} <- [];
143143- Imports.fixup code forest;
135135+ Imports.fixup ~uri code forest;
144136 (Expand uri, forest)
145137 | Error parse_error ->
146138 let errors = [Error.parse_error parse_error] in
···148140 (report ~errors ~and_then:Done, forest)
149141 end
150142 | None -> (
151151- match Imports.resolve_uri_to_code forest uri with
143143+ match Imports.resolve_uri_to_code ~forest uri with
152144 | Ok code ->
153153- Imports.fixup code forest;
154154- forest.={uri} <- Parsed code;
145145+ Imports.fixup ~uri code forest;
146146+ forest.={uri} <- Tree code;
155147 (Expand uri, forest)
156148 | Error errors -> (Report_errors (errors, Expand uri), forest))
157149 end
+34-11
lib/compiler/Error.ml
···8181 ~none:[]
82828383let render_type_error ~range Eval_error.{got; expected} =
8484+ let show_value : Value.t -> string = function
8585+ | Value.Content _ -> "content"
8686+ | Value.Clo (_, _, _) -> "a function"
8787+ | Value.Dx_prop _ -> "a datalog proposition"
8888+ | Value.Dx_sequent _ -> "a datalog sequent"
8989+ | Value.Dx_query _ -> "a datalog query"
9090+ | Value.Dx_var _ -> "a datalog variable"
9191+ | Value.Dx_const _ -> "a datalog constant"
9292+ | Value.Sym _ -> "a symbol"
9393+ | Value.Obj _ -> "an object"
9494+ in
8495 let labels =
8596 range
8697 |> Option.fold ~none:[] ~some:(fun range ->
8798 match got with
8888- | Some (Value.Clo _) ->
9999+ | Some (Clo _) ->
89100 [
90101 Label.createf ~range ~priority:Primary
91102 "This is a function. Did you forget to provide some arguments?";
92103 ]
9393- | Some got ->
104104+ | Some (Obj _) ->
94105 [
9595- Label.createf ~range ~priority:Primary "this value is of type %a"
9696- Value.pp got;
106106+ Label.createf ~range ~priority:Primary
107107+ "This is an object. Did you forget to bind this object to an \
108108+ identifier?";
97109 ]
110110+ | Some got ->
111111+ [Label.createf ~range ~priority:Primary "this is %s" (show_value got)]
98112 | None -> [])
99113 in
114114+ let got_note =
115115+ match range with
116116+ | None ->
117117+ Option.fold got
118118+ ~some:(fun got -> [Message.createf "this is %s" (show_value got)])
119119+ ~none:[]
120120+ | Some _ -> []
121121+ in
100122 let notes =
101123 match expected with
102124 | [] -> []
···109131 ]
110132 in
111133 let msg = Message.createf "mismatched type" in
112112- Diagnostic.create Error ~code:`Type_error ~labels ~notes msg
134134+ Diagnostic.create Error ~code:`Type_error ~labels ~notes:(got_note @ notes)
135135+ msg
113136114137(*
115138 Diagnostic.Label.createf ~range ~priority:Diagnostic.Priority.Primary
···173196 Diagnostic.createf ~code:`Config_error Error "directory %s does not exist" s
174197 | Missing_file s ->
175198 Diagnostic.createf ~code:`Config_error Error "file %s does not exist" s
176176- | Todo -> Diagnostic.createf Error "todo"
177199178200let render_latex_error ({range; msg} : latex_error) =
179201 Diagnostic.create Error
···221243 | Io_error error -> render_io_error error
222244 | Configuration_error error -> render_config_error error
223245 | LaTeX_error error -> render_latex_error error
224224- | Duplicate_tree _uri -> Diagnostic.createf Error "todo"
246246+ | Duplicate_tree uri ->
247247+ Diagnostic.createf Error "duplicate tree %a" URI.pp uri
225248 | Broken_link link -> render_broken_link link
226249 | Broken_transclusion t -> render_broken_transclusion t
227250 | Unlinked_attribution_warning w -> render_unlinked_attribution_warning w
228228- | Failed_to_load_foreign_blob _ -> failwith "todo"
229229- | Failed_to_parse_foreign_blob _ -> failwith "todo"
230230- | Failed_to_add_edge (_, _) -> failwith "todo"
231231- | Unknown_error _ -> failwith "todo"
251251+ | Failed_to_load_foreign_blob _ -> failwith "failed to load foreign blob"
252252+ | Failed_to_parse_foreign_blob _ -> failwith "failed to parse foreign bob"
253253+ | Failed_to_add_edge (_, _) -> failwith "failed to add edge"
254254+ | Unknown_error _ -> failwith "unknown error"
232255233256(*
234257 let corrected = "\\tag/content" in
+8-7
lib/compiler/Eval.ml
···375375 | Some addr -> Some (URI.named_uri ~base:env.config.url addr)
376376 | None -> None
377377 in
378378- let* subtree = eval_tree_inner ~env ?uri nodes in
378378+ let* subtree = eval_tree_inner ~env ~range ?uri nodes in
379379 let frontmatter = env.frontmatter in
380380 let subtree =
381381 {
···727727 match c with
728728 | Content content when T.strip_whitespace content = T.Content [] -> ok v
729729 | v' ->
730730- let expected = [] in
730730+ let expected = [Content] in
731731 let got = Some v' in
732732 type_error ~got ~expected ~range
733733 end
···765765and emit_content_node ~env ~range content =
766766 emit_content_nodes ~env ~range [content]
767767768768-and eval_tree_inner ~env ?(uri : URI.t option) (syn : Syn.t) :
768768+and eval_tree_inner ~env ~range ?(uri : URI.t option) (syn : Syn.t) :
769769 (T.content T.article, _) result =
770770 let attribution_is_author attr =
771771 match T.(attr.role) with T.Author -> true | _ -> false
···782782 let env = {env with frontmatter = ref frontmatter} in
783783 let* mainmatter =
784784 let* value = eval_tape ~env syn in
785785- extract_content {value; range = None}
785785+ extract_content {value; range}
786786 in
787787 let frontmatter = env.frontmatter.contents in
788788 let backmatter =
···794794 config:Config.t ->
795795 uri:URI.t ->
796796 source_path:string option ->
797797- Syn.t ->
797797+ Tree.(expanded tree) ->
798798 eval_result option * Error.t list =
799799- fun ~config ~uri ~source_path tree ->
799799+ fun ~config ~uri ~source_path {tree = {nodes; _}; source; _} ->
800800 let res = ref None in
801801 let errors =
802802 let@ () = Error.collect in
803803 let fm = T.default_frontmatter ~uri ?source_path () in
804804 let env = initial_eval_env config (ref fm) in
805805- match eval_tree_inner ~env ~uri tree with
805805+ let range = Option.map Range.(fun source -> total ~source) source in
806806+ match eval_tree_inner ~range ~env ~uri nodes with
806807 | Error error -> Error.yield_eval_error error
807808 | Ok main ->
808809 let side = env.emitted_trees |> Stack.to_seq |> List.of_seq in
+8-6
lib/compiler/Expand.ml
···10821082let initial_visible_trie : (Syn.resolver_data, Range.t option) Trie.t =
10831083 Yuujinchou.Trie.of_seq builtins
1084108410851085-let expand_tree_inner ~forest (code : Tree.code) : Tree.syn =
10851085+let expand_tree_inner ~forest (code : Tree.(parsed tree)) : Tree.(expanded tree)
10861086+ =
10861087 let@ () = Sc.section [] in
10871087- let nodes = expand_eff ~forest code.nodes in
10881088- let exports = Sc.get_export () in
10891089- Tree.{nodes; identity = code.identity; code; units = exports}
10881088+ let nodes = expand_eff ~forest Tree.(nodes code) in
10891089+ let units = Sc.get_export () in
10901090+ let tree : Tree.expanded = {nodes; code = Tree.nodes code; units} in
10911091+ Tree.{tree; source = code.source; phase = Expanded}
1090109210911091-let expand_tree ~(forest : State.t) (code : Tree.code) : Tree.syn * Error.t list
10921092- =
10931093+let expand_tree ~(forest : State.t) (code : Tree.(parsed tree)) :
10941094+ Tree.(expanded tree) * Error.t list =
10931095 let result = ref None in
10941096 let errors =
10951097 let@ () = Error.collect in
···2424 Dir_scanner.scan_directory tree_dir |> Seq.map Imports.load_tree
25252626let parse (forest : State.t) =
2727- let trees = forest.index |> URI.Tbl.to_seq_values |> List.of_seq in
2828- let results =
2929- let@ tree = List.filter_map @~ trees in
2727+ let trees = forest.index |> URI.Tbl.to_seq |> List.of_seq in
2828+ let@ uri, result =
2929+ List.partition_map
3030+ @~
3131+ let@ uri, Tree tree = List.filter_map @~ trees in
3032 match tree with
3131- | Document doc -> Some (Parse.parse_document ~config:forest.config doc)
3232- | Parsed _ | Expanded _ | Resource _ -> None
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
3338 in
3434- let@ result = List.partition_map @~ results in
3535- match result with Ok t -> Right t | Error d -> Left d
3939+ match result with Ok tree -> Right (uri, tree) | Error e -> Left (uri, e)
36403741let reparse (doc : Lsp.Text_document.t) (forest : State.t) =
3842 Logs.debug (fun m -> m "reparsing");
···4044 URI_scheme.lsp_uri_to_uri ~base:forest.config.url
4145 @@ Lsp.Text_document.documentUri doc
4246 in
4343- begin match Parse.parse_document ~config:forest.config doc with
4747+ begin match Parse.parse_document doc with
4448 | Ok code ->
4545- forest.={uri} <- Parsed code;
4646- Imports.fixup code forest
4949+ forest.={uri} <- Tree code;
5050+ Imports.fixup ~uri code forest
4751 | Error d -> forest.?{uri} <- [Error.parse_error d]
4848- end;
4949- forest
5252+ end
50535154let build_import_graph ~(forest : State.t) : _ * _ = Imports.build forest
5255···6568 | Some tree ->
6669 let expanded, errors = Expand.expand_tree ~forest tree in
6770 diagnostics := errors @ !diagnostics;
6868- forest.={uri} <- Expanded expanded;
7171+ forest.={uri} <- Tree expanded;
6972 forest.?{uri} <- errors
7073 | None ->
7174 Logs.debug (fun m -> m "expanding: no source code for %a" URI.pp uri);
···100103 match guess_uri (Error.tex_range tex_error) with
101104 | None -> assert false
102105 | Some uri ->
103103- let uri = Tree.of_lsp_uri ~base:forest.config.url uri in
106106+ let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri in
104107 forest.?{uri} <- [Error.of_tex_error tex_error]
105108 end
106109 end
107110108111let eval (forest : State.t) =
109109- let expanded_trees =
110110- State.get_all_unevaluated ~forest
111111- |> Seq.filter Tree.is_expanded
112112- |> List.of_seq
113113- in
112112+ let expanded_trees = State.get_all_expanded ~forest |> List.of_seq in
114113 let errors, results =
115115- let@ expanded = List.partition_map @~ expanded_trees in
116116- let tree = Option.get @@ Tree.to_syn expanded in
117117- match identity_to_uri tree.identity with
118118- | None -> left [Error.cant_eval_anonymous_tree]
119119- | Some uri ->
120120- let source_path =
121121- if forest.dev then URI.Tbl.find_opt forest.resolver uri else None
122122- in
123123- right Eval.(eval_tree ~config:forest.config ~source_path ~uri tree.nodes)
114114+ let@ uri, tree = List.partition_map @~ expanded_trees in
115115+ let source_path =
116116+ if forest.dev then URI.Tbl.find_opt forest.resolver uri else None
117117+ in
118118+ right Eval.(eval_tree ~config:forest.config ~source_path ~uri tree)
124119 in
125120 let results, additional_errors =
126121 let organize =
···133128let eval_only (uri : URI.t) (forest : State.t) =
134129 match forest.={uri} with
135130 | None -> assert false
136136- | Some (Document _) -> assert false
137137- | Some (Parsed _) | Some (Resource _) -> assert false
138138- | Some (Expanded expanded) ->
139139- let source_path =
140140- if forest.dev then URI.Tbl.find_opt forest.resolver uri else None
141141- in
142142- (* TODO: run jobs. *)
143143- let result, errors =
144144- Eval.eval_tree ~config:forest.config ~source_path ~uri expanded.nodes
145145- in
146146- forest.?{uri} <- errors;
147147- let@ {articles; _} = Option.iter @~ result in
148148- let@ article = List.iter @~ articles in
149149- State.plant_resource ~forest (Article article)
131131+ | Some (Tree ({phase; _} as t)) -> begin
132132+ match phase with
133133+ | Loaded | Parsed | Evaluated -> assert false
134134+ | Expanded ->
135135+ let source_path =
136136+ if forest.dev then URI.Tbl.find_opt forest.resolver uri else None
137137+ in
138138+ (* TODO: run jobs. *)
139139+ let result, errors =
140140+ Eval.eval_tree ~config:forest.config ~source_path ~uri t
141141+ in
142142+ forest.?{uri} <- errors;
143143+ let@ {articles; _} = Option.iter @~ result in
144144+ let@ article = List.iter @~ articles in
145145+ State.plant_resource ~forest (Article article)
146146+ end
150147151148let implant ~(forest : State.t) (foreign : Config.foreign) =
152149 let* path =
+57-92
lib/compiler/State.ml
···77open Forester_core
88open Tree
99open Forester_core
1010-open Grace
11101211open struct
1312 module T = Types
···7675 match state.={uri} with
7776 | None -> URI.Tbl.replace state.index uri tree
7877 | Some existing ->
7979- if Tree.origin tree <> Tree.origin existing then
7878+ if
7979+ Option.(compare Grace.Source.compare)
8080+ (Tree.source tree) (Tree.source existing)
8181+ = 0
8282+ && Tree.(equal_phases tree existing)
8383+ then
8084 let () = state.?{uri} <- [Error.duplicate_tree ~uri] in
8185 URI.Tbl.replace state.index uri tree
8286 else URI.Tbl.replace state.index uri tree
···8690 let ( ./{} ) state uri =
8791 Option.bind (URI.Tbl.find_opt state.index uri) Tree.get_units
88929393+ (*
8994 (* updating units*)
9095 let ( ./{}<- ) state uri units : _ result =
9196 match URI.Tbl.find_opt state.index uri with
···100105 | Some (Expanded expanded) ->
101106 ok @@ URI.Tbl.replace state.index uri (Expanded {expanded with units})
102107 | Some (Resource _) -> Ok ()
108108+ *)
103109104110 (* @ for article/resource *)
105111 let ( .@{} ) state uri =
106112 match URI.Tbl.find_opt state.index uri with
107107- | Some (Document _) -> None
108108- | Some (Parsed _) | Some (Expanded _) | None -> None
109109- | Some (Resource res) -> Some res.resource
113113+ | Some (Tree {phase = Evaluated; tree; _}) -> Some tree.resource
114114+ | _ -> None
110115end
111116112117open Syntax
···121126 forest.index |> URI.Tbl.to_seq_values |> Seq.filter is_unparsed
122127123128let get_all_code ~forest =
124124- forest.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_code
129129+ forest.index |> URI.Tbl.to_seq
130130+ |> Seq.filter_map (fun (uri, code) ->
131131+ match to_code code with
132132+ | None -> None
133133+ | Some code -> Some (uri, nodes code))
125134126135let get_all_unexpanded ~forest =
127136 forest.index |> URI.Tbl.to_seq_values |> Seq.filter is_unexpanded
128137129138let get_all_expanded ~forest =
130130- forest.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_syn
139139+ forest.index |> URI.Tbl.to_seq
140140+ |> Seq.filter_map (fun (uri, tree) ->
141141+ match to_syn tree with None -> None | Some tree -> Some (uri, tree))
131142132143let get_all_unevaluated ~forest =
133133- forest.index |> URI.Tbl.to_seq_values |> Seq.filter is_unevaluated
144144+ forest.index |> URI.Tbl.to_seq
145145+ |> Seq.filter_map (fun (uri, tree) ->
146146+ if is_unevaluated tree then Some (uri, tree) else None)
134147135148let get_all_articles : t -> T.content T.article Seq.t =
136149 fun state -> state.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_article
···151164let get_article : forest:t -> URI.t -> T.content T.article option =
152165 fun ~forest uri ->
153166 match URI.Tbl.find_opt forest.index uri with
154154- | None | Some (Document _) | Some (Parsed _) | Some (Expanded _) -> None
155155- | Some (Resource {resource; _}) -> (
156156- match resource with T.Article a -> Some a | _ -> None)
167167+ | None -> None
168168+ | Some tree -> Tree.to_article tree
169169+170170+let resolve ~forest ~uri = URI.Tbl.find_opt forest.resolver uri
157171158172let section_symbol = "§"
159173···260274 | None -> Not_found {suggestion = URI.Tbl.find_opt forest.suggestions uri}
261275 ))
262276263263-let plant_resource ?(route_locally = true) ?(include_in_manifest = true)
264264- resource ~forest =
277277+let plant_resource :
278278+ ?route_locally:bool ->
279279+ ?include_in_manifest:bool ->
280280+ T.content T.resource ->
281281+ forest:t ->
282282+ unit =
283283+ fun ?(route_locally = true) ?(include_in_manifest = true) resource ~forest ->
265284 let module Graphs = (val forest.graphs) in
266285 Forest.analyse_resource forest.graphs resource;
267286 let@ uri = Option.iter @~ T.uri_for_resource resource in
287287+ Logs.debug (fun m -> m "planting resource %a" URI.pp uri);
268288 let uri = URI.canonicalise uri in
269289 (* Seems dodgy if this isn't already canonical! *)
270290 Graphs.register_uri uri;
···279299 match forest.={uri} with
280300 | None ->
281301 forest.={uri} <-
282282- Resource {resource; expanded = None; route_locally; include_in_manifest}
283283- | Some (Tree.Expanded syn) ->
284284- forest.={uri} <-
285285- Resource
286286- {resource; expanded = Some syn; route_locally; include_in_manifest}
287287- | _ ->
288288- forest.={uri} <-
289289- Resource {resource; expanded = None; route_locally; include_in_manifest}
290290-291291-let serialize_graphs : (module Forest_graphs.S) -> 'a =
292292- fun s ->
293293- let module Graphs = (val s) in
294294- Graphs.dl_db
295295-296296-let batch_write : t -> _ = function
297297- | {import_graph; _} ->
298298- (* let dl_db = serialize_graphs graphs in *)
299299- let open Cache in
300300- let module Gmap = Forest_graph.Map (Cache.Dependecy_graph) in
301301- let tbl = Dependency_tbl.create 100 in
302302- let now = Unix.time () in
303303- let g =
304304- import_graph
305305- |> Gmap.map @@ function
306306- | T.Content_vertex _ ->
307307- (*Import graph has no content vertices*)
308308- assert false
309309- | T.Uri_vertex uri ->
310310- let item = Item.Tree uri in
311311- Dependency_tbl.add tbl item
312312- Item.{timestamp = Some now; color = Green};
313313- item
314314- in
315315- {Cache.empty with graph = g; tbl}
316316-317317-let reconstruct =
318318- fun ~env:_ ~(_config : Config.t) paths cache ->
319319- match cache with
320320- | {search_index = _; _} ->
321321- (* let init = Phases.init ~env ~config ~dev: true in *)
322322- (* let graphs = Forest_graphs.init dl_db in *)
323323- paths
324324- |> Seq.iter (fun _path ->
325325- (* let uri = URI_scheme.path_to_uri ~base: config.url (Eio.Path.native_exn path) in *)
326326- (* match URI.Tbl.find_opt forest uri with *)
327327- (* | None -> () *)
328328- (* | Some tree -> *)
329329- (* match check_timestamp path tree.timestamp with *)
330330- (* | _ -> () *)
331331- ())
332332-333333-let rec lsp_uri_of_uri (uri : URI.t) (forest : t) : Lsp.Uri.t option =
334334- let@ tree = Option.bind @@ find_opt forest uri in
335335- lsp_uri_of_tree tree forest
336336-337337-and lsp_uri_of_tree (tree : Tree.t) (forest : t) : Lsp.Uri.t option =
338338- match tree with
339339- | Document doc -> Some (Lsp.Text_document.documentUri doc)
340340- | Parsed code -> lsp_uri_of_origin code.origin forest
341341- | Expanded syn -> lsp_uri_of_identity syn.identity forest
342342- | Resource evaluated -> lsp_uri_of_resource evaluated.resource
343343-344344-and lsp_uri_of_resource (resource : resource) : Lsp.Uri.t option =
345345- match resource with
346346- | Article article ->
347347- Option.map Lsp.Uri.of_string article.frontmatter.source_path
348348- | Asset _ | Syndication _ -> None
349349-350350-and lsp_uri_of_origin (origin : origin) (forest : t) : Lsp.Uri.t option =
351351- match origin with
352352- | Physical document -> Some (Lsp.Text_document.documentUri document)
353353- | Subtree {parent} -> lsp_uri_of_identity parent forest
354354- | Undefined -> None
355355-356356-and lsp_uri_of_identity (identity : identity) (forest : t) : Lsp.Uri.t option =
357357- match identity with URI uri -> lsp_uri_of_uri uri forest | Anonymous -> None
358358-359359-let source_path_of_uri uri forest =
360360- Option.map Lsp.Uri.to_path @@ lsp_uri_of_uri uri forest
302302+ Tree
303303+ {
304304+ phase = Evaluated;
305305+ tree = {resource; route_locally; include_in_manifest; expanded = None};
306306+ source = None;
307307+ }
308308+ | Some (Tree {phase; tree; source}) -> begin
309309+ match phase with
310310+ | Expanded ->
311311+ forest.={uri} <-
312312+ Tree
313313+ {
314314+ phase = Evaluated;
315315+ tree =
316316+ {
317317+ resource;
318318+ route_locally;
319319+ include_in_manifest;
320320+ expanded = Some tree;
321321+ };
322322+ source;
323323+ }
324324+ | Loaded | Evaluated | Parsed -> assert false
325325+ end
···20202121let identity_to_uri = function URI uri -> Some uri | Anonymous -> None
22222323-type origin =
2323+(* TODO: Just replace this with Grace's source type *)
2424+type _origin =
2425 | Physical of
2526 (Lsp.Text_document.t
2627 [@printer
···10101111type t = Range.t
12121313+let total ~source =
1414+ let eos_index = Byte_index.of_int @@ Source.length source in
1515+ create ~source Byte_index.initial eos_index
1616+1317let t =
1418 let module T = struct
1519 let byte_index =
···5357 end in
5458 T.repr
55595656-type 'a located = {value: 'a; range: t option}
6060+type 'a really_located = {value: 'a; range: t}
6161+type 'a located = {value: 'a; range: t option} [@@deriving show]
6262+6363+let builtin =
6464+ initial
6565+ (`Reader {id = 0; length = 0; name = None; unsafe_get = (fun _ -> ' ')})
57665867let unloc a = {value = a; range = None}
5968let get_value {value; _} = value
60696161-let pp_located pp_arg fmt (x : 'a located) = pp_arg fmt x.value
7070+(*let pp_located pp_arg fmt (x : 'a located) = pp_arg fmt x.value*)
6271let map : type a b. (a -> b) -> a located -> b located =
6372 fun f node -> {node with value = f node.value}
6473
+139-105
lib/core/Tree.ml
···44 * SPDX-License-Identifier: GPL-3.0-or-later
55 *)
6677-open Grace
87open Forester_prelude
98109open struct
···15141615type exports = (R.P.data, Grace.Range.t option) Trie.t
17161818-type code = {
1919- nodes: Code.t;
2020- identity: identity;
2121- origin: origin;
2222- (* document: Lsp.Text_document.t; [@opaque] *)
2323- timestamp: float option;
2424-}
2525-[@@deriving show]
1717+type loaded = Lsp.Text_document.t
1818+type parsed = Code.t
26192727-type syn = {
2828- nodes: Syn.t;
2929- code: code;
3030- identity: identity;
3131- units: exports; [@opaque]
3232-}
2020+type expanded = {nodes: Syn.t; code: Code.t; units: exports [@opaque]}
3321[@@deriving show]
34223523type evaluated = {
3624 resource: T.content T.resource;
3725 route_locally: bool;
3826 include_in_manifest: bool;
3939- expanded: syn option;
2727+ expanded: expanded option;
4028}
4129[@@deriving show]
42304343-type t =
4444- | Document of (Lsp.Text_document.t[@opaque])
4545- | Parsed of code
4646- | Expanded of syn
4747- | Resource of evaluated
4848-[@@deriving show]
3131+type 'a tag =
3232+ | Loaded : loaded tag
3333+ | Parsed : parsed tag
3434+ | Expanded : expanded tag
3535+ | Evaluated : evaluated tag
49365050-let origin = function
5151- | Document doc -> Physical doc
5252- | Parsed parsed -> parsed.origin
5353- | Expanded expanded -> expanded.code.origin
5454- | Resource resource -> (
5555- match resource.expanded with
5656- | None -> Undefined
5757- | Some expanded -> expanded.code.origin)
3737+type 'a tree = {phase: 'a tag; tree: 'a; source: Grace.Source.t option}
58385959-let show_phase = function
6060- | Document _ -> "document"
6161- | Parsed _ -> "parsed"
6262- | Expanded _ -> "expanded"
6363- | Resource _ -> "resource"
3939+type t = Tree : 'a tree -> t
64406565-let of_lsp_uri ~base uri = URI_scheme.lsp_uri_to_uri ~base uri
4141+let source : t -> Grace.Source.t option = function
4242+ | Tree {phase; tree; source} -> source
66436767-(* IDK if subtrees should resolve to their parent document*)
6868-let to_doc : t -> Lsp.Text_document.t option = function
6969- | Document doc -> Some doc
7070- | Resource {expanded; _} -> begin
7171- match expanded with
7272- | None -> None
7373- | Some {code; _} -> (
7474- match code.origin with
7575- | Physical doc -> Some doc
7676- | Subtree _ -> None
7777- | Undefined -> None)
4444+let equal_phases =
4545+ fun (Tree {phase = phase1; _}) (Tree {phase = phase2; _}) ->
4646+ match (phase1, phase2) with
4747+ | Loaded, Loaded -> true
4848+ | Parsed, Parsed -> true
4949+ | Expanded, Expanded -> true
5050+ | Evaluated, Evaluated -> true
5151+ | _ -> false
5252+5353+let lsp_uri : loaded tree -> Lsp.Uri.t = function
5454+ | {phase; tree; source} -> Lsp.Text_document.documentUri tree
5555+5656+let to_doc : t -> loaded option = function
5757+ | Tree {phase; tree; source} -> begin
5858+ match phase with
5959+ | Loaded -> Some tree
6060+ | Parsed -> None
6161+ | Expanded -> None
6262+ | Evaluated -> None
7863 end
7979- | Parsed {origin; _} | Expanded {code = {origin; _}; _} -> (
8080- match origin with
8181- | Physical doc -> Some doc
8282- | Subtree _ -> None
8383- | Undefined -> None)
6464+6565+let of_code : source:Grace.Source.t -> Code.t -> Code.t tree =
6666+ fun ~source nodes -> {phase = Parsed; tree = nodes; source = Some source}
6767+6868+let of_doc : Lsp.Text_document.t -> loaded tree =
6969+ fun doc ->
7070+ let uri = Lsp.Text_document.documentUri doc in
7171+ let path = Lsp.Uri.to_path uri in
7272+ {phase = Loaded; tree = doc; source = Some (`File path)}
7373+7474+let of_syn ~source syn = {phase = Expanded; tree = syn; source}
7575+let of_resource ~source resource = {phase = Evaluated; tree = resource; source}
7676+7777+let show_phase = function
7878+ | Loaded -> "loaded"
7979+ | Parsed -> "parsed"
8080+ | Expanded -> "expanded"
8181+ | Evaluated -> "evaluated"
84828583let to_resource : t -> T.content T.resource option = function
8686- | Document _ | Parsed _ | Expanded _ -> None
8787- | Resource {resource; _} -> Some resource
8484+ | Tree {phase; tree; _} -> begin
8585+ match phase with
8686+ | Loaded -> None
8787+ | Parsed -> None
8888+ | Expanded -> None
8989+ | Evaluated -> Some tree.resource
9090+ end
88918992let to_evaluated : t -> evaluated option = function
9090- | Document _ | Parsed _ | Expanded _ -> None
9191- | Resource evaluated -> Some evaluated
9393+ | Tree {phase; tree; _} -> begin
9494+ match phase with
9595+ | Loaded | Parsed | Expanded -> None
9696+ | Evaluated -> Some tree
9797+ end
92989399let to_article : t -> T.content T.article option = function
9494- | Document _ | Parsed _ | Expanded _ -> None
9595- | Resource {resource; _} -> (
9696- match resource with T.Article a -> Some a | _ -> None)
100100+ | Tree {phase; tree; _} -> begin
101101+ match phase with
102102+ | Loaded | Parsed | Expanded -> None
103103+ | Evaluated -> begin
104104+ match tree.resource with T.Article a -> Some a | _ -> None
105105+ end
106106+ end
9710798108let get_frontmatter : t -> T.content T.frontmatter option = function
9999- | Resource {resource = Types.Article {frontmatter; _}; _} -> Some frontmatter
100100- | _ -> None
109109+ | Tree {phase; tree; _} -> begin
110110+ match phase with
111111+ | Evaluated -> begin
112112+ match tree with
113113+ | {resource = Types.Article {frontmatter; _}; _} -> Some frontmatter
114114+ | _ -> None
115115+ end
116116+ | _ -> None
117117+ end
101118102102-let to_code : t -> code option = function
103103- | Document _doc ->
104104- (* Logs.debug (fun m -> m "tried to get code of unparsed document %s" (Lsp.Uri.to_string @@ Lsp.Text_document.documentUri doc)); *)
105105- (* assert false *)
106106- None
107107- | Parsed code -> Some code
108108- | Resource {expanded; _} -> begin
109109- match expanded with None -> None | Some {code; _} -> Some code
119119+let to_code : t -> Code.t tree option = function
120120+ | Tree ({phase; tree; source} as t) -> begin
121121+ match phase with
122122+ | Loaded -> None
123123+ | Parsed -> Some t
124124+ | Evaluated -> begin
125125+ match tree.expanded with
126126+ | None -> None
127127+ | Some tree -> Some {phase = Parsed; tree = tree.code; source}
128128+ end
129129+ | Expanded -> Some {phase = Parsed; tree = tree.code; source}
110130 end
111111- | Expanded {code; _} -> Some code
112131113113-let to_syn : t -> syn option = function
114114- | Document _ -> None
115115- | Parsed _ -> None
116116- | Expanded syn -> Some syn
117117- | Resource {expanded; _} -> expanded
132132+let nodes : Code.t tree -> Code.t = function {tree; _} -> tree
118133119119-let get_units : t -> exports option =
120120- fun item ->
121121- match item with
122122- | Document _ -> None
123123- | Parsed _ -> None
124124- | Expanded {units; _} -> Some units
125125- | Resource {expanded; _} -> (
126126- match expanded with Some {units; _} -> Some units | None -> None)
134134+let to_syn : t -> expanded tree option = function
135135+ | Tree {phase; tree; source} -> begin
136136+ match phase with
137137+ | Loaded -> None
138138+ | Parsed -> None
139139+ | Expanded -> Some {phase = Expanded; tree; source}
140140+ | Evaluated -> (
141141+ match tree.expanded with
142142+ | Some expanded -> Some {tree = expanded; phase = Expanded; source}
143143+ | None -> None)
144144+ end
127145128128-let is_unparsed = function Document _ -> true | _ -> false
129129-let is_parsed t = not @@ is_unparsed t
146146+let get_units : t -> exports option = function
147147+ | Tree {phase; tree; _} -> (
148148+ match phase with
149149+ | Loaded -> None
150150+ | Parsed -> None
151151+ | Expanded -> Some tree.units
152152+ | Evaluated -> begin
153153+ match tree.expanded with Some {units; _} -> Some units | None -> None
154154+ end)
155155+156156+let is_unparsed = function
157157+ | Tree {phase; _} -> begin match phase with Loaded -> true | _ -> false end
158158+159159+let is_parsed tree = not @@ is_unparsed tree
130160131161let is_unexpanded = function
132132- | Document _ | Parsed _ -> true
133133- | Expanded _ | Resource _ -> false
162162+ | Tree {phase; _} -> begin
163163+ match phase with Loaded | Parsed -> true | Expanded | Evaluated -> false
164164+ end
134165135135-let is_expanded : t -> bool = function
136136- | Document _ | Parsed _ -> false
137137- | Expanded _ -> true
138138- | Resource {expanded; _} -> Option.is_some expanded
166166+let is_expanded tree = not @@ is_unexpanded tree
139167140168let is_unevaluated = function
141141- | Document _ | Parsed _ | Expanded _ -> true
142142- | Resource _ -> false
169169+ | Tree {phase; _} -> begin
170170+ match phase with Loaded | Parsed | Expanded -> true | Evaluated -> false
171171+ end
143172144144-let is_asset = function
145145- | Document _ | Parsed _ | Expanded _ -> false
146146- | Resource {resource; _} -> (
147147- match resource with T.Asset _ -> true | _ -> false)
173173+let is_asset : t -> bool = function
174174+ | Tree {phase; tree; _} -> begin
175175+ match phase with
176176+ | Loaded | Parsed | Expanded -> false
177177+ | Evaluated -> begin
178178+ match tree.resource with T.Asset _ -> true | _ -> false
179179+ end
180180+ end
148181149149-let update_units : t -> exports -> (t, [`Internal_error] Diagnostic.t) result =
150150- fun item units ->
151151- match item with
152152- | Document _ | Parsed _ ->
182182+let update_units : type a.
183183+ a tree -> exports -> (a tree, [`Internal_error] Diagnostic.t) result =
184184+ fun ({phase; tree; _} as t) units ->
185185+ match phase with
186186+ | Loaded | Parsed ->
153187 error
154188 @@ Diagnostic.createf Error ~code:`Internal_error
155189 "can't update units for this item. It has not been expanded yet"
156156- | Expanded e -> ok @@ Expanded {e with units}
157157- | Resource ({expanded; _} as e) -> (
158158- match expanded with
190190+ | Expanded -> ok @@ {t with tree = {tree with units}}
191191+ | Evaluated -> (
192192+ match tree.expanded with
159193 | None ->
160194 error
161195 @@ Diagnostic.createf Error ~code:`Internal_error
162196 "can't update units for this item. It is not a tree."
163197 | Some expanded ->
164164- ok @@ Resource {e with expanded = Some {expanded with units}})
198198+ ok @@ {t with tree = {tree with expanded = Some {expanded with units}}})
+1-1
lib/frontend/Legacy_xml_client.ml
···48484949let range ~env =
5050 let@ uri = Option.bind env.uri in
5151- let@ path = Option.map @~ State.source_path_of_uri uri env.forest in
5151+ let@ path = Option.map @~ URI.Tbl.find_opt env.forest.resolver uri in
5252 Range.initial (`File path)
53535454let render_xml_qname qname =
+19-14
lib/frontend/test/Test_transclusion.ml
···3232 let uri = URI.named_uri ~base:config.url "transcludee" in
3333 let index = URI.Tbl.create 10 in
3434 URI.Tbl.add index uri
3535- @@ Tree.Resource
3535+ @@ Tree.Tree
3636 {
3737- resource =
3838- T.Article
3939- {
4040- frontmatter =
4141- T.default_frontmatter
4242- ~uri:(URI.of_string_exn "forest://test/transcludee")
4343- ~title:(T.Content [Text "I am being transcluded"]) ();
4444- mainmatter = Content [Text "Hello"];
4545- backmatter = Content [];
4646- };
4747- expanded = None;
4848- route_locally = true;
4949- include_in_manifest = true;
3737+ phase = Evaluated;
3838+ source = None;
3939+ tree =
4040+ {
4141+ resource =
4242+ T.Article
4343+ {
4444+ frontmatter =
4545+ T.default_frontmatter
4646+ ~uri:(URI.of_string_exn "forest://test/transcludee")
4747+ ~title:(T.Content [Text "I am being transcluded"]) ();
4848+ mainmatter = Content [Text "Hello"];
4949+ backmatter = Content [];
5050+ };
5151+ expanded = None;
5252+ route_locally = true;
5353+ include_in_manifest = true;
5454+ };
5055 };
5156 let forest = {(State.make ~env ~config ~dev:false ()) with index} in
5257 let print_transclusion : T.transclusion -> unit =
+2-2
lib/language_server/Analysis.ml
···120120 in
121121 match Tree.to_code tree with
122122 | None -> None
123123- | Some code -> go ~position code.nodes
123123+ | Some code -> go ~position @@ Tree.nodes code
124124125125let get_enclosing_syn_group ~position tree =
126126 let rec go ~position nodes =
···139139 in
140140 match Tree.to_syn tree with
141141 | None -> None
142142- | Some syn -> go ~position syn.nodes
142142+ | Some syn -> go ~position syn.tree.nodes
143143144144let enclosing_group_start ~position
145145 ~(enclosing_group :
+2-2
lib/language_server/Call_hierarchy.ml
···8181 let uri =
8282 URI_scheme.lsp_uri_to_uri ~base:forest.config.url textDocument.uri
8383 in
8484- match Imports.resolve_uri_to_code forest uri with
8484+ match Imports.resolve_uri_to_code ~forest uri with
8585 | Error _ -> None
8686 | Ok tree ->
8787 let item =
8888- match Analysis.node_at_code ~position tree.nodes with
8888+ match Analysis.node_at_code ~position (Tree.nodes tree) with
8989 | None -> None
9090 | Some {range = _; value} -> (
9191 match value with
+9-17
lib/language_server/Completion.ml
···137137 Option.bind @@ Analysis.enclosing_group_start ~enclosing_group ~position t
138138 in
139139 let@ code = Option.bind code_opt in
140140- Analysis.parent_or_prev_at_code ~position code.nodes
140140+ Analysis.parent_or_prev_at_code ~position @@ Tree.nodes code
141141 in
142142 let syn_context =
143143 let enclosing_group = Analysis.get_enclosing_syn_group in
···145145 Option.bind @@ Analysis.enclosing_group_start ~enclosing_group ~position t
146146 in
147147 let@ syn = Option.bind syn_opt in
148148- Analysis.parent_or_prev_at_syn ~position syn.nodes
148148+ Analysis.parent_or_prev_at_syn ~position syn.tree.nodes
149149 in
150150 completions
151151 |> List.fold_left
···315315 ]
316316317317let visible_completions ~(forest : State.t) ~(position : L.Position.t) :
318318- Tree.code option -> L.CompletionItem.t list = function
319319- | None ->
320320- List.append syntax_completions
321321- @@
322322- let@ path, _ =
323323- List.map @~ List.of_seq @@ Trie.to_seq Expand.initial_visible_trie
324324- in
325325- L.CompletionItem.create ~insertText:"todo" ~label:(String.concat "/" path)
326326- ()
327327- | Some {nodes; _} ->
328328- Analysis.get_visible ~position ~forest nodes
329329- |> Trie.to_seq |> List.of_seq |> List.filter_map make
330330- |> List.append syntax_completions
318318+ Tree.parsed -> L.CompletionItem.t list =
319319+ fun nodes ->
320320+ Analysis.get_visible ~position ~forest nodes
321321+ |> Trie.to_seq |> List.of_seq |> List.filter_map make
322322+ |> List.append syntax_completions
331323332324let date_completions () : L.CompletionItem.t list =
333325 let now = Human_datetime.now () in
···348340 let base = config.url in
349341 let uri = URI_scheme.lsp_uri_to_uri ~base uri in
350342 let* tree = forest.={uri} in
351351- let code = Tree.to_code tree in
343343+ let* code = Tree.to_code tree in
352344 let completion_types = completion_types ~position tree in
353345 let items =
354346 let@ completion = List.concat_map @~ S.to_list completion_types in
···356348 | Addrs -> addr_completions ~forest
357349 | New_addr -> new_addr_completions ~forest
358350 | Assets -> asset_completions ~config
359359- | Visible -> visible_completions ~forest ~position code
351351+ | Visible -> visible_completions ~forest ~position @@ Tree.nodes code
360352 | Date -> date_completions ()
361353 in
362354 Logs.debug (fun m -> m "items: %d" (List.length items));
+1-1
lib/language_server/Definitions.ml
···2020 URI_scheme.lsp_uri_to_uri ~base:forest.config.url params.textDocument.uri
2121 in
2222 let@ tree = Option.bind forest.={uri} in
2323- let@ {nodes; _} = Option.bind @@ Tree.to_code tree in
2323+ let@ nodes = Option.bind Tree.(Option.map nodes @@ to_code tree) in
2424 let@ {value = str; _} =
2525 Option.bind @@ Analysis.addr_at ~position:params.position nodes
2626 in
+5-4
lib/language_server/Did_change.ml
···2929 (Lsp.Uri.to_string lsp_uri));
3030 assert false
3131 | Some doc ->
3232- let new_doc =
3333- Lsp.Text_document.apply_content_changes doc params.contentChanges
3232+ let updated =
3333+ Tree.of_doc
3434+ @@ Lsp.Text_document.apply_content_changes doc params.contentChanges
3435 in
3535- forest.={uri} <- Document new_doc;
3636+ forest.={uri} <- Tree updated;
3637 Lsp_state.modify (fun ({forest; _} as lsp_state) ->
3738 let new_forest = Driver.run_until_done (Action.Parse lsp_uri) forest in
3839 {lsp_state with forest = new_forest});
3939- Diagnostics.compute new_doc
4040+ Diagnostics.compute updated.tree
+1-1
lib/language_server/Did_create_files.ml
···2323 let uri = URI_scheme.lsp_uri_to_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} <- Document doc
2626+ forest.={uri} <- Tree doc
2727 end;
2828 let new_forest = Driver.run_until_done Parse_all forest in
2929 {lsp_state with forest = new_forest}
+3-1
lib/language_server/Did_open.ml
···15151616let compute (params : L.DidOpenTextDocumentParams.t) =
1717 let lsp_uri = params.textDocument.uri in
1818+ let path = Lsp.Uri.to_path lsp_uri in
1819 let Lsp_state.{forest; _} = Lsp_state.get () in
1920 let document = Lsp.Text_document.make ~position_encoding:`UTF16 params in
2021 let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url lsp_uri in
2121- forest.={uri} <- Document document;
2222+ forest.={uri} <-
2323+ Tree {tree = document; source = Some (`File path); phase = Loaded};
2224 Lsp_state.modify (fun ({forest; _} as lsp_state) ->
2325 let new_forest = Driver.run_until_done (Action.Parse lsp_uri) forest in
2426 {lsp_state with forest = new_forest});
+1-1
lib/language_server/Document_link.ml
···3131 match Option.bind forest.={uri} Tree.to_code with
3232 | None -> []
3333 | Some tree -> (
3434- let@ Range.{range; value} = List.filter_map @~ tree.nodes in
3434+ let@ Range.{range; value} = List.filter_map @~ Tree.nodes tree in
3535 match value with
3636 | Code.Group (Squares, [{value = Text addr; _}])
3737 | Code.Group (Parens, [{value = Text addr; _}])
+2-2
lib/language_server/Document_symbols.ml
···2424 @@ URI_scheme.lsp_uri_to_uri ~base:forest.config.url uri
2525 with
2626 | None -> assert false
2727- | Some {nodes; _} ->
2727+ | Some {tree; _} ->
2828 let symbols : L.DocumentSymbol.t list =
2929- let@ {range; value} = List.filter_map @~ nodes in
2929+ let@ {range; value} = List.filter_map @~ tree in
3030 let open Code in
3131 let* range = Option.map Lsp_shims.lsp_range_of_range range in
3232 let selectionRange = range in
+1-1
lib/language_server/Highlight.ml
···1919 URI_scheme.lsp_uri_to_uri ~base:forest.config.url params.textDocument.uri
2020 in
2121 let@ tree = Option.map @~ State.get_code forest uri in
2222- let@ Range.{range; value} = List.filter_map @~ tree.nodes in
2222+ let@ Range.{range; value} = List.filter_map @~ Tree.nodes tree in
2323 let@ range = Option.map @~ range in
2424 let range = Lsp_shims.lsp_range_of_range range in
2525 let kind =
+1-1
lib/language_server/Hover.ml
···3535 URI.pp uri
3636 *)
3737 | Some tree -> (
3838- let* {nodes; _} = Tree.to_code tree in
3838+ let* nodes = Tree.(Option.map nodes @@ to_code tree) in
3939 let* node = Analysis.node_at_code ~position nodes in
4040 let tree_under_cursor =
4141 let* {value = addr; _} = Analysis.extract_addr node in
+3-1
lib/language_server/Inlay_hint.ml
···5252 let uri =
5353 URI_scheme.lsp_uri_to_uri ~base:config.url params.textDocument.uri
5454 in
5555- let@ {nodes; _} = Option.map @~ Option.bind forest.={uri} Tree.to_syn in
5555+ let@ {tree = {nodes; _}; _} =
5656+ Option.map @~ Option.bind forest.={uri} Tree.to_syn
5757+ in
5658 extract_inlayable_hints ~config ~forest nodes
+4-4
lib/language_server/Semantic_tokens.ml
···270270 let uri = URI_scheme.lsp_uri_to_uri ~base:forest.config.url identifier.uri in
271271 Result.to_option
272272 @@
273273- let@ {nodes; _} = Result.map @~ Imports.resolve_uri_to_code forest uri in
274274- let tokens = tokens nodes in
273273+ let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in
274274+ let tokens = tokens @@ Tree.nodes tree in
275275 Format.(
276276 Eio.traceln "%a"
277277 (pp_print_list ~pp_sep:(fun out () -> fprintf out "; ") pp_token)
···288288 in
289289 Result.to_option
290290 @@
291291- let@ tree = Result.map @~ Imports.resolve_uri_to_code forest uri in
292292- semantic_tokens_delta tree.nodes
291291+ let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in
292292+ semantic_tokens_delta @@ Tree.nodes tree
293293294294let on_full_request (params : L.SemanticTokensParams.t) :
295295 L.SemanticTokens.t option =
+1-1
lib/language_server/Workspace_symbols.ml
···110110 let@ file_symbol =
111111 List.concat_map @~ Option.to_list
112112 @@
113113- let@ source_path = Option.map @~ State.source_path_of_uri uri forest in
113113+ let@ source_path = Option.map @~ State.resolve ~forest ~uri in
114114 let lsp_uri = Lsp.Uri.of_string source_path in
115115 let location =
116116 L.Location.
+4-8
lib/parser/Parse.ml
···5151 lexbuf.lex_curr_p <- {lexbuf.lex_curr_p with pos_fname = filename};
5252 parse (`File filename) lexbuf
53535454-let parse_document ~(config : Config.t) doc =
5454+let parse_document doc : (Tree.(parsed tree), _) result =
5555 let uri = Lsp.Text_document.documentUri doc in
5656 let path = Lsp.Uri.to_path uri in
5757 let text = Lsp.Text_document.text doc in
···5959 lexbuf.lex_curr_p <- {lexbuf.lex_curr_p with pos_fname = path};
6060 parse (`String {content = text; name = Some path}) lexbuf
6161 |> Result.map (fun nodes ->
6262- Tree.
6363- {
6464- nodes;
6565- origin = Physical doc;
6666- identity = URI (URI_scheme.path_to_uri ~base:config.url path);
6767- timestamp = Some (Unix.time ());
6868- })
6262+ let source = `File path in
6363+ (*let identity = URI (URI_scheme.path_to_uri ~base:config.url path) *)
6464+ Tree.of_code ~source nodes)
69657066let parse_file filename =
7167 let ch = open_in filename in
···11+open Forester_parser
22+open Forester_core
33+44+let () =
55+ let filename = Sys.argv.(1) in
66+ let result = Parse.parse_file filename in
77+ match result with
88+ | Ok code -> Format.printf "%a@." Code.pp code
99+ | Error _ -> assert false
+15
test/Print_syn.ml
···11+open Forester_core
22+open Forester_parser
33+open Forester_compiler
44+55+let () =
66+ let@ env = Eio_main.run in
77+ let filename = Sys.argv.(1) in
88+ let result = Parse.parse_file filename in
99+ let forest = State.make ~env ~dev:true ~config:Config.(default ()) () in
1010+ match result with
1111+ | Ok code ->
1212+ let tree = Tree.of_code ~source:(`File filename) code in
1313+ let Tree.{tree; _}, _ = Expand.(expand_tree ~forest tree) in
1414+ Format.printf "%a@." Syn.pp tree.nodes
1515+ | Error _ -> assert false