···55 *
66 *)
7788+open Forester_prelude
89open Forester_core
9101011module L = Lsp.Types
11121212-let extract_addr (node : Code.node Range.located) : string option =
1313- match node.value with
1414- | Group (Braces, [{value = Text addr; _}])
1515- | Group (Parens, [{value = Text addr; _}])
1616- | Group (Squares, [{value = Group (Squares, [{value = Text addr; _}]); _}])
1717- | Text addr
1818- | Import (_, addr) ->
1919- Some addr
2020- | Subtree (addr, _) -> addr
2121- | Verbatim _ | Math (_, _) | Ident _ | Hash_ident _ | Xml_ident _ | Let (_, _, _) | Open _ | Scope _ | Put (_, _) | Default (_, _) | Get _ | Fun (_, _) | Object _ | Patch _ | Call (_, _) | Def (_, _, _) | Decl_xmlns (_, _) | Alloc _ | Namespace (_, _) | _ -> None
1313+module Item = struct
1414+ type t = [
1515+ | `Path of Trie.path
1616+ | `Addr of string
1717+ ]
1818+ let addr str = `Addr str
1919+ let path p = `Path p
2020+end
2121+2222+module S = Algaeff.Sequencer.Make(struct
2323+ type t = Item.t Range.located
2424+end)
22252326let nodes_within (node : Code.node Range.located) =
2427 match node.value with
···6366let flatten (tree : Code.t) : Code.t =
6467 List.concat_map nodes_within tree
65686969+let paths_in_bindings =
7070+ List.map snd
7171+7272+(* This function should not descend into the nodes!*)
7373+let paths : Code.node Range.located -> _ = function
7474+ | {value; loc;} ->
7575+ match value with
7676+ | Ident path
7777+ | Open (path)
7878+ | Put (path, _)
7979+ | Default (path, _)
8080+ | Get path
8181+ | Alloc path
8282+ | Namespace (path, _) ->
8383+ Some ([path], loc)
8484+ | Def (path, bindings, _)
8585+ | Let (path, bindings, _) ->
8686+ Some (path :: paths_in_bindings bindings, loc)
8787+ | Patch {self; _}
8888+ | Object {self; _;} ->
8989+ (* Option.to_list self; *)
9090+ Option.map (fun path -> [path], loc) self
9191+ | Fun (bindings, _) -> Some (paths_in_bindings bindings, loc)
9292+ | Subtree _
9393+ | Group _
9494+ | Scope _
9595+ | Math _
9696+ | Dx_sequent _
9797+ | Dx_const_uri _
9898+ | Dx_const_content _
9999+ | Dx_query _
100100+ | Dx_prop _
101101+ | Text _
102102+ | Verbatim _
103103+ | Hash_ident _
104104+ | Xml_ident _
105105+ | Call _
106106+ | Import _
107107+ | Decl_xmlns _
108108+ | Dx_var _
109109+ | Comment _
110110+ | Error _ ->
111111+ None
112112+113113+let extract_addr (node : Code.node Range.located) =
114114+ match node.value with
115115+ | Group (Braces, [{value = Text addr; _}])
116116+ | Group (Parens, [{value = Text addr; _}])
117117+ | Group (Squares, [{value = Group (Squares, [{value = Text addr; _}]); _}])
118118+ | Text addr
119119+ | Import (_, addr) ->
120120+ Some (Range.{value = addr; loc = node.loc})
121121+ | Subtree (addr, _) ->
122122+ Option.map (fun s -> Range.{value = s; loc = node.loc}) addr
123123+ | _ -> None
124124+125125+let rec analyse (node : Code.node Range.located) =
126126+ begin
127127+ let@ {value; loc} = Option.iter @~ extract_addr node in
128128+ S.yield ({value = Item.addr value; loc});
129129+ end;
130130+ begin
131131+ let@ paths, loc = Option.iter @~ paths node in
132132+ let@ path = List.iter @~ paths in
133133+ S.yield ({value = Item.path path; loc});
134134+ end;
135135+ let children = nodes_within node in
136136+ List.iter analyse children
137137+66138let contains = fun
67139 ~(position : Lsp.Types.Position.t)
68140 (located : _ Range.located)
···97169 | Some inner -> Some inner
98170 | None -> Some n
99171100100-let addr_at ~(position : Lsp.Types.Position.t) (code : _ list) : string option =
172172+let addr_at ~(position : Lsp.Types.Position.t) (code : _ list) : _ Range.located option =
101173 Option.bind (node_at ~position code) extract_addr
174174+175175+let analyse_syntax nodes =
176176+ let@ () = S.run in
177177+ List.iter analyse nodes
+4-2
lib/language_server/Analysis.mli
···1919*)
2020val extract_addr :
2121 Code.node Range.located ->
2222- string option
2222+ string Range.located option
23232424(** Attempts to find the smallest located {{!type:Forester_compiler.Code.node}node} which contains [position]*)
2525val node_at :
···3232val addr_at :
3333 position: Lsp.Types.Position.t ->
3434 Code.t ->
3535- string option
3535+ string Asai.Range.located option
36363737(** [flatten code] is a "flat" list of nodes. This function is underspecified and needs to be thought about more.*)
3838val flatten : Code.t -> Code.t
3939+4040+val analyse_syntax : Code.t -> [ `Addr of string | `Path of Trie.path ] Asai.Range.located Seq.t
+4-4
lib/language_server/Definitions.ml
···2121 let uri = URI_scheme.lsp_uri_to_uri ~host textDocument.uri in
2222 match Option.bind forest.={uri} Tree.to_code with
2323 | None -> None
2424- | Some code ->
2525- match Analysis.addr_at ~position code.nodes with
2424+ | Some {nodes; _} ->
2525+ match Analysis.addr_at ~position nodes with
2626 | None -> None
2727- | Some addr ->
2828- let uri = URI_scheme.user_uri ~host addr in
2727+ | Some {value = str; _} ->
2828+ let uri = URI_scheme.user_uri ~host str in
2929 let path = URI.Tbl.find forest.resolver uri in
3030 let uri = Lsp.Uri.of_path path in
3131 Logs.debug (fun m -> m "Definitions: %s" path);
+1-1
lib/language_server/Hover.ml
···4040 (* TODO: use node_at and provide hover for things other than links.*)
4141 match Analysis.addr_at ~position tree.nodes with
4242 | None -> Format.asprintf "character: %i, line: %i." position.character position.line;
4343- | Some addr_at_cursor ->
4343+ | Some Range.{value = addr_at_cursor; _} ->
4444 let uri_under_cursor = URI_scheme.user_uri ~host addr_at_cursor in
4545 match State.get_article uri_under_cursor forest with
4646 | None ->
+1-1
lib/language_server/Inlay_hint.ml
···4040 | Some (`Range (_, pos)) ->
4141 match Analysis.extract_addr node with
4242 | None -> None
4343- | Some str ->
4343+ | Some {value = str; _} ->
4444 let uri = URI_scheme.user_uri ~host str in
4545 match State.get_article uri forest with
4646 | None ->