ocaml
0
fork

Configure Feed

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

Actually filter by the query parameter in Workspace_symbols

+54 -27
+54 -27
lib/language_server/Workspace_symbols.ml
··· 89 89 ~name: (Format.asprintf "%a" Resolver.Scope.pp_path path) 90 90 () 91 91 92 - let compute (_params : L.WorkspaceSymbolParams.t) : _ = 92 + let contains_substring_case_insensitive ~pattern text = 93 + let text = String.lowercase_ascii text 94 + and pattern = String.lowercase_ascii pattern 95 + in 96 + let n = String.length text 97 + and m = String.length pattern 98 + in 99 + let rec search i = 100 + if i + m > n then false 101 + else if String.sub text i m = pattern then true 102 + else search (i + 1) 103 + in 104 + if m = 0 then true else search 0 105 + 106 + let fuzzy_match ~pattern text = 107 + let pattern = String.lowercase_ascii pattern in 108 + let text = String.lowercase_ascii text in 109 + let n = String.length text 110 + and m = String.length pattern 111 + in 112 + if n = 0 then false 113 + else 114 + let rec aux i j = 115 + if j = m then true (* matched entire pattern *) 116 + else if i = n then false (* text exhausted first *) 117 + else if text.[i] = pattern.[j] then 118 + aux (i + 1) (j + 1) (* match, advance both *) 119 + else 120 + aux (i + 1) j (* skip char in text *) 121 + in 122 + aux 0 0 123 + 124 + (* We no longer show exported functions, as this is really gumming up the editor interfaces. *) 125 + let compute (params : L.WorkspaceSymbolParams.t) : _ = 126 + Logs.debug (fun m -> m "QUERY: %s" params.query); 93 127 let Lsp_state.{forest; _} = Lsp_state.get () in 94 128 let render = Plain_text_client.string_of_content ~forest in 95 129 Option.some @@ 96 - let@ _, item = List.concat_map @~ List.of_seq @@ State.to_seq forest in 97 - let title = 98 - match Tree.to_article item with 99 - | Some {frontmatter; _} -> 100 - render (State.get_expanded_title frontmatter forest) 101 - | None -> "untitled" 102 - in 103 - let units = 104 - List.concat @@ 105 - Option.to_list @@ 106 - Option.map exports_to_symbols @@ Tree.get_units item 107 - in 108 - let lsp_uri = Option.map Lsp.Text_document.documentUri @@ Tree.to_doc item in 109 - let file_symbol = 130 + let@ uri, item = List.concat_map @~ List.of_seq @@ State.to_seq forest in 131 + let@ {frontmatter; _} = List.concat_map @~ Option.to_list (Tree.to_article item) in 132 + let title = render @@ State.get_expanded_title frontmatter forest in 133 + let@ () = List.concat_map @~ if fuzzy_match ~pattern: params.query title then [()] else [] in 134 + let@ file_symbol = 135 + List.concat_map @~ 110 136 Option.to_list @@ 111 - let@ uri = Option.map @~ lsp_uri in 112 - let location = 113 - L.Location.{ 114 - range = L.Range.{ 115 - end_ = {character = 0; line = 0;}; 116 - start = {character = 0; line = 0;}; 117 - }; 118 - uri; 119 - } 120 - in 121 - L.SymbolInformation.create ~kind: File ~location ~name: title () 137 + let@ source_path = Option.map @~ State.source_path_of_uri uri forest in 138 + let lsp_uri = Lsp.Uri.of_string source_path in 139 + let location = 140 + L.Location.{ 141 + range = L.Range.{ 142 + end_ = {character = 0; line = 0;}; 143 + start = {character = 0; line = 0;}; 144 + }; 145 + uri = lsp_uri; 146 + } 147 + in 148 + L.SymbolInformation.create ~kind: File ~location ~name: title () 122 149 in 123 - units @ file_symbol 150 + [file_symbol]