123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199(*
* SPDX-FileCopyrightText: 2024 The Forester Project Contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*)openstructmoduleT=TypesmoduleR=ResolverincludeBaseendtypeexports=(R.P.data,Asai.Range.toption)Trie.ttypecode={nodes:Code.t;identity:identity;origin:origin;(* document: Lsp.Text_document.t; [@opaque] *)timestamp:floatoption;}[@@derivingshow]typesyn={nodes:Syn.t;code:code;identity:identity;units:exports;[@opaque]}[@@derivingshow]typeevaluated={resource:T.contentT.resource;route_locally:bool;expanded:synoption;}[@@deriving show]typet=|Documentof(Lsp.Text_document.t[@opaque])|Parsedofcode|Expandedofsyn|Resourceofevaluated[@@derivingshow]letorigin=function|Documentdoc->Physical doc|Parsedparsed->parsed.origin|Expandedexpanded->expanded.code.origin|Resourceresource->matchresource.expandedwith|None->Undefined|Someexpanded->expanded.code.originletshow_phase=function|Document_->"document"|Parsed_->"parsed"|Expanded_->"expanded"|Resource_->"resource"(* let get_uri ~base = fun t ->
let of_lsp_uri doc = Some (URI_scheme.lsp_uri_to_uri ~base (Lsp.Text_document.documentUri doc)) in
let uri_opt =
match t with
| Document doc -> of_lsp_uri doc
| Resource {tree; _} -> T.uri_for_resource tree
| Expanded {identity; _}
| Parsed {identity; _} ->
identity_to_uri identity
in
match uri_opt with
| Some uri -> uri
| None -> Reporter.fatal Internal_error ~extra_remarks: [Asai.Diagnostic.loctext "tried to get URI of an anonymous resource"] *)(* IDK if subtrees should resolve to their parent document*)letto_doc:t->Lsp.Text_document.toption=function|Documentdoc->Somedoc|Resource{expanded;_}->beginmatchexpandedwith|None->None|Some{code;_}->matchcode.originwith|Physicaldoc->Somedoc|Subtree_->None|Undefined->Noneend|Parsed{origin;_;}|Expanded{code={origin;_};_;}->matchoriginwith|Physicaldoc->Somedoc|Subtree_->None|Undefined->Noneletto_resource:t->T.contentT.resourceoption=function|Document_|Parsed_|Expanded_->None|Resource{resource;_;}->Someresourceletto_evaluated:t->evaluatedoption=function|Document_|Parsed_|Expanded_->None|Resourceevaluated->Someevaluatedletto_article:t->T.contentT.articleoption=function|Document_|Parsed_|Expanded_->None|Resource{resource;_;}->matchresourcewith|T.Articlea->Somea|_->Noneletget_frontmatter:t->T.contentT.frontmatteroption=function|Resource{resource=Types.Article{frontmatter;_};_}->Somefrontmatter|_->Noneletto_code:t->codeoption=function|Document_doc->(* Logs.debug (fun m -> m "tried to get code of unparsed document %s" (Lsp.Uri.to_string @@ Lsp.Text_document.documentUri doc)); *)(* assert false *)None|Parsedcode->Somecode|Resource{expanded;_}->beginmatchexpandedwith|None->None|Some{code;_}->Somecodeend|Expanded{code;_;}->Somecodeletto_syn:t->synoption=function|Document_->None|Parsed_->None|Expandedsyn->Somesyn|Resource{expanded;_}->expandedletget_units:t->exportsoption=funitem->matchitemwith|Document_->None|Parsed_->None|Expanded{units;_}->Someunits|Resource{expanded;_}->matchexpandedwith|Some{units;_}->Someunits|None->Noneletis_unparsed=function|Document_->true|_->falseletis_parsedt=not@@is_unparsedtletis_unexpanded=function|Document_|Parsed_->true|Expanded_|Resource_->falseletis_expanded:t->bool=function|Document_|Parsed_->false|Expanded_->true|Resource{expanded;_}->Option.is_someexpandedletis_unevaluated=function|Document_|Parsed_|Expanded_->true|Resource_->falseletis_asset=function|Document_|Parsed_|Expanded_->false|Resource{resource;_}->matchresourcewith|T.Asset_->true|_->falseletupdate_units:t->exports->t=funitemunits->matchitemwith|Document_|Parsed_->Reporter.fatalInternal_error~extra_remarks:[Asai.Diagnostic.loctext"can't update units for this item. It has not been expanded yet"]|Expandede->Expanded{ewithunits}|Resource({expanded;_}ase)->matchexpandedwith|None->Reporter.fatalInternal_error~extra_remarks:[Asai.Diagnostic.loctext"can't update units for this item. It is not a tree."]|Someexpanded->Resource{ewithexpanded=Some{expandedwithunits}}