Skip to content

Commit b95feba

Browse files
authored
Treat package opens the same way local opens are. (#616)
* Treat package opens the same way local opens are. * Update CHANGELOG.md
1 parent 1ced671 commit b95feba

File tree

6 files changed

+125
-35
lines changed

6 files changed

+125
-35
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix issue where `-open Some.Path` in `"bsc-flags"` would sometimes be treated differently from `open Some.Path` locally in a file https://github.com/rescript-lang/rescript-vscode/pull/616
18+
1519
## v1.8.2
1620

1721
#### :rocket: New Feature

analysis/src/CompletionBackEnd.ml

+26-29
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ let showConstructor {Constructor.cname = {txt}; args; res} =
503503
| Some typ -> "\n" ^ (typ |> Shared.typeToString)
504504

505505
(* TODO: local opens *)
506-
let resolveOpens ~env ~previous opens ~package =
506+
let resolveOpens ~env opens ~package =
507507
List.fold_left
508508
(fun previous path ->
509509
(* Finding an open, first trying to find it in previoulsly resolved opens *)
@@ -540,7 +540,7 @@ let resolveOpens ~env ~previous opens ~package =
540540
Log.log "Was local";
541541
previous @ [env])
542542
(* loop(previous) *)
543-
previous opens
543+
[] opens
544544

545545
let checkName name ~prefix ~exact =
546546
if exact then name = prefix else Utils.startsWith name prefix
@@ -1319,11 +1319,6 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13191319
| Some path -> Some (getModulePath path)
13201320
in
13211321
let lhsPath = fromType typ in
1322-
let removePackageOpens modulePath =
1323-
match modulePath with
1324-
| toplevel :: rest when package.opens |> List.mem toplevel -> rest
1325-
| _ -> modulePath
1326-
in
13271322
let rec removeRawOpen rawOpen modulePath =
13281323
match (rawOpen, modulePath) with
13291324
| [_], _ -> Some modulePath
@@ -1345,8 +1340,9 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13451340
match modulePath with
13461341
| _ :: _ ->
13471342
let modulePathMinusOpens =
1348-
modulePath |> removePackageOpens |> removeRawOpens rawOpens
1349-
|> String.concat "."
1343+
modulePath
1344+
|> removeRawOpens package.opens
1345+
|> removeRawOpens rawOpens |> String.concat "."
13501346
in
13511347
let completionName name =
13521348
if modulePathMinusOpens = "" then name
@@ -1369,35 +1365,36 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13691365
| None -> [])
13701366
| None -> [])
13711367

1372-
let getOpens ~rawOpens ~package ~env =
1373-
Log.log
1374-
("Raw ppens: "
1375-
^ string_of_int (List.length rawOpens)
1376-
^ " "
1377-
^ String.concat " ... " (rawOpens |> List.map pathToString));
1368+
let getOpens ~debug ~rawOpens ~package ~env =
1369+
if debug && rawOpens <> [] then
1370+
Printf.printf "%s\n"
1371+
("Raw opens: "
1372+
^ string_of_int (List.length rawOpens)
1373+
^ " "
1374+
^ String.concat " ... " (rawOpens |> List.map pathToString));
13781375
let packageOpens = package.opens in
1379-
Log.log ("Package opens " ^ String.concat " " packageOpens);
1376+
if debug && packageOpens <> [] then
1377+
Printf.printf "%s\n"
1378+
("Package opens "
1379+
^ String.concat " " (packageOpens |> List.map pathToString));
13801380
let resolvedOpens =
1381-
resolveOpens ~env
1382-
~previous:
1383-
(List.map QueryEnv.fromFile
1384-
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
1385-
(List.rev rawOpens) ~package
1381+
resolveOpens ~env (List.rev (packageOpens @ rawOpens)) ~package
13861382
in
1387-
Log.log
1388-
("Resolved opens "
1389-
^ string_of_int (List.length resolvedOpens)
1390-
^ " "
1391-
^ String.concat " "
1392-
(resolvedOpens
1393-
|> List.map (fun (e : QueryEnv.t) -> Uri.toString e.file.uri)));
1383+
if debug && resolvedOpens <> [] then
1384+
Printf.printf "%s\n"
1385+
("Resolved opens "
1386+
^ string_of_int (List.length resolvedOpens)
1387+
^ " "
1388+
^ String.concat " "
1389+
(resolvedOpens
1390+
|> List.map (fun (e : QueryEnv.t) -> Uri.toString e.file.uri)));
13941391
(* Last open takes priority *)
13951392
List.rev resolvedOpens
13961393

13971394
let processCompletable ~debug ~package ~scope ~env ~pos ~forHover
13981395
(completable : Completable.t) =
13991396
let rawOpens = Scope.getRawOpens scope in
1400-
let opens = getOpens ~rawOpens ~package ~env in
1397+
let opens = getOpens ~debug ~rawOpens ~package ~env in
14011398
let allFiles = FileSet.union package.projectFiles package.dependenciesFiles in
14021399
let findTypeOfValue path =
14031400
path

analysis/src/Packages.ml

+10-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ let newBsPackage ~rootPath =
5151
Log.log
5252
("############ Namespaced as " ^ namespace ^ " at " ^ cmt);
5353
Hashtbl.add pathsForModule namespace (Namespace {cmt});
54-
[FindFiles.nameSpaceToName namespace]
54+
let path = [FindFiles.nameSpaceToName namespace] in
55+
[path]
5556
in
5657
Log.log
5758
("Dependency dirs: "
@@ -69,16 +70,20 @@ let newBsPackage ~rootPath =
6970
let parts = String.split_on_char ' ' s in
7071
match parts with
7172
| "-open" :: name :: _ ->
72-
let names = name |> String.split_on_char '.' in
73-
names @ opens
73+
let path = name |> String.split_on_char '.' in
74+
path :: opens
7475
| _ -> opens))
7576
[] l
7677
| None -> []
7778
in
7879
let opens =
79-
List.rev_append opens_from_bsc_flags opens_from_namespace
80+
opens_from_namespace
81+
|> List.rev_append opens_from_bsc_flags
82+
|> List.map (fun path -> path @ ["place holder"])
8083
in
81-
Log.log ("Opens from bsconfig: " ^ (opens |> String.concat " "));
84+
Log.log
85+
("Opens from bsconfig: "
86+
^ (opens |> List.map pathToString |> String.concat " "));
8287
{
8388
rootPath;
8489
projectFiles =

analysis/src/SharedTypes.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ type package = {
367367
dependenciesFiles: FileSet.t;
368368
pathsForModule: (file, paths) Hashtbl.t;
369369
namespace: string option;
370-
opens: string list;
370+
opens: path list;
371371
}
372372

373373
type full = {extra: extra; file: File.t; package: package}

0 commit comments

Comments
 (0)