Skip to content

Commit 5230214

Browse files
zthcknitt
authored andcommitted
pipe completion for stdlib
1 parent 54707c0 commit 5230214

File tree

8 files changed

+993
-69
lines changed

8 files changed

+993
-69
lines changed

analysis/src/TypeUtils.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,14 @@ let pathToBuiltin path =
12551255

12561256
let completionPathFromMaybeBuiltin path =
12571257
match pathToBuiltin path with
1258-
| Some ("array", _) -> Some ["Array"]
1259-
| Some ("option", _) -> Some ["Option"]
1260-
| Some ("string", _) -> Some ["String"]
1261-
| Some ("int", _) -> Some ["Int"]
1262-
| Some ("float", _) -> Some ["Float"]
1263-
| Some ("promise", _) -> Some ["Promise"]
1264-
| Some ("list", _) -> Some ["List"]
1265-
| Some ("result", _) -> Some ["Result"]
1266-
| Some ("dict", _) -> Some ["Dict"]
1267-
| Some ("char", _) -> Some ["Char"]
1258+
| Some ("array", _) -> Some ["Stdlib"; "Array"]
1259+
| Some ("option", _) -> Some ["Stdlib"; "Option"]
1260+
| Some ("string", _) -> Some ["Stdlib"; "String"]
1261+
| Some ("int", _) -> Some ["Stdlib"; "Int"]
1262+
| Some ("float", _) -> Some ["Stdlib"; "Float"]
1263+
| Some ("promise", _) -> Some ["Stdlib"; "Promise"]
1264+
| Some ("list", _) -> Some ["Stdlib"; "List"]
1265+
| Some ("result", _) -> Some ["Stdlib"; "Result"]
1266+
| Some ("dict", _) -> Some ["Stdlib"; "Dict"]
1267+
| Some ("char", _) -> Some ["Stdlib"; "Char"]
12681268
| _ -> None

tests/analysis_tests/tests-generic-jsx-transform/src/expected/GenericJsxCompletion.res.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Package opens Pervasives.JsxModules.place holder
5959
ContextPath Value[someString]->st <<jsx>>
6060
ContextPath Value[someString]
6161
Path someString
62-
Path String.st
62+
Path Stdlib.String.st
6363
[{
6464
"label": "GenericJsx.string",
6565
"kind": 12,
@@ -69,13 +69,13 @@ Path String.st
6969
"sortText": "A",
7070
"insertTextFormat": 2
7171
}, {
72-
"label": "String.startsWith",
72+
"label": "Stdlib.String.startsWith",
7373
"kind": 12,
7474
"tags": [],
7575
"detail": "(string, string) => bool",
7676
"documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}
7777
}, {
78-
"label": "String.startsWithFrom",
78+
"label": "Stdlib.String.startsWithFrom",
7979
"kind": 12,
8080
"tags": [],
8181
"detail": "(string, string, int) => bool",
@@ -106,7 +106,7 @@ Resolved opens 1 GenericJsx
106106
ContextPath Value[someString]->st <<jsx>>
107107
ContextPath Value[someString]
108108
Path someString
109-
Path String.st
109+
Path Stdlib.String.st
110110
[{
111111
"label": "string",
112112
"kind": 12,
@@ -116,13 +116,13 @@ Path String.st
116116
"sortText": "A",
117117
"insertTextFormat": 2
118118
}, {
119-
"label": "String.startsWith",
119+
"label": "Stdlib.String.startsWith",
120120
"kind": 12,
121121
"tags": [],
122122
"detail": "(string, string) => bool",
123123
"documentation": {"kind": "markdown", "value": "\n`startsWith(str, substr)` returns `true` if the `str` starts with `substr`,\n`false` otherwise.\nSee [`String.startsWith`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) on MDN.\n\n## Examples\n\n```rescript\nString.startsWith(\"BuckleScript\", \"Buckle\") == true\nString.startsWith(\"BuckleScript\", \"\") == true\nString.startsWith(\"JavaScript\", \"Buckle\") == false\n```\n"}
124124
}, {
125-
"label": "String.startsWithFrom",
125+
"label": "Stdlib.String.startsWithFrom",
126126
"kind": 12,
127127
"tags": [],
128128
"detail": "(string, string, int) => bool",

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

Lines changed: 202 additions & 16 deletions
Large diffs are not rendered by default.

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

Lines changed: 236 additions & 20 deletions
Large diffs are not rendered by default.

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

Lines changed: 411 additions & 9 deletions
Large diffs are not rendered by default.

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

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,68 @@ ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)->t
267267
ContextPath Value[Belt, Array, reduce](Nolabel, Nolabel, Nolabel)
268268
ContextPath Value[Belt, Array, reduce]
269269
Path Belt.Array.reduce
270-
Path Int.t
271-
[]
270+
Path Stdlib.Int.t
271+
[{
272+
"label": "Stdlib.Int.toStringWithRadix",
273+
"kind": 12,
274+
"tags": [1],
275+
"detail": "(int, ~radix: int) => string",
276+
"documentation": {"kind": "markdown", "value": "Deprecated: Use `toString` instead\n\n\n`toStringWithRadix(n, ~radix)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toStringWithRadix(6, ~radix=2) // \"110\"\nInt.toStringWithRadix(373592855, ~radix=16) // \"16449317\"\nInt.toStringWithRadix(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"}
277+
}, {
278+
"label": "Stdlib.Int.toExponentialWithPrecision",
279+
"kind": 12,
280+
"tags": [1],
281+
"detail": "(int, ~digits: int) => string",
282+
"documentation": {"kind": "markdown", "value": "Deprecated: Use `toExponential` instead\n\n\n`toExponential(n, ~digits)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\non MDN.\n\n## Examples\n\n```rescript\nInt.toExponentialWithPrecision(77, ~digits=2) // \"7.70e+1\"\nInt.toExponentialWithPrecision(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"}
283+
}, {
284+
"label": "Stdlib.Int.toFixedWithPrecision",
285+
"kind": 12,
286+
"tags": [1],
287+
"detail": "(int, ~digits: int) => string",
288+
"documentation": {"kind": "markdown", "value": "Deprecated: Use `toFixed` instead\n\n\n`toFixedWithPrecision(n, ~digits)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixedWithPrecision(300, ~digits=4) // \"300.0000\"\nInt.toFixedWithPrecision(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"}
289+
}, {
290+
"label": "Stdlib.Int.toPrecisionWithPrecision",
291+
"kind": 12,
292+
"tags": [1],
293+
"detail": "(int, ~digits: int) => string",
294+
"documentation": {"kind": "markdown", "value": "Deprecated: Use `toPrecision` instead\n\n\n`toPrecisionWithPrecision(n, ~digits)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecisionWithPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecisionWithPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n\n"}
295+
}, {
296+
"label": "Stdlib.Int.toPrecision",
297+
"kind": 12,
298+
"tags": [],
299+
"detail": "(int, ~digits: int=?) => string",
300+
"documentation": {"kind": "markdown", "value": "\n`toPrecision(n, ~digits=?)` return a `string` representing the giver value with\nprecision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.\n\n## Examples\n\n```rescript\nInt.toPrecision(100) // \"100\"\nInt.toPrecision(1) // \"1\"\nInt.toPrecision(100, ~digits=2) // \"1.0e+2\"\nInt.toPrecision(1, ~digits=2) // \"1.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is not between 1 and 100 (inclusive).\nImplementations are allowed to support larger and smaller values as well.\nECMA-262 only requires a precision of up to 21 significant digits.\n"}
301+
}, {
302+
"label": "Stdlib.Int.toString",
303+
"kind": 12,
304+
"tags": [],
305+
"detail": "(int, ~radix: int=?) => string",
306+
"documentation": {"kind": "markdown", "value": "\n`toString(n, ~radix=?)` return a `string` representing the given value.\n`~radix` specifies the radix base to use for the formatted number.\nSee [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)\non MDN.\n\n## Examples\n\n```rescript\nInt.toString(1000) // \"1000\"\nInt.toString(-1000) // \"-1000\"\nInt.toString(6, ~radix=2) // \"110\"\nInt.toString(373592855, ~radix=16) // \"16449317\"\nInt.toString(123456, ~radix=36) // \"2n9c\"\n```\n\n## Exceptions\n\n`RangeError`: if `radix` is less than 2 or greater than 36.\n"}
307+
}, {
308+
"label": "Stdlib.Int.toFloat",
309+
"kind": 12,
310+
"tags": [],
311+
"detail": "int => float",
312+
"documentation": {"kind": "markdown", "value": "\n`toFloat(n)` return a `float` representing the given value.\n\n## Examples\n\n```rescript\nInt.toFloat(100) == 100.0\nInt.toFloat(2) == 2.0\n```\n"}
313+
}, {
314+
"label": "Stdlib.Int.toLocaleString",
315+
"kind": 12,
316+
"tags": [],
317+
"detail": "int => string",
318+
"documentation": {"kind": "markdown", "value": "\n`toLocaleString(n)` return a `string` with language-sensitive representing the\ngiven value. See [`Number.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) on MDN.\n\n## Examples\n\n```rescript\n// If the application uses English as the default language\nInt.toLocaleString(1000) // \"1,000\"\n\n// If the application uses Portuguese Brazil as the default language\nInt.toLocaleString(1000) // \"1.000\"\n```\n"}
319+
}, {
320+
"label": "Stdlib.Int.toExponential",
321+
"kind": 12,
322+
"tags": [],
323+
"detail": "(int, ~digits: int=?) => string",
324+
"documentation": {"kind": "markdown", "value": "\n`toExponential(n, ~digits=?)` return a `string` representing the given value in\nexponential notation. `digits` specifies how many digits should appear after\nthe decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)\n\n## Examples\n\n```rescript\nInt.toExponential(1000) // \"1e+3\"\nInt.toExponential(-1000) // \"-1e+3\"\nInt.toExponential(77, ~digits=2) // \"7.70e+1\"\nInt.toExponential(5678, ~digits=2) // \"5.68e+3\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` less than 0 or greater than 10.\n"}
325+
}, {
326+
"label": "Stdlib.Int.toFixed",
327+
"kind": 12,
328+
"tags": [],
329+
"detail": "(int, ~digits: int=?) => string",
330+
"documentation": {"kind": "markdown", "value": "\n`toFixed(n, ~digits=?)` return a `string` representing the given\nvalue using fixed-point notation. `digits` specifies how many digits should\nappear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)\non MDN.\n\n## Examples\n\n```rescript\nInt.toFixed(123456) // \"123456.00\"\nInt.toFixed(10) // \"10.00\"\nInt.toFixed(300, ~digits=4) // \"300.0000\"\nInt.toFixed(300, ~digits=1) // \"300.0\"\n```\n\n## Exceptions\n\n- `RangeError`: If `digits` is less than 0 or larger than 100.\n"}
331+
}]
272332

273333
Complete src/CompletionPipeChain.res 70:12
274334
posCursor:[70:12] posNoWhite:[70:11] Found expr:[70:3->0:-1]

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,44 @@ Path ffff
210210
ContextPath Value[ffff]->u
211211
ContextPath Value[ffff]
212212
Path ffff
213-
Path Array.u
214-
[]
213+
Path Stdlib.Array.u
214+
[{
215+
"label": "->Stdlib.Array.unshiftMany",
216+
"kind": 12,
217+
"tags": [],
218+
"detail": "(array<'a>, array<'a>) => unit",
219+
"documentation": {"kind": "markdown", "value": "\n`unshiftMany(array, itemsArray)` inserts many new items to the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.push`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshiftMany([\"yay\", \"wehoo\"])\nsomeArray->assertEqual([\"yay\", \"wehoo\", \"hi\", \"hello\"])\n```\n"},
220+
"sortText": "unshiftMany",
221+
"insertText": "->Stdlib.Array.unshiftMany",
222+
"additionalTextEdits": [{
223+
"range": {"start": {"line": 75, "character": 7}, "end": {"line": 75, "character": 8}},
224+
"newText": ""
225+
}]
226+
}, {
227+
"label": "->Stdlib.Array.unshift",
228+
"kind": 12,
229+
"tags": [],
230+
"detail": "(array<'a>, 'a) => unit",
231+
"documentation": {"kind": "markdown", "value": "\n`unshift(array, item)` inserts a new item at the start of the array.\n\nBeware this will *mutate* the array.\n\nSee [`Array.unshift`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) on MDN.\n\n## Examples\n\n```rescript\nlet someArray = [\"hi\", \"hello\"]\nsomeArray->Array.unshift(\"yay\")\nsomeArray->assertEqual([\"yay\", \"hi\", \"hello\"])\n```\n"},
232+
"sortText": "unshift",
233+
"insertText": "->Stdlib.Array.unshift",
234+
"additionalTextEdits": [{
235+
"range": {"start": {"line": 75, "character": 7}, "end": {"line": 75, "character": 8}},
236+
"newText": ""
237+
}]
238+
}, {
239+
"label": "->Stdlib.Array.unsafe_get",
240+
"kind": 12,
241+
"tags": [1],
242+
"detail": "(array<'a>, int) => 'a",
243+
"documentation": {"kind": "markdown", "value": "Deprecated: Use getUnsafe instead. This will be removed in v13\n\n\n`unsafe_get(array, index)` returns the element at `index` of `array`.\n\nThis is _unsafe_, meaning it will return `undefined` value if `index` does not exist in `array`.\n\nUse `Array.unsafe_get` only when you are sure the `index` exists (i.e. when using for-loop).\n\n## Examples\n\n```rescript\nlet array = [1, 2, 3]\nfor index in 0 to array->Array.length - 1 {\n let value = array->Array.unsafe_get(index)\n Console.log(value)\n}\n```\n"},
244+
"sortText": "unsafe_get",
245+
"insertText": "->Stdlib.Array.unsafe_get",
246+
"additionalTextEdits": [{
247+
"range": {"start": {"line": 75, "character": 7}, "end": {"line": 75, "character": 8}},
248+
"newText": ""
249+
}]
250+
}]
215251

216252
Complete src/DotPipeCompletionSpec.res 80:7
217253
posCursor:[80:7] posNoWhite:[80:6] Found expr:[80:3->80:7]

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,20 @@ ContextPath Value[t]
1111
Path t
1212
CPPipe pathFromEnv: found:true
1313
Path RecordCompletion.n
14-
Path Array.m
15-
[]
14+
Path Stdlib.Array.m
15+
[{
16+
"label": "Stdlib.Array.map",
17+
"kind": 12,
18+
"tags": [],
19+
"detail": "(array<'a>, 'a => 'b) => array<'b>",
20+
"documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"}
21+
}, {
22+
"label": "Stdlib.Array.mapWithIndex",
23+
"kind": 12,
24+
"tags": [],
25+
"detail": "(array<'a>, ('a, int) => 'b) => array<'b>",
26+
"documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"}
27+
}]
1628

1729
Complete src/RecordCompletion.res 11:13
1830
posCursor:[11:13] posNoWhite:[11:12] Found expr:[11:3->11:13]
@@ -39,8 +51,20 @@ CPPipe pathFromEnv: found:true
3951
Path RecordCompletion.n2
4052
CPPipe pathFromEnv: found:true
4153
Path RecordCompletion.n
42-
Path Array.m
43-
[]
54+
Path Stdlib.Array.m
55+
[{
56+
"label": "Stdlib.Array.map",
57+
"kind": 12,
58+
"tags": [],
59+
"detail": "(array<'a>, 'a => 'b) => array<'b>",
60+
"documentation": {"kind": "markdown", "value": "\n`map(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray = array->Array.map(greeting => greeting ++ \" to you\")\n\nassertEqual(mappedArray, [\"Hello to you\", \"Hi to you\", \"Good bye to you\"])\n```\n"}
61+
}, {
62+
"label": "Stdlib.Array.mapWithIndex",
63+
"kind": 12,
64+
"tags": [],
65+
"detail": "(array<'a>, ('a, int) => 'b) => array<'b>",
66+
"documentation": {"kind": "markdown", "value": "\n`mapWithIndex(array, fn)` returns a new array with all elements from `array`, each element transformed using the provided `fn`.\n\nSee [`Array.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) on MDN.\n\n## Examples\n\n```rescript\nlet array = [\"Hello\", \"Hi\", \"Good bye\"]\nlet mappedArray =\n array->Array.mapWithIndex((greeting, index) =>\n greeting ++ \" at position \" ++ Int.toString(index)\n )\n\nassertEqual(mappedArray, [\"Hello at position 0\", \"Hi at position 1\", \"Good bye at position 2\"])\n```\n"}
67+
}]
4468

4569
Complete src/RecordCompletion.res 19:7
4670
posCursor:[19:7] posNoWhite:[19:6] Found expr:[19:3->19:7]

0 commit comments

Comments
 (0)