···8989 ~name: (Format.asprintf "%a" Resolver.Scope.pp_path path)
9090 ()
91919292-let compute (_params : L.WorkspaceSymbolParams.t) : _ =
9292+let contains_substring_case_insensitive ~pattern text =
9393+ let text = String.lowercase_ascii text
9494+ and pattern = String.lowercase_ascii pattern
9595+ in
9696+ let n = String.length text
9797+ and m = String.length pattern
9898+ in
9999+ let rec search i =
100100+ if i + m > n then false
101101+ else if String.sub text i m = pattern then true
102102+ else search (i + 1)
103103+ in
104104+ if m = 0 then true else search 0
105105+106106+let fuzzy_match ~pattern text =
107107+ let pattern = String.lowercase_ascii pattern in
108108+ let text = String.lowercase_ascii text in
109109+ let n = String.length text
110110+ and m = String.length pattern
111111+ in
112112+ if n = 0 then false
113113+ else
114114+ let rec aux i j =
115115+ if j = m then true (* matched entire pattern *)
116116+ else if i = n then false (* text exhausted first *)
117117+ else if text.[i] = pattern.[j] then
118118+ aux (i + 1) (j + 1) (* match, advance both *)
119119+ else
120120+ aux (i + 1) j (* skip char in text *)
121121+ in
122122+ aux 0 0
123123+124124+(* We no longer show exported functions, as this is really gumming up the editor interfaces. *)
125125+let compute (params : L.WorkspaceSymbolParams.t) : _ =
126126+ Logs.debug (fun m -> m "QUERY: %s" params.query);
93127 let Lsp_state.{forest; _} = Lsp_state.get () in
94128 let render = Plain_text_client.string_of_content ~forest in
95129 Option.some @@
9696- let@ _, item = List.concat_map @~ List.of_seq @@ State.to_seq forest in
9797- let title =
9898- match Tree.to_article item with
9999- | Some {frontmatter; _} ->
100100- render (State.get_expanded_title frontmatter forest)
101101- | None -> "untitled"
102102- in
103103- let units =
104104- List.concat @@
105105- Option.to_list @@
106106- Option.map exports_to_symbols @@ Tree.get_units item
107107- in
108108- let lsp_uri = Option.map Lsp.Text_document.documentUri @@ Tree.to_doc item in
109109- let file_symbol =
130130+ let@ uri, item = List.concat_map @~ List.of_seq @@ State.to_seq forest in
131131+ let@ {frontmatter; _} = List.concat_map @~ Option.to_list (Tree.to_article item) in
132132+ let title = render @@ State.get_expanded_title frontmatter forest in
133133+ let@ () = List.concat_map @~ if fuzzy_match ~pattern: params.query title then [()] else [] in
134134+ let@ file_symbol =
135135+ List.concat_map @~
110136 Option.to_list @@
111111- let@ uri = Option.map @~ lsp_uri in
112112- let location =
113113- L.Location.{
114114- range = L.Range.{
115115- end_ = {character = 0; line = 0;};
116116- start = {character = 0; line = 0;};
117117- };
118118- uri;
119119- }
120120- in
121121- L.SymbolInformation.create ~kind: File ~location ~name: title ()
137137+ let@ source_path = Option.map @~ State.source_path_of_uri uri forest in
138138+ let lsp_uri = Lsp.Uri.of_string source_path in
139139+ let location =
140140+ L.Location.{
141141+ range = L.Range.{
142142+ end_ = {character = 0; line = 0;};
143143+ start = {character = 0; line = 0;};
144144+ };
145145+ uri = lsp_uri;
146146+ }
147147+ in
148148+ L.SymbolInformation.create ~kind: File ~location ~name: title ()
122149 in
123123- units @ file_symbol
150150+ [file_symbol]