@@ -24,7 +24,7 @@ let kindNumber = function
2424 | EnumMember -> 22
2525 | TypeParameter -> 26
2626
27- let command ~path =
27+ let document ~path =
2828 let symbols = ref [] in
2929 let rec exprKind (exp : Parsetree.expression ) =
3030 match exp.pexp_desc with
@@ -134,19 +134,42 @@ let command ~path =
134134 let parser = Res_driver. parsingEngine.parseInterface ~for Printer:false in
135135 let {Res_driver. parsetree = signature} = parser ~filename: path in
136136 iterator.signature iterator signature |> ignore);
137- let result =
138- ! symbols
139- |> List. rev_map (fun (name , loc , kind ) ->
140- Protocol. stringifyDocumentSymbolItem
141- {
142- name;
143- location =
144- {
145- uri = Uri. toString (Uri. fromPath path);
146- range = Utils. cmtLocToRange loc;
147- };
148- kind = kindNumber kind;
149- })
150- |> String. concat " ,\n "
151- in
152- print_endline (" [\n " ^ result ^ " \n ]" )
137+ ! symbols
138+ |> List. rev_map (fun (name , loc , kind ) ->
139+ let symbol : Protocol.documentSymbolItem =
140+ {
141+ name;
142+ location =
143+ {
144+ uri = Uri. toString (Uri. fromPath path);
145+ range = Utils. cmtLocToRange loc;
146+ };
147+ kind = kindNumber kind;
148+ }
149+ in
150+ symbol)
151+
152+ let workspace ~dir =
153+ let open FindFiles in
154+ let bsconfig = dir /+ " bsconfig.json" in
155+ match Files. readFile bsconfig with
156+ | None -> None
157+ | Some text -> (
158+ match Json. parse text with
159+ | None -> None
160+ | Some inner ->
161+ let sourceDirectories =
162+ getSourceDirectories ~include Dev:false ~base Dir:dir inner
163+ in
164+ let result =
165+ sourceDirectories
166+ |> List. map (fun srcDir ->
167+ Files. readDirectory (dir /+ srcDir)
168+ |> List. map (fun path -> dir /+ srcDir /+ path)
169+ |> List. filter isSourceFile |> filterDuplicates)
170+ |> List. flatten
171+ |> List. map (fun path ->
172+ document ~path |> List. map Protocol. stringifyDocumentSymbolItem)
173+ |> List. flatten |> Protocol. array
174+ in
175+ Some result)
0 commit comments