Skip to content

Commit 91036ee

Browse files
committed
handle nopervasives, and open Stdlib by default
1 parent fe576f6 commit 91036ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2156
-795
lines changed

analysis/src/Packages.ml

+26-17
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,35 @@ let newBsPackage ~rootPath =
115115
let path = [FindFiles.nameSpaceToName namespace] in
116116
[path]
117117
in
118+
let bind f x = Option.bind x f in
119+
let bsc_flags =
120+
Json.get "bsc-flags" config
121+
|> bind Json.array |> Option.value ~default:[]
122+
in
123+
let no_pervasives =
124+
bsc_flags
125+
|> List.exists (fun s -> Json.string s = Some "-nopervasives")
126+
in
118127
let opens_from_bsc_flags =
119-
let bind f x = Option.bind x f in
120-
match Json.get "bsc-flags" config |> bind Json.array with
121-
| Some l ->
122-
List.fold_left
123-
(fun opens item ->
124-
match item |> Json.string with
125-
| None -> opens
126-
| Some s -> (
127-
let parts = String.split_on_char ' ' s in
128-
match parts with
129-
| "-open" :: name :: _ ->
130-
let path = name |> String.split_on_char '.' in
131-
path :: opens
132-
| _ -> opens))
133-
[] l
134-
| None -> []
128+
List.fold_left
129+
(fun opens item ->
130+
match item |> Json.string with
131+
| None -> opens
132+
| Some s -> (
133+
let parts = String.split_on_char ' ' s in
134+
match parts with
135+
| "-open" :: name :: _ ->
136+
let path = name |> String.split_on_char '.' in
137+
path :: opens
138+
| _ -> opens))
139+
[] bsc_flags
140+
in
141+
let opens_from_pervasives =
142+
if no_pervasives then []
143+
else [["Stdlib"]; ["Pervasives"; "JsxModules"]]
135144
in
136145
let opens =
137-
["Pervasives"; "JsxModules"] :: opens_from_namespace
146+
opens_from_pervasives @ opens_from_namespace
138147
|> List.rev_append opens_from_bsc_flags
139148
|> List.map (fun path -> path @ ["place holder"])
140149
in

tests/analysis_tests/tests-incremental-typechecking/src/expected/ConstructorCompletion__Json.res.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ Pexp_construct Js
44
Json
55
Array:[0:8->0:21] [0:21->0:23]
66
Completable: Cexpression CTypeAtPos()->variantPayload::Array($0)
7-
Package opens Pervasives.JsxModules.place holder
87
ContextPath CTypeAtPos()
98
[{
109
"label": "[]",
1110
"kind": 12,
1211
"tags": [],
1312
"detail": "t",
14-
"documentation": {"kind": "markdown", "value": " The JSON data structure \n\n```rescript\n@unboxed\ntype t =\n | Boolean(bool)\n | @as(null) Null\n | String(string)\n | Number(float)\n | Object(dict<t>)\n | Array(array<t>)\n```"},
13+
"documentation": {"kind": "markdown", "value": " \nA type representing a JSON object.\n\n\n```rescript\n@unboxed\ntype t =\n | Boolean(bool)\n | @as(null) Null\n | String(string)\n | Number(float)\n | Object(dict<t>)\n | Array(array<t>)\n```"},
1514
"sortText": "A",
1615
"insertText": "[$0]",
1716
"insertTextFormat": 2

tests/analysis_tests/tests-incremental-typechecking/src/expected/ConstructorCompletion__Own.res.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ posCursor:[4:24] posNoWhite:[4:23] Found expr:[4:8->4:25]
33
Pexp_construct WithVariant
44
One:[4:8->4:23] [4:23->4:25]
55
Completable: Cexpression CTypeAtPos()->variantPayload::One($0)
6-
Package opens Pervasives.JsxModules.place holder
76
ContextPath CTypeAtPos()
87
[{
98
"label": "{}",

tests/analysis_tests/tests/src/expected/BrokenParserCases.res.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ Complete src/BrokenParserCases.res 2:24
22
posCursor:[2:24] posNoWhite:[2:23] Found expr:[2:11->2:30]
33
Pexp_apply ...[2:11->2:17] (~isOff2:19->2:24=...[2:27->2:29])
44
Completable: CnamedArg(Value[someFn], isOff, [isOff])
5-
Package opens Pervasives.JsxModules.place holder
5+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
6+
Resolved opens 1 Stdlib
67
ContextPath Value[someFn]
78
Path someFn
89
[]
910

1011
Complete src/BrokenParserCases.res 6:17
1112
posCursor:[6:17] posNoWhite:[6:16] Found pattern:[6:16->6:19]
1213
Completable: Cpattern Value[s]=t
13-
Package opens Pervasives.JsxModules.place holder
14+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
15+
Resolved opens 1 Stdlib
1416
ContextPath Value[s]
1517
Path s
1618
[]
@@ -20,7 +22,8 @@ posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:39]
2022
posCursor:[10:29] posNoWhite:[10:27] Found pattern:[10:24->10:28]
2123
Ppat_construct None:[10:24->10:28]
2224
Completable: Cpath Value[None]
23-
Package opens Pervasives.JsxModules.place holder
25+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
26+
Resolved opens 1 Stdlib
2427
ContextPath Value[None]
2528
Path None
2629
[]

tests/analysis_tests/tests/src/expected/CompletePrioritize1.res.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Complete src/CompletePrioritize1.res 6:6
22
posCursor:[6:6] posNoWhite:[6:5] Found expr:[6:3->0:-1]
33
Completable: Cpath Value[a]->
4-
Package opens Pervasives.JsxModules.place holder
4+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
5+
Resolved opens 1 Stdlib
56
ContextPath Value[a]->
67
ContextPath Value[a]
78
Path a

tests/analysis_tests/tests/src/expected/CompletePrioritize2.res.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Complete src/CompletePrioritize2.res 9:7
22
posCursor:[9:7] posNoWhite:[9:6] Found expr:[9:3->0:-1]
33
Completable: Cpath Value[ax]->
4-
Package opens Pervasives.JsxModules.place holder
4+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
5+
Resolved opens 1 Stdlib
56
ContextPath Value[ax]->
67
ContextPath Value[ax]
78
Path ax
@@ -19,7 +20,8 @@ Complete src/CompletePrioritize2.res 12:5
1920
posCursor:[12:5] posNoWhite:[12:4] Found expr:[12:3->12:5]
2021
Pexp_ident ax:[12:3->12:5]
2122
Completable: Cpath Value[ax]
22-
Package opens Pervasives.JsxModules.place holder
23+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
24+
Resolved opens 1 Stdlib
2325
ContextPath Value[ax]
2426
Path ax
2527
[{

0 commit comments

Comments
 (0)