ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Renaming and simplifications in Tree.ml

+115 -141
+1 -1
lib/compiler/Driver.ml
··· 39 39 report ~errors ~and_then:Eval_all 40 40 | Expand uri -> begin 41 41 Option.fold forest.={uri} ~none:(assert false) ~some:begin fun tree -> 42 - match Tree.to_code tree with 42 + match Tree.code tree with 43 43 | None -> assert false 44 44 | Some code -> 45 45 let result, errors = Phases.expand forest code in
+2 -2
lib/compiler/Expand.ml
··· 1085 1085 let expand_tree_inner ~forest (code : Tree.(parsed tree)) : Tree.(expanded tree) 1086 1086 = 1087 1087 let@ () = Sc.section [] in 1088 - let nodes = expand_eff ~forest Tree.(nodes code) in 1088 + let nodes = expand_eff ~forest Tree.Parsed.(nodes code) in 1089 1089 let units = Sc.get_export () in 1090 - let tree : Tree.expanded = {nodes; code = Tree.nodes code; units} in 1090 + let tree : Tree.expanded = {nodes; code = Tree.Parsed.nodes code; units} in 1091 1091 let source = Tree.Parsed.source code in 1092 1092 Tree.Expanded.create ?source tree 1093 1093
+18 -14
lib/compiler/Imports.ml
··· 50 50 result in some errors.*) 51 51 assert (List.is_empty errors); 52 52 match Forest.find_opt forest.index uri with 53 - | Some tree -> begin 54 - match Tree.to_code tree with None -> assert false | Some code -> ok code 55 - end 56 - | None -> begin 57 - match URI.Tbl.find_opt forest.resolver uri with 53 + | Some tree -> 54 + begin match Tree.code tree with 55 + | None -> assert false 56 + | Some code -> ok code 57 + end 58 + | None -> 59 + begin match URI.Tbl.find_opt forest.resolver uri with 58 60 | Some path -> 59 61 let doc = load_tree Eio.Path.(forest.env#fs / path) in 60 62 Result.map_error (Error.parse_error >>> List.singleton) 61 63 @@ Parse.parse_document doc.tree 62 - | None -> begin 63 - match Dir_scanner.find_tree dirs uri with 64 + | None -> 65 + begin match Dir_scanner.find_tree dirs uri with 64 66 | Some path -> 65 67 let native = Eio.Path.native_exn path in 66 68 URI.Tbl.add forest.resolver uri native; ··· 68 70 Result.map_error (Error.parse_error >>> List.singleton) 69 71 @@ Parse.parse_document doc.tree 70 72 | None -> assert false 73 + end 71 74 end 72 - end 73 75 74 76 let rec analyse_tree ~env ~uri code = 75 77 let@ root = Option.iter @~ uri in ··· 88 90 let target = T.Uri_vertex root in 89 91 Forest_graph.add_vertex env.graph dependency; 90 92 assert (Result.is_ok @@ add_edge env.graph dependency target); 91 - if env.follow then begin 92 - match resolve_uri_to_code ~forest:env.forest dep_uri with 93 - | Ok code -> analyse_tree ~env ~uri:(Some dep_uri) Tree.(nodes code) 93 + if env.follow then 94 + begin match resolve_uri_to_code ~forest:env.forest dep_uri with 95 + | Ok code -> 96 + analyse_tree ~env ~uri:(Some dep_uri) Tree.Parsed.(nodes code) 94 97 | Error error -> env.errors <- List.append error env.errors 95 - end 98 + end 96 99 | Subtree (addr, nodes) -> 97 100 let uri = Option.map (URI.named_uri ~base:config.url) addr in 98 101 analyse_tree ~env ~uri nodes ··· 145 148 let new_deps = 146 149 let env = {forest; follow = false; graph; errors = []} in 147 150 begin 148 - analyse_tree ~env ~uri:(Some uri) Tree.(nodes tree); 151 + analyse_tree ~env ~uri:(Some uri) Tree.Parsed.(nodes tree); 149 152 Vertex_set.of_list 150 153 @@ Forest_graph.immediate_dependencies env.graph this_vertex 151 154 end ··· 182 185 {forest; follow = false; graph = Forest_graph.create (); errors = []} 183 186 in 184 187 State.get_all_code ~forest:env.forest 185 - |> Seq.iter (fun (uri, code) -> analyse_tree ~uri:(Some uri) ~env code); 188 + |> List.iter (fun (uri, code) -> 189 + analyse_tree ~uri:(Some uri) ~env Tree.Parsed.(nodes code)); 186 190 (env.errors, env.graph)
+2 -2
lib/compiler/Phases.ml
··· 39 39 40 40 let parse (forest : State.t) uri = 41 41 let open Action in 42 - Option.bind forest.={uri} Tree.to_doc 42 + Option.bind forest.={uri} Tree.document 43 43 |> Option.fold 44 44 ~some:begin fun tree -> 45 45 match Parse.parse_document tree with ··· 98 98 match forest.={uri} with 99 99 | None -> () 100 100 | Some tree -> ( 101 - match Tree.to_code tree with 101 + match Tree.code tree with 102 102 | Some tree -> 103 103 let expanded, errors = Expand.expand_tree ~forest tree in 104 104 diagnostics := errors @ !diagnostics;
+26 -52
lib/compiler/State.ml
··· 85 85 (* URI.Tbl.replace state.index uri item *) 86 86 87 87 (* / for units*) 88 - let ( ./{} ) state uri = 89 - Option.bind (URI.Tbl.find_opt state.index uri) Tree.get_units 88 + let ( ./{} ) state uri = Option.bind state.={uri} Tree.units 90 89 91 90 (* @ for article/resource *) 92 - let ( .@{} ) state uri = 93 - Option.bind (URI.Tbl.find_opt state.index uri) Tree.to_resource 91 + let ( .@{} ) state uri = Option.bind state.={uri} Tree.resource 94 92 end 95 - 96 - open Syntax 97 93 98 94 let update_history ~forest action = 99 95 {forest with history = action :: forest.history} 100 96 101 - let find_opt state uri = URI.Tbl.find_opt state.index uri 102 97 let to_seq state = URI.Tbl.to_seq state.index 103 98 104 - let get_all_unparsed ~forest = 99 + let get_all ~forest f = 105 100 forest.index |> URI.Tbl.to_seq 106 - |> Seq.filter_map (fun (uri, tree) -> 107 - match Tree.to_doc tree with Some doc -> Some (uri, doc) | _ -> None) 101 + |> Seq.filter_map (fun (uri, t) -> 102 + match f t with Some tree -> Some (uri, tree) | _ -> None) 108 103 |> List.of_seq 109 104 110 - let get_all_code ~forest = 111 - forest.index |> URI.Tbl.to_seq 112 - |> Seq.filter_map (fun (uri, code) -> 113 - match to_code code with 114 - | None -> None 115 - | Some code -> Some (uri, nodes code)) 116 - 117 - let get_all_unexpanded ~forest = 118 - forest.index |> URI.Tbl.to_seq_values |> Seq.filter is_unexpanded 119 - 120 - let get_all_expanded ~forest = 105 + let filter ~forest f = 121 106 forest.index |> URI.Tbl.to_seq 122 107 |> Seq.filter_map (fun (uri, tree) -> 123 - match to_syn tree with None -> None | Some tree -> Some (uri, tree)) 108 + if f tree then Some (uri, tree) else None) 124 109 |> List.of_seq 125 110 126 - let get_all_unevaluated ~forest = 127 - forest.index |> URI.Tbl.to_seq 128 - |> Seq.filter_map (fun (uri, tree) -> 129 - if is_unevaluated tree then Some (uri, tree) else None) 130 - 131 - let get_all_articles ~forest = 132 - forest.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_article 133 - 134 - let get_all_evaluated ~forest = 135 - forest.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_evaluated 136 - 137 - let get_all_resources : t -> T.content T.resource Seq.t = 138 - fun state -> state.index |> URI.Tbl.to_seq_values |> Seq.filter_map to_resource 111 + let get_all_unparsed = get_all Tree.document 112 + let get_all_code = get_all Tree.code 113 + let get_all_expanded = get_all Tree.syn 114 + let get_all_articles = get_all Tree.article 115 + let get_all_evaluated = get_all Tree.evaluated 116 + let get_all_resources = get_all Tree.resource 139 117 140 - let get_resource state uri = 141 - match state.={uri} with None -> None | Some tree -> to_resource tree 118 + let get_all_unevaluated = filter Tree.is_unevaluated 119 + let get_all_unexpanded = filter Tree.is_unexpanded 142 120 143 - let get_code state uri = 144 - match state.={uri} with None -> None | Some tree -> to_code tree 121 + open Syntax 145 122 146 - let get_article : forest:t -> URI.t -> T.content T.article option = 147 - fun ~forest uri -> 148 - match URI.Tbl.find_opt forest.index uri with 149 - | None -> None 150 - | Some tree -> Tree.to_article tree 151 - 123 + let get_resource ~forest uri = Option.bind forest.={uri} Tree.resource 124 + let get_code ~forest uri = Option.bind forest.={uri} Tree.code 125 + let get_article ~forest uri = Option.bind forest.={uri} Tree.article 152 126 let resolve ~forest ~uri = URI.Tbl.find_opt forest.resolver uri 153 127 154 128 let section_symbol = "§" ··· 158 132 let short_title = 159 133 match frontmatter.title with 160 134 | Some content -> content 161 - | None when not flags.empty_when_untitled -> begin 162 - match frontmatter.uri with 135 + | None when not flags.empty_when_untitled -> 136 + begin match frontmatter.uri with 163 137 | Some uri -> T.Content [T.Uri uri] 164 138 | _ -> T.Content [T.Text "Untitled"] 165 - end 139 + end 166 140 | _ -> T.Content [] 167 141 in 168 142 Option.value ~default:short_title ··· 221 195 let get_title_or_content_of_vertex ?(not_found = fun _ -> None) vertex forest = 222 196 match vertex with 223 197 | T.Content_vertex content -> Some content 224 - | T.Uri_vertex uri -> begin 225 - match get_article ~forest uri with 198 + | T.Uri_vertex uri -> 199 + begin match get_article ~forest uri with 226 200 | Some article -> article.frontmatter.title 227 201 | None -> not_found uri 228 - end 202 + end 229 203 230 204 (* A list of mistakes that a user might make when typing a given URI. For 231 205 example, they might type "https://www.forester-notes.com/005P" instead of ··· 281 255 let tree = 282 256 Option.fold forest.={uri} 283 257 ~some:begin fun tree -> 284 - let expanded = Tree.to_expanded tree in 258 + let expanded = Tree.syn tree in 285 259 let source = Tree.source tree in 286 260 Tree.Evaluated.create ?source ~route_locally ~include_in_manifest 287 261 ?expanded resource
+3 -3
lib/compiler/test/Test_compiler.ml
··· 51 51 (List.length (State.get_all_unparsed ~forest)); 52 52 Alcotest.(check @@ int) 53 53 "no tree is unexpanded" 0 54 - (Seq.length (State.get_all_unexpanded ~forest)); 54 + (List.length (State.get_all_unexpanded ~forest)); 55 55 Alcotest.(check @@ int) 56 56 "no tree is unevaluated" 0 57 - (Seq.length (State.get_all_unevaluated ~forest)); 57 + (List.length (State.get_all_unevaluated ~forest)); 58 58 Alcotest.(check @@ int) 59 59 "has correct number of articles" 8 60 - (Seq.length (State.get_all_articles ~forest)) 60 + (List.length (State.get_all_articles ~forest)) 61 61 62 62 let test_includes_paths ~env () = 63 63 let config = Config.default () in
+14 -8
lib/core/Tree.ml
··· 47 47 let create : ?source:source -> parsed -> t = 48 48 fun ?source tree -> {tree; phase = Parsed; source} 49 49 let source {source; _} = source 50 + let nodes ({tree; _} : t) = tree 50 51 end 51 52 52 53 module Expanded = struct ··· 61 62 type t = evaluated tree 62 63 let create ~route_locally ~include_in_manifest ?expanded ?source 63 64 (resource : _ T.resource) = 64 - let tree = {resource; route_locally; include_in_manifest; expanded} in 65 + let tree = 66 + let expanded = 67 + match expanded with Some expanded -> Some expanded.tree | None -> None 68 + in 69 + {resource; route_locally; include_in_manifest; expanded} 70 + in 65 71 {tree; phase = Evaluated; source} 66 72 67 73 let source {source; _} = source ··· 105 111 end 106 112 end 107 113 108 - let to_doc : t -> loaded option = function 114 + let document : t -> loaded option = function 109 115 | Tree {phase; tree; _} -> begin 110 116 match phase with Loaded -> Some tree | _ -> None 111 117 end ··· 133 139 end 134 140 | _ -> None 135 141 136 - let to_resource : t -> T.content T.resource option = function 142 + let resource : t -> T.content T.resource option = function 137 143 | Tree {phase; tree; _} -> begin 138 144 match phase with 139 145 | Loaded -> None ··· 150 156 | _ -> None 151 157 end 152 158 153 - let to_evaluated : t -> evaluated option = function 159 + let evaluated : t -> evaluated option = function 154 160 | Tree {phase; tree; _} -> begin 155 161 match phase with 156 162 | Loaded | Parsed | Expanded -> None 157 163 | Evaluated -> Some tree 158 164 end 159 165 160 - let to_article : t -> T.content T.article option = function 166 + let article : t -> T.content T.article option = function 161 167 | Tree {phase; tree; _} -> begin 162 168 match phase with 163 169 | Loaded | Parsed | Expanded -> None ··· 177 183 | _ -> None 178 184 end 179 185 180 - let to_code : t -> Code.t tree option = function 186 + let code : t -> Code.t tree option = function 181 187 | Tree ({phase; tree; source} as t) -> begin 182 188 match phase with 183 189 | Loaded -> None ··· 192 198 193 199 let nodes : Code.t tree -> Code.t = function {tree; _} -> tree 194 200 195 - let to_syn : t -> expanded tree option = function 201 + let syn : t -> expanded tree option = function 196 202 | Tree {phase; tree; source} -> begin 197 203 match phase with 198 204 | Loaded -> None ··· 204 210 | None -> None) 205 211 end 206 212 207 - let get_units : t -> exports option = function 213 + let units : t -> exports option = function 208 214 | Tree {phase; tree; _} -> ( 209 215 match phase with 210 216 | Loaded -> None
+8 -11
lib/frontend/Forester.ml
··· 54 54 55 55 let complete ~(forest : State.t) prefix : (string * string) List.t = 56 56 let config = forest.config in 57 - let@ article = 58 - List.filter_map @~ List.of_seq @@ State.get_all_articles ~forest 59 - in 60 - let@ uri = Option.bind article.frontmatter.uri in 57 + let@ uri, article = List.filter_map @~ State.get_all_articles ~forest in 61 58 let short_uri = URI.display_path_string ~base:config.url uri in 62 59 let@ title = Option.bind article.frontmatter.title in 63 60 let title = Plain_text_client.string_of_content ~forest title in ··· 88 85 let render = Json_manifest_client.render_tree ~forest in 89 86 let articles = 90 87 let@ tree = Seq.filter_map @~ Forest.to_seq_values forest.index in 91 - let@ evaluated = Option.bind @@ Tree.to_evaluated tree in 92 - if evaluated.include_in_manifest then Tree.to_article tree else None 88 + let@ evaluated = Option.bind @@ Tree.evaluated tree in 89 + if evaluated.include_in_manifest then Tree.article tree else None 93 90 in 94 91 articles |> List.of_seq 95 92 |> List.sort (Forest_util.compare_article ~forest) ··· 134 131 let@ vertex = List.filter_map @~ Vertex_set.elements vertices in 135 132 match vertex with 136 133 | Content_vertex _ -> None 137 - | Uri_vertex uri -> State.get_resource forest uri 134 + | Uri_vertex uri -> State.get_resource ~forest uri 138 135 in 139 136 let json_content = 140 137 Repr.to_json_string ~minify:true (T.forest_t T.content_t) resources ··· 173 170 let render_forest ~dev ~emit_legacy_xml ~(forest : State.t) : unit = 174 171 let cwd = Eio.Stdenv.cwd forest.env in 175 172 let all_resources = State.get_all_evaluated ~forest in 176 - Logs.debug (fun m -> m "Rendering %i resources" (Seq.length all_resources)); 173 + Logs.debug (fun m -> m "Rendering %i resources" (List.length all_resources)); 177 174 begin 178 175 let json_string = json_manifest ~dev ~forest in 179 176 let json_path = EP.(output_path ~cwd ~forest / "forest.json") in ··· 188 185 ~path:(uri_to_local_path ~forest forest.config.home) 189 186 in 190 187 let errors, jobs = 191 - all_resources |> List.of_seq 192 - |> Eio.Fiber.List.map ~max_fibers:40 193 - (outputs_for_resource ~forest ~emit_legacy_xml) 188 + all_resources 189 + |> Eio.Fiber.List.map ~max_fibers:40 (fun (_, tree) -> 190 + outputs_for_resource ~forest ~emit_legacy_xml tree) 194 191 |> List.partition_map (function Ok v -> Right v | Error e -> Left e) 195 192 in 196 193 (errors, List.cons [(home_route, home_content)] jobs)
+1 -1
lib/frontend/Legacy_xml_client.ml
··· 29 29 match forest.={uri} with 30 30 | None -> uri 31 31 | Some tree -> begin 32 - match Tree.to_evaluated tree with 32 + match Tree.evaluated tree with 33 33 | Some evaluated when evaluated.route_locally -> 34 34 let path = "" :: local_path_components forest.config uri in 35 35 URI.make ~path ()
+12 -12
lib/language_server/Analysis.ml
··· 111 111 | None -> None 112 112 | Some ({value; range} as node) -> ( 113 113 match value with 114 - | Code.Group (delim, t) -> begin 115 - match go ~position t with 114 + | Code.Group (delim, t) -> 115 + begin match go ~position t with 116 116 | None -> Some Range.{value = (delim, t); range} 117 117 | Some t -> Some t 118 - end 118 + end 119 119 | _ -> (go ~position) (Code.children node)) 120 120 in 121 - match Tree.to_code tree with 121 + match Tree.code tree with 122 122 | None -> None 123 - | Some code -> go ~position @@ Tree.nodes code 123 + | Some code -> go ~position @@ Tree.Parsed.nodes code 124 124 125 125 let get_enclosing_syn_group ~position tree = 126 126 let rec go ~position nodes = ··· 130 130 | None -> None 131 131 | Some ({value; range} as node) -> ( 132 132 match value with 133 - | Syn.Group (delim, children) -> begin 134 - match go ~position children with 133 + | Syn.Group (delim, children) -> 134 + begin match go ~position children with 135 135 | None -> Some Range.{value = (delim, children); range} 136 136 | Some t -> Some t 137 - end 137 + end 138 138 | _ -> go ~position (Syn.children node)) 139 139 in 140 - match Tree.to_syn tree with 140 + match Tree.syn tree with 141 141 | None -> None 142 142 | Some syn -> go ~position syn.tree.nodes 143 143 ··· 172 172 let go ~position ~children nodes = 173 173 match find_with_prev ~position nodes with 174 174 | None -> None 175 - | Some (None, node) -> begin 176 - match (node_at ~position ~children) (children node) with 175 + | Some (None, node) -> 176 + begin match (node_at ~position ~children) (children node) with 177 177 | Some inner -> 178 178 (* go ~position ~children (children inner) *) 179 179 Some (Context.Top inner) 180 180 | None -> Some (Top node) 181 - end 181 + end 182 182 | Some (Some prev, node) -> ( 183 183 match (node_at ~position ~children) (children node) with 184 184 | None -> Some (Prev (prev, node))
+1 -1
lib/language_server/Call_hierarchy.ml
··· 83 83 | Error _ -> None 84 84 | Ok tree -> 85 85 let item = 86 - match Analysis.node_at_code ~position (Tree.nodes tree) with 86 + match Analysis.node_at_code ~position (Tree.Parsed.nodes tree) with 87 87 | None -> None 88 88 | Some {range = _; value} -> ( 89 89 match value with
+7 -8
lib/language_server/Completion.ml
··· 125 125 date_completion; 126 126 ] 127 127 in 128 - let code_opt = Tree.to_code t in 129 - let syn_opt = Tree.to_syn t in 130 - let doc_opt = Tree.to_doc t in 128 + let code_opt = Tree.code t in 129 + let syn_opt = Tree.syn t in 130 + let doc_opt = Tree.document t in 131 131 let text_context = Option.bind doc_opt @@ Analysis.word_before ~position in 132 132 Logs.debug (fun m -> 133 133 m "Text_context: %a" Format.(pp_print_option pp_print_string) text_context); ··· 137 137 Option.bind @@ Analysis.enclosing_group_start ~enclosing_group ~position t 138 138 in 139 139 let@ code = Option.bind code_opt in 140 - Analysis.parent_or_prev_at_code ~position @@ Tree.nodes code 140 + Analysis.parent_or_prev_at_code ~position @@ Tree.Parsed.nodes code 141 141 in 142 142 let syn_context = 143 143 let enclosing_group = Analysis.get_enclosing_syn_group in ··· 280 280 L.CompletionItem.create ~insertText ~label () 281 281 282 282 let addr_completions ~(forest : State.t) : L.CompletionItem.t list = 283 - let articles = List.of_seq @@ State.get_all_articles ~forest in 284 - let@ article = List.filter_map @~ articles in 283 + let@ uri, article = List.filter_map @~ State.get_all_articles ~forest in 285 284 let frontmatter = article.frontmatter in 286 285 let@ _ = Option.bind frontmatter.title in 287 286 let title = State.get_expanded_title frontmatter forest in ··· 340 339 let base = config.url in 341 340 let uri = URI.of_lsp_uri ~base uri in 342 341 let* tree = forest.={uri} in 343 - let* code = Tree.to_code tree in 342 + let* code = Tree.code tree in 344 343 let completion_types = completion_types ~position tree in 345 344 let items = 346 345 let@ completion = List.concat_map @~ S.to_list completion_types in ··· 348 347 | Addrs -> addr_completions ~forest 349 348 | New_addr -> new_addr_completions ~forest 350 349 | Assets -> asset_completions ~config 351 - | Visible -> visible_completions ~forest ~position @@ Tree.nodes code 350 + | Visible -> visible_completions ~forest ~position @@ Tree.Parsed.nodes code 352 351 | Date -> date_completions () 353 352 in 354 353 Logs.debug (fun m -> m "items: %d" (List.length items));
+1 -1
lib/language_server/Definitions.ml
··· 18 18 let Lsp_state.{forest; _} = Lsp_state.get () in 19 19 let uri = URI.of_lsp_uri ~base:forest.config.url params.textDocument.uri in 20 20 let@ tree = Option.bind forest.={uri} in 21 - let@ nodes = Option.bind Tree.(Option.map nodes @@ to_code tree) in 21 + let@ nodes = Option.bind Tree.(Option.map Parsed.nodes @@ code tree) in 22 22 let@ {value = str; _} = 23 23 Option.bind @@ Analysis.addr_at ~position:params.position nodes 24 24 in
+1 -1
lib/language_server/Did_change.ml
··· 19 19 let lsp_uri = params.textDocument.uri in 20 20 let uri = URI.of_lsp_uri ~base:forest.config.url lsp_uri in 21 21 let@ tree = Option.iter @~ forest.={uri} in 22 - match Tree.to_doc tree with 22 + match Tree.document tree with 23 23 | None -> assert false 24 24 | Some doc -> 25 25 let updated =
+2 -2
lib/language_server/Document_link.ml
··· 25 25 let Lsp_state.{forest; _} = Lsp_state.get () in 26 26 let links = 27 27 let uri = URI.of_lsp_uri ~base:config.url params.textDocument.uri in 28 - match Option.bind forest.={uri} Tree.to_code with 28 + match Option.bind forest.={uri} Tree.code with 29 29 | None -> [] 30 30 | Some tree -> ( 31 - let@ Range.{range; value} = List.filter_map @~ Tree.nodes tree in 31 + let@ Range.{range; value} = List.filter_map @~ Tree.Parsed.nodes tree in 32 32 match value with 33 33 | Code.Group (Squares, [{value = Text addr; _}]) 34 34 | Code.Group (Parens, [{value = Text addr; _}])
+3 -3
lib/language_server/Document_symbols.ml
··· 15 15 let ( let* ) = Option.bind 16 16 end 17 17 18 - let compute (params : L.DocumentSymbolParams.t) : 18 + let compute ({textDocument = {uri; _}; _} : L.DocumentSymbolParams.t) : 19 19 [> `DocumentSymbol of L.DocumentSymbol.t list] option = 20 - let uri = params.textDocument.uri in 21 20 let Lsp_state.{forest; _} = Lsp_state.get () in 22 - match State.get_code forest @@ URI.of_lsp_uri ~base:forest.config.url uri with 21 + let uri = URI.of_lsp_uri ~base:forest.config.url uri in 22 + match State.get_code ~forest uri with 23 23 | None -> assert false 24 24 | Some {tree; _} -> 25 25 let symbols : L.DocumentSymbol.t list =
+2 -2
lib/language_server/Highlight.ml
··· 16 16 let compute (params : L.DocumentHighlightParams.t) = 17 17 let Lsp_state.{forest; _} = Lsp_state.get () in 18 18 let uri = URI.of_lsp_uri ~base:forest.config.url params.textDocument.uri in 19 - let@ tree = Option.map @~ State.get_code forest uri in 20 - let@ Range.{range; value} = List.filter_map @~ Tree.nodes tree in 19 + let@ tree = Option.map @~ State.get_code ~forest uri in 20 + let@ Range.{range; value} = List.filter_map @~ Tree.Parsed.nodes tree in 21 21 let@ range = Option.map @~ range in 22 22 let range = Lsp_shims.lsp_range_of_range range in 23 23 let kind =
+3 -8
lib/language_server/Hover.ml
··· 26 26 Option.map 27 27 @~ 28 28 match forest.={uri} with 29 - | None -> 30 - assert false 31 - (*error 32 - @@ Diagnostic.createf Error ~code:Internal_error "%a is not in the index" 33 - URI.pp uri 34 - *) 29 + | None -> assert false 35 30 | Some tree -> ( 36 - let* nodes = Tree.(Option.map nodes @@ to_code tree) in 31 + let* nodes = Option.map Tree.Parsed.nodes Tree.(code tree) in 37 32 let* node = Analysis.node_at_code ~position nodes in 38 33 let tree_under_cursor = 39 34 let* {value = addr; _} = Analysis.extract_addr node in ··· 43 38 match tree_under_cursor with 44 39 | Some article -> Some (render article.mainmatter) 45 40 | None -> 46 - let* doc = Tree.to_doc tree in 41 + let* doc = Tree.document tree in 47 42 let* search_term = Analysis.word_at ~position doc in 48 43 let results = 49 44 List.map snd @@ Index.search forest.search_index search_term
+1 -1
lib/language_server/Inlay_hint.ml
··· 51 51 let config = forest.config in 52 52 let uri = URI.of_lsp_uri ~base:config.url params.textDocument.uri in 53 53 let@ {tree = {nodes; _}; _} = 54 - Option.map @~ Option.bind forest.={uri} Tree.to_syn 54 + Option.map @~ Option.bind forest.={uri} Tree.syn 55 55 in 56 56 extract_inlayable_hints ~config ~forest nodes
+2 -3
lib/language_server/Publish.ml
··· 7 7 8 8 open Forester_core 9 9 open Forester_compiler 10 + open State.Syntax 10 11 11 12 open struct 12 13 module L = Lsp.Types ··· 39 40 let source = 40 41 let Lsp_state.{forest; _} = Lsp_state.get () in 41 42 let uri = URI.of_lsp_uri ~base:forest.config.url uri in 42 - let@ doc = 43 - Option.map @~ Option.bind (State.find_opt forest uri) Tree.to_doc 44 - in 43 + let@ doc = Option.map @~ Option.bind forest.={uri} Tree.document in 45 44 Lsp.Text_document.text doc 46 45 in 47 46 let message = Format.asprintf "%a" Diagnostic.Message.pp diag.message in
+2 -2
lib/language_server/Semantic_tokens.ml
··· 271 271 Result.to_option 272 272 @@ 273 273 let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in 274 - let tokens = tokens @@ Tree.nodes tree in 274 + let tokens = tokens @@ Tree.Parsed.nodes tree in 275 275 Format.( 276 276 Eio.traceln "%a" 277 277 (pp_print_list ~pp_sep:(fun out () -> fprintf out "; ") pp_token) ··· 287 287 Result.to_option 288 288 @@ 289 289 let@ tree = Result.map @~ Imports.resolve_uri_to_code ~forest uri in 290 - semantic_tokens_delta @@ Tree.nodes tree 290 + semantic_tokens_delta @@ Tree.Parsed.nodes tree 291 291 292 292 let on_full_request (params : L.SemanticTokensParams.t) : 293 293 L.SemanticTokens.t option =
+1 -1
lib/language_server/Workspace_symbols.ml
··· 100 100 @@ 101 101 let@ uri, item = List.concat_map @~ List.of_seq @@ State.to_seq forest in 102 102 let@ {frontmatter; _} = 103 - List.concat_map @~ Option.to_list (Tree.to_article item) 103 + List.concat_map @~ Option.to_list (Tree.article item) 104 104 in 105 105 let title = render @@ State.get_expanded_title frontmatter forest in 106 106 let@ () =
+2 -2
lib/search/Search_engine.ml
··· 64 64 in 65 65 let dev = true in 66 66 let forest = Driver.batch_run ~env ~dev ~config ~config_path:"forest.toml" in 67 - let articles = List.of_seq @@ State.get_all_articles ~forest in 68 - let index = Index.create articles in 67 + let articles = State.get_all_articles ~forest in 68 + let index = Index.create List.(map snd articles) in 69 69 let size = Obj.reachable_words @@ Obj.repr index in 70 70 Format.printf "index size: %i@." size; 71 71 let forest = {forest with search_index = index} in