ocaml
0
fork

Configure Feed

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

State.ml: correct the erroneous source path fetching logic

+24 -9
+24 -9
lib/compiler/State.ml
··· 320 320 () 321 321 ) 322 322 323 - let rec source_path_of_uri (uri : URI.t) (forest : t) : string option = 323 + let rec lsp_uri_of_uri (uri : URI.t) (forest : t) : Lsp.Uri.t option = 324 324 let@ tree = Option.bind @@ find_opt forest uri in 325 - source_path_of_origin (Tree.origin tree) forest 325 + lsp_uri_of_tree tree forest 326 + 327 + and lsp_uri_of_tree (tree : Tree.t) (forest : t) : Lsp.Uri.t option = 328 + match tree with 329 + | Document doc -> Some (Lsp.Text_document.documentUri doc) 330 + | Parsed code -> lsp_uri_of_origin code.origin forest 331 + | Expanded syn -> lsp_uri_of_identity syn.identity forest 332 + | Resource evaluated -> lsp_uri_of_resource evaluated.resource forest 326 333 327 - and source_path_of_origin (origin : origin) (forest : t) : string option = 334 + and lsp_uri_of_resource (resource : resource) (forest : t) : Lsp.Uri.t option = 335 + match resource with 336 + | Article article -> Option.map Lsp.Uri.of_string article.frontmatter.source_path 337 + | Asset _ | Syndication _ -> None 338 + 339 + and lsp_uri_of_origin (origin : origin) (forest : t) : Lsp.Uri.t option = 328 340 match origin with 329 - | Physical document -> 330 - Option.some @@ Lsp.Uri.to_path @@ Lsp.Text_document.documentUri document 331 - | Subtree {parent} -> source_path_of_identity parent forest 341 + | Physical document -> Some (Lsp.Text_document.documentUri document) 342 + | Subtree {parent} -> lsp_uri_of_identity parent forest 332 343 | Undefined -> None 333 344 334 - and source_path_of_identity (identity : identity) (forest : t) : string option = 335 - let@ uri = Option.bind @@ identity_to_uri identity in 336 - source_path_of_uri uri forest 345 + and lsp_uri_of_identity (identity : identity) (forest : t) : Lsp.Uri.t option = 346 + match identity with 347 + | URI uri -> lsp_uri_of_uri uri forest 348 + | Anonymous -> None 349 + 350 + let source_path_of_uri uri forest = 351 + Option.map Lsp.Uri.to_path @@ lsp_uri_of_uri uri forest