@@ -1516,6 +1516,8 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
15161516 ]
15171517 | Tpromise _ -> []
15181518
1519+ module StringSet = Set. Make (String )
1520+
15191521let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
15201522 if debug then
15211523 Printf. printf " Completable: %s\n " (Completable. toString completable);
@@ -1571,6 +1573,83 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
15711573 && (forHover || not (List. mem name identsSeen)))
15721574 |> List. map mkLabel)
15731575 @ keyLabels
1576+ | CdecoratorPayload (Module prefix ) ->
1577+ let packageJsonPath =
1578+ Utils. findPackageJson (full.package.rootPath |> Uri. fromPath)
1579+ in
1580+ let itemsFromPackageJson =
1581+ match packageJsonPath with
1582+ | None ->
1583+ if debug then
1584+ Printf. printf
1585+ " Did not find package.json, started looking (going upwards) from: %s\n "
1586+ full.package.rootPath;
1587+ []
1588+ | Some path -> (
1589+ match Files. readFile path with
1590+ | None ->
1591+ if debug then print_endline " Could not read package.json" ;
1592+ []
1593+ | Some s -> (
1594+ match Json. parse s with
1595+ | Some (Object items ) ->
1596+ items
1597+ |> List. filter_map (fun (key , t ) ->
1598+ match (key, t) with
1599+ | ("dependencies" | "devDependencies" ), Json. Object o ->
1600+ Some
1601+ (o
1602+ |> List. filter_map (fun (pkgName , _ ) ->
1603+ match pkgName with
1604+ | "rescript" -> None
1605+ | pkgName -> Some pkgName))
1606+ | _ -> None )
1607+ |> List. flatten
1608+ | _ ->
1609+ if debug then print_endline " Could not parse package.json" ;
1610+ [] ))
1611+ in
1612+ (* TODO: Resolve relatives? *)
1613+ let localItems =
1614+ try
1615+ let files =
1616+ Sys. readdir (Filename. dirname (env.file.uri |> Uri. toPath))
1617+ |> Array. to_list
1618+ in
1619+ (* Try to filter out compiled in source files *)
1620+ let resFiles =
1621+ StringSet. of_list
1622+ (files
1623+ |> List. filter_map (fun f ->
1624+ if Filename. extension f = " .res" then
1625+ Some (try Filename. chop_extension f with _ -> f)
1626+ else None ))
1627+ in
1628+ files
1629+ |> List. filter_map (fun fileName ->
1630+ let withoutExtension =
1631+ try Filename. chop_extension fileName with _ -> fileName
1632+ in
1633+ if
1634+ String. ends_with fileName ~suffix: package.suffix
1635+ && resFiles |> StringSet. mem withoutExtension
1636+ then None
1637+ else
1638+ match Filename. extension fileName with
1639+ | ".js" | ".mjs" -> Some (" ./" ^ fileName)
1640+ | _ -> None )
1641+ with _ ->
1642+ if debug then print_endline " Could not read relative directory" ;
1643+ []
1644+ in
1645+ let items = itemsFromPackageJson @ localItems in
1646+ items
1647+ |> List. filter (fun name -> Utils. startsWith name prefix)
1648+ |> List. map (fun name ->
1649+ let isLocal = Utils. startsWith name " ./" in
1650+ Completion. create name
1651+ ~kind: (Label (if isLocal then " Local file" else " Package" ))
1652+ ~env )
15741653 | Cdecorator prefix ->
15751654 let mkDecorator (name , docstring ) =
15761655 {(Completion. create name ~kind: (Label " " ) ~env ) with docstring}
0 commit comments