Skip to content

Commit d6fc76a

Browse files
authored
Add missing docstring for String (#7571)
* Add missing docstring for String * Update analysis snapshot * Remove Symbol functions from String module * Add changelog entry * Revert "Remove Symbol functions from String module" This reverts commit 44193d3. * Revert "Add changelog entry" This reverts commit e28d75e. * Update String doc samples * Remove symbol bindings * Update analysis tests
1 parent 14f388b commit d6fc76a

File tree

7 files changed

+72
-74
lines changed

7 files changed

+72
-74
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#### :boom: Breaking Change
1616

1717
- The legacy rescript cli can be called through rewatch via `rewatch legacy`. Arguments to rewatch need to be passed after the subcommand. Argument `--compiler-args` is now a subcommand `compiler-args`. https://github.com/rescript-lang/rescript/pull/7551
18+
- Remove `String.getSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571
19+
- Remove `String.getSymbolUnsafe` from standard library. https://github.com/rescript-lang/rescript/pull/7571
20+
- Remove `String.setSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571
1821

1922
#### :rocket: New Feature
2023

runtime/Stdlib_String.res

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ external splitByRegExpAtMost: (string, Stdlib_RegExp.t, ~limit: int) => array<op
164164
@send external padStart: (string, int, string) => string = "padStart"
165165
@send external padEnd: (string, int, string) => string = "padEnd"
166166

167-
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""
168-
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""
169-
@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = ""
170-
171167
@send external localeCompare: (string, string) => float = "localeCompare"
172168

173169
external ignore: string => unit = "%ignore"

runtime/Stdlib_String.resi

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,30 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺`
121121
@variadic @val
122122
external fromCodePointMany: array<int> => string = "String.fromCodePoint"
123123

124+
/**
125+
`equal(str1, str2)` checks if two strings are equal.
126+
127+
## Examples
128+
129+
```rescript
130+
String.equal("hello", "hello") == true
131+
String.equal("hello", "world") == false
132+
String.equal("", "") == true
133+
```
134+
*/
124135
external equal: (string, string) => bool = "%equal"
125136

137+
/**
138+
`compare(str1, str2)` compares two strings, returns an `Ordering.t` value.
139+
140+
## Examples
141+
142+
```rescript
143+
String.compare("hello", "hello") == Ordering.equal
144+
String.compare("apple", "banana") == Ordering.less
145+
String.compare("zebra", "apple") == Ordering.greater
146+
```
147+
*/
126148
external compare: (string, string) => Stdlib_Ordering.t = "%compare"
127149

128150
/**
@@ -1090,11 +1112,6 @@ String.padEnd("abc", 1, "") == "abc"
10901112
@send
10911113
external padEnd: (string, int, string) => string = "padEnd"
10921114

1093-
// TODO: add docs
1094-
@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = ""
1095-
@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = ""
1096-
@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = ""
1097-
10981115
/**
10991116
`localeCompare(referenceStr, compareStr)` returns a float than indicatings
11001117
whether a reference string comes before or after, or is the same as the given

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

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,30 @@ Path s
785785
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
786786
"newText": ""
787787
}]
788+
}, {
789+
"label": "->String.startsWith",
790+
"kind": 12,
791+
"tags": [],
792+
"detail": "(string, string) => bool",
793+
"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"},
794+
"sortText": "startsWith",
795+
"insertText": "->String.startsWith",
796+
"additionalTextEdits": [{
797+
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
798+
"newText": ""
799+
}]
800+
}, {
801+
"label": "->String.splitAtMost",
802+
"kind": 12,
803+
"tags": [],
804+
"detail": "(string, string, ~limit: int) => array<string>",
805+
"documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"},
806+
"sortText": "splitAtMost",
807+
"insertText": "->String.splitAtMost",
808+
"additionalTextEdits": [{
809+
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
810+
"newText": ""
811+
}]
788812
}, {
789813
"label": "->String.searchOpt",
790814
"kind": 12,
@@ -821,42 +845,6 @@ Path s
821845
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
822846
"newText": ""
823847
}]
824-
}, {
825-
"label": "->String.substringToEnd",
826-
"kind": 12,
827-
"tags": [],
828-
"detail": "(string, ~start: int) => string",
829-
"documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\nis returned.\nSee [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"},
830-
"sortText": "substringToEnd",
831-
"insertText": "->String.substringToEnd",
832-
"additionalTextEdits": [{
833-
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
834-
"newText": ""
835-
}]
836-
}, {
837-
"label": "->String.startsWith",
838-
"kind": 12,
839-
"tags": [],
840-
"detail": "(string, string) => bool",
841-
"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"},
842-
"sortText": "startsWith",
843-
"insertText": "->String.startsWith",
844-
"additionalTextEdits": [{
845-
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
846-
"newText": ""
847-
}]
848-
}, {
849-
"label": "->String.splitAtMost",
850-
"kind": 12,
851-
"tags": [],
852-
"detail": "(string, string, ~limit: int) => array<string>",
853-
"documentation": {"kind": "markdown", "value": "\n`splitAtMost(str, delimiter, ~limit)` splits the given `str` at every\noccurrence of `delimiter` and returns an array of the first `limit` resulting\nsubstrings. If `limit` is negative or greater than the number of substrings,\nthe array will contain all the substrings.\n\n## Examples\n\n```rescript\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=3) == [\"ant\", \"bee\", \"cat\"]\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=0) == []\nString.splitAtMost(\"ant/bee/cat/dog/elk\", \"/\", ~limit=9) == [\"ant\", \"bee\", \"cat\", \"dog\", \"elk\"]\n```\n"},
854-
"sortText": "splitAtMost",
855-
"insertText": "->String.splitAtMost",
856-
"additionalTextEdits": [{
857-
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
858-
"newText": ""
859-
}]
860848
}, {
861849
"label": "->String.sliceToEnd",
862850
"kind": 12,
@@ -869,18 +857,6 @@ Path s
869857
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
870858
"newText": ""
871859
}]
872-
}, {
873-
"label": "->String.setSymbol",
874-
"kind": 12,
875-
"tags": [],
876-
"detail": "(string, Symbol.t, 'a) => unit",
877-
"documentation": null,
878-
"sortText": "setSymbol",
879-
"insertText": "->String.setSymbol",
880-
"additionalTextEdits": [{
881-
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
882-
"newText": ""
883-
}]
884860
}, {
885861
"label": "->String.splitByRegExp",
886862
"kind": 12,
@@ -941,5 +917,17 @@ Path s
941917
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
942918
"newText": ""
943919
}]
920+
}, {
921+
"label": "->String.substringToEnd",
922+
"kind": 12,
923+
"tags": [],
924+
"detail": "(string, ~start: int) => string",
925+
"documentation": {"kind": "markdown", "value": "\n`substringToEnd(str, ~start)` returns the substring of `str` from position\n`start` to the end.\n- If `start` is less than or equal to zero, the entire string is returned.\n- If `start` is greater than or equal to the length of `str`, the empty string\nis returned.\nSee [`String.substring`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) on MDN.\n\n## Examples\n\n```rescript\nString.substringToEnd(\"playground\", ~start=4) == \"ground\"\nString.substringToEnd(\"playground\", ~start=-3) == \"playground\"\nString.substringToEnd(\"playground\", ~start=12) == \"\"\n```\n"},
926+
"sortText": "substringToEnd",
927+
"insertText": "->String.substringToEnd",
928+
"additionalTextEdits": [{
929+
"range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}},
930+
"newText": ""
931+
}]
944932
}]
945933

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,25 @@ Path Array.joinWith
418418
Path Stdlib.String.includ
419419
Path includ
420420
[{
421-
"label": "->String.includes",
421+
"label": "->String.includesFrom",
422422
"kind": 12,
423423
"tags": [],
424-
"detail": "(string, string) => bool",
425-
"documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"},
426-
"sortText": "includes",
427-
"insertText": "->String.includes",
424+
"detail": "(string, string, int) => bool",
425+
"documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"},
426+
"sortText": "includesFrom",
427+
"insertText": "->String.includesFrom",
428428
"additionalTextEdits": [{
429429
"range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}},
430430
"newText": ""
431431
}]
432432
}, {
433-
"label": "->String.includesFrom",
433+
"label": "->String.includes",
434434
"kind": 12,
435435
"tags": [],
436-
"detail": "(string, string, int) => bool",
437-
"documentation": {"kind": "markdown", "value": "\n`includesFrom(str, searchValue, start)` returns `true` if `searchValue` is found\nanywhere within `str` starting at character number `start` (where 0 is the\nfirst character), `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includesFrom(\"programmer\", \"gram\", 1) == true\nString.includesFrom(\"programmer\", \"gram\", 4) == false\nString.includesFrom(`대한민국`, `한`, 1) == true\n```\n"},
438-
"sortText": "includesFrom",
439-
"insertText": "->String.includesFrom",
436+
"detail": "(string, string) => bool",
437+
"documentation": {"kind": "markdown", "value": "\n`includes(str, searchValue)` returns `true` if `searchValue` is found anywhere\nwithin `str`, `false` otherwise.\nSee [`String.includes`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) on MDN.\n\n## Examples\n\n```rescript\nString.includes(\"programmer\", \"gram\") == true\nString.includes(\"programmer\", \"er\") == true\nString.includes(\"programmer\", \"pro\") == true\nString.includes(\"programmer.dat\", \"xyz\") == false\n```\n"},
438+
"sortText": "includes",
439+
"insertText": "->String.includes",
440440
"additionalTextEdits": [{
441441
"range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}},
442442
"newText": ""

tests/tests/src/core/Core_TempTests.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,6 @@ let x = Symbol.for("Foo");
249249

250250
console.log(x);
251251

252-
let array$1 = "foo"[Symbol.iterator]().toArray();
253-
254-
console.log(array$1);
255-
256252
console.info("");
257253

258254
console.info("Global namespace");
@@ -338,6 +334,7 @@ export {
338334
_formatter,
339335
formatter,
340336
segments,
337+
array,
341338
date,
342339
dict,
343340
dict2,
@@ -354,7 +351,6 @@ export {
354351
set,
355352
regexp,
356353
x,
357-
array$1 as array,
358354
timeout,
359355
z,
360356
intFromBigInt,

tests/tests/src/core/Core_TempTests.res

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ Console.info("Symbol")
160160
Console.info("---")
161161
let x = Symbol.getFor("Foo")
162162
Console.log(x)
163-
let array: array<string> = String.getSymbolUnsafe("foo", Symbol.iterator)()->Iterator.toArray
164-
Console.log(array)
165163

166164
Console.info("")
167165
Console.info("Global namespace")

0 commit comments

Comments
 (0)