(* * SPDX-FileCopyrightText: 2024 The Forester Project Contributors * SPDX-FileCopyrightText: 2026 The Forester Project Contributors * * SPDX-License-Identifier: GPL-3.0-or-later *) open Forester_core open Forester_compiler open Forester_frontend open struct module L = Lsp.Types end let start_of_file = let beginning = L.Position.create ~character:0 ~line:0 in L.Range.create ~start:beginning ~end_:beginning let state_and_uri lsp_uri = let Lsp_state.{forest; _} = Lsp_state.get () in (forest, URI.of_lsp_uri ~base:(Forest.base forest) lsp_uri) let code_nodes ~(forest : Forest.t) (uri : URI.t) : Code.t option = Option.map Tree.Parsed.nodes (Forest.get_code ~forest uri) let code_nodes_for_doc lsp_uri = let forest, uri = state_and_uri lsp_uri in Option.map (fun nodes -> (forest, uri, nodes)) (code_nodes ~forest uri) let is_foreign_docs_uri ~forest uri = URI.same_site ~base:Config.docs_url uri && Router.Scope.get ~forest uri <> Local