From a991569fa4552d6e59656f2260f6589b3c33884b Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 20 Jun 2025 15:06:06 +0200 Subject: [PATCH 1/7] Add missing docstring for String --- runtime/Stdlib_String.res | 2 +- runtime/Stdlib_String.resi | 66 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/runtime/Stdlib_String.res b/runtime/Stdlib_String.res index 7aaa139492..152a958036 100644 --- a/runtime/Stdlib_String.res +++ b/runtime/Stdlib_String.res @@ -1,6 +1,6 @@ type t = string -@val external make: 'a => string = "String" +@new external make: 'a => string = "String" @val external fromCharCode: int => string = "String.fromCharCode" @variadic @val external fromCharCodeMany: array => string = "String.fromCharCode" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index 3de15ffec7..f930eb10f5 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -42,7 +42,7 @@ String.make(3.5) == "3.5" String.make([1, 2, 3]) == "1,2,3" ``` */ -@val +@new external make: 'a => string = "String" /** @@ -121,8 +121,30 @@ String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` @variadic @val external fromCodePointMany: array => string = "String.fromCodePoint" +/** +`equal(str1, str2)` checks if two strings are equal. + +## Examples + +```rescript +String.equal("hello", "hello") == true +String.equal("hello", "world") == false +String.equal("", "") == true +``` +*/ external equal: (string, string) => bool = "%equal" +/** +`compare(str1, str2)` compares two strings, returns an `Ordering.t` value. + +## Examples + +```rescript +String.compare("hello", "hello") == Ordering.equal +String.compare("apple", "banana") == Ordering.less +String.compare("zebra", "apple") == Ordering.greater +``` +*/ external compare: (string, string) => Stdlib_Ordering.t = "%compare" /** @@ -1090,9 +1112,49 @@ String.padEnd("abc", 1, "") == "abc" @send external padEnd: (string, int, string) => string = "padEnd" -// TODO: add docs +/** +`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`. +Returns `None` if the symbol property doesn't exist. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 42) +String.getSymbol(h, mySymbol) == Some(42) +``` +*/ @get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" + +/** +`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string. + +This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 43) +String.getSymbolUnsafe(h, mySymbol) == 43 +``` +*/ @get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" + +/** +`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 42) +String.getSymbol(h, mySymbol) == Some(42) +``` +*/ @set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = "" /** From 562b0dcbd37671a1e07d50ff757610965cc6fac6 Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 20 Jun 2025 15:08:10 +0200 Subject: [PATCH 2/7] Update analysis snapshot --- tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index 412e810c27..d053698b97 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -874,7 +874,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, Symbol.t, 'a) => unit", - "documentation": null, + "documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"}, "sortText": "setSymbol", "insertText": "->String.setSymbol", "additionalTextEdits": [{ From 44193d3dae3363074b365e7b8e8d268dced5ebe0 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 23 Jun 2025 12:58:38 +0200 Subject: [PATCH 3/7] Remove Symbol functions from String module --- runtime/Stdlib_String.res | 4 - runtime/Stdlib_String.resi | 45 ---------- .../tests/src/expected/CompletionJsx.res.txt | 84 ++++++++----------- .../expected/DotPipeCompletionSpec.res.txt | 20 ++--- 4 files changed, 46 insertions(+), 107 deletions(-) diff --git a/runtime/Stdlib_String.res b/runtime/Stdlib_String.res index 152a958036..4fe1132dda 100644 --- a/runtime/Stdlib_String.res +++ b/runtime/Stdlib_String.res @@ -164,10 +164,6 @@ external splitByRegExpAtMost: (string, Stdlib_RegExp.t, ~limit: int) => array string = "padStart" @send external padEnd: (string, int, string) => string = "padEnd" -@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" -@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" -@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = "" - @send external localeCompare: (string, string) => float = "localeCompare" external ignore: string => unit = "%ignore" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index f930eb10f5..7090fe5472 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -1112,51 +1112,6 @@ String.padEnd("abc", 1, "") == "abc" @send external padEnd: (string, int, string) => string = "padEnd" -/** -`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`. -Returns `None` if the symbol property doesn't exist. - -## Examples - -```rescript -let mySymbol = Symbol.make("test") -let h = String.make("hello") -String.setSymbol(h, mySymbol, 42) -String.getSymbol(h, mySymbol) == Some(42) -``` -*/ -@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" - -/** -`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string. - -This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist. - -## Examples - -```rescript -let mySymbol = Symbol.make("test") -let h = String.make("hello") -String.setSymbol(h, mySymbol, 43) -String.getSymbolUnsafe(h, mySymbol) == 43 -``` -*/ -@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" - -/** -`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value. - -## Examples - -```rescript -let mySymbol = Symbol.make("test") -let h = String.make("hello") -String.setSymbol(h, mySymbol, 42) -String.getSymbol(h, mySymbol) == Some(42) -``` -*/ -@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = "" - /** `localeCompare(referenceStr, compareStr)` returns a float than indicatings whether a reference string comes before or after, or is the same as the given diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index d053698b97..b8a18d32e3 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -785,6 +785,30 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.startsWith", + "kind": 12, + "tags": [], + "detail": "(string, string) => bool", + "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"}, + "sortText": "startsWith", + "insertText": "->String.startsWith", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.splitAtMost", + "kind": 12, + "tags": [], + "detail": "(string, string, ~limit: int) => array", + "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"}, + "sortText": "splitAtMost", + "insertText": "->String.splitAtMost", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }, { "label": "->String.searchOpt", "kind": 12, @@ -821,42 +845,6 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.substringToEnd", - "kind": 12, - "tags": [], - "detail": "(string, ~start: int) => string", - "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"}, - "sortText": "substringToEnd", - "insertText": "->String.substringToEnd", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.startsWith", - "kind": 12, - "tags": [], - "detail": "(string, string) => bool", - "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"}, - "sortText": "startsWith", - "insertText": "->String.startsWith", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.splitAtMost", - "kind": 12, - "tags": [], - "detail": "(string, string, ~limit: int) => array", - "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"}, - "sortText": "splitAtMost", - "insertText": "->String.splitAtMost", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }, { "label": "->String.sliceToEnd", "kind": 12, @@ -869,18 +857,6 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.setSymbol", - "kind": 12, - "tags": [], - "detail": "(string, Symbol.t, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"}, - "sortText": "setSymbol", - "insertText": "->String.setSymbol", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }, { "label": "->String.splitByRegExp", "kind": 12, @@ -941,5 +917,17 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.substringToEnd", + "kind": 12, + "tags": [], + "detail": "(string, ~start: int) => string", + "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"}, + "sortText": "substringToEnd", + "insertText": "->String.substringToEnd", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }] diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index 8db5129032..4c826a3c55 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -418,25 +418,25 @@ Path Array.joinWith Path Stdlib.String.includ Path includ [{ - "label": "->String.includes", + "label": "->String.includesFrom", "kind": 12, "tags": [], - "detail": "(string, string) => bool", - "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"}, - "sortText": "includes", - "insertText": "->String.includes", + "detail": "(string, string, int) => bool", + "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"}, + "sortText": "includesFrom", + "insertText": "->String.includesFrom", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" }] }, { - "label": "->String.includesFrom", + "label": "->String.includes", "kind": 12, "tags": [], - "detail": "(string, string, int) => bool", - "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"}, - "sortText": "includesFrom", - "insertText": "->String.includesFrom", + "detail": "(string, string) => bool", + "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"}, + "sortText": "includes", + "insertText": "->String.includes", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" From e28d75ee8e358309e91d40ad2314ed3d103e1b44 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 23 Jun 2025 13:00:34 +0200 Subject: [PATCH 4/7] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9695b714..231a91399f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ - Remove `@return(undefined_to_opt)` and `%undefined_to_opt` primitive. https://github.com/rescript-lang/rescript/pull/7462 +#### :boom: Breaking Change + +- Remove `String.getSymbol`, `String.getSymbolUnsafe` and `String.setSymbol`. https://github.com/rescript-lang/rescript/pull/7571 + # 12.0.0-alpha.14 #### :boom: Breaking Change From 5ffe5c81963ea9433c1a95f126d9573135bd8e65 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 23 Jun 2025 13:58:14 +0200 Subject: [PATCH 5/7] Revert "Remove Symbol functions from String module" This reverts commit 44193d3dae3363074b365e7b8e8d268dced5ebe0. --- runtime/Stdlib_String.res | 4 + runtime/Stdlib_String.resi | 45 ++++++++++ .../tests/src/expected/CompletionJsx.res.txt | 84 +++++++++++-------- .../expected/DotPipeCompletionSpec.res.txt | 20 ++--- 4 files changed, 107 insertions(+), 46 deletions(-) diff --git a/runtime/Stdlib_String.res b/runtime/Stdlib_String.res index 4fe1132dda..152a958036 100644 --- a/runtime/Stdlib_String.res +++ b/runtime/Stdlib_String.res @@ -164,6 +164,10 @@ external splitByRegExpAtMost: (string, Stdlib_RegExp.t, ~limit: int) => array string = "padStart" @send external padEnd: (string, int, string) => string = "padEnd" +@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" +@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" +@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = "" + @send external localeCompare: (string, string) => float = "localeCompare" external ignore: string => unit = "%ignore" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index 7090fe5472..f930eb10f5 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -1112,6 +1112,51 @@ String.padEnd("abc", 1, "") == "abc" @send external padEnd: (string, int, string) => string = "padEnd" +/** +`getSymbol(str, symbol)` returns the value associated with the given symbol on the string as an `option<'a>`. +Returns `None` if the symbol property doesn't exist. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 42) +String.getSymbol(h, mySymbol) == Some(42) +``` +*/ +@get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" + +/** +`getSymbolUnsafe(str, symbol)` returns the value associated with the given symbol on the string. + +This is _unsafe_, meaning it will return `undefined` if the symbol property doesn't exist. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 43) +String.getSymbolUnsafe(h, mySymbol) == 43 +``` +*/ +@get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" + +/** +`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value. + +## Examples + +```rescript +let mySymbol = Symbol.make("test") +let h = String.make("hello") +String.setSymbol(h, mySymbol, 42) +String.getSymbol(h, mySymbol) == Some(42) +``` +*/ +@set_index external setSymbol: (string, Stdlib_Symbol.t, 'a) => unit = "" + /** `localeCompare(referenceStr, compareStr)` returns a float than indicatings whether a reference string comes before or after, or is the same as the given diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index b8a18d32e3..d053698b97 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -785,30 +785,6 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.startsWith", - "kind": 12, - "tags": [], - "detail": "(string, string) => bool", - "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"}, - "sortText": "startsWith", - "insertText": "->String.startsWith", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] - }, { - "label": "->String.splitAtMost", - "kind": 12, - "tags": [], - "detail": "(string, string, ~limit: int) => array", - "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"}, - "sortText": "splitAtMost", - "insertText": "->String.splitAtMost", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }, { "label": "->String.searchOpt", "kind": 12, @@ -845,6 +821,42 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.substringToEnd", + "kind": 12, + "tags": [], + "detail": "(string, ~start: int) => string", + "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"}, + "sortText": "substringToEnd", + "insertText": "->String.substringToEnd", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.startsWith", + "kind": 12, + "tags": [], + "detail": "(string, string) => bool", + "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"}, + "sortText": "startsWith", + "insertText": "->String.startsWith", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] + }, { + "label": "->String.splitAtMost", + "kind": 12, + "tags": [], + "detail": "(string, string, ~limit: int) => array", + "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"}, + "sortText": "splitAtMost", + "insertText": "->String.splitAtMost", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }, { "label": "->String.sliceToEnd", "kind": 12, @@ -857,6 +869,18 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] + }, { + "label": "->String.setSymbol", + "kind": 12, + "tags": [], + "detail": "(string, Symbol.t, 'a) => unit", + "documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"}, + "sortText": "setSymbol", + "insertText": "->String.setSymbol", + "additionalTextEdits": [{ + "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, + "newText": "" + }] }, { "label": "->String.splitByRegExp", "kind": 12, @@ -917,17 +941,5 @@ Path s "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, "newText": "" }] - }, { - "label": "->String.substringToEnd", - "kind": 12, - "tags": [], - "detail": "(string, ~start: int) => string", - "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"}, - "sortText": "substringToEnd", - "insertText": "->String.substringToEnd", - "additionalTextEdits": [{ - "range": {"start": {"line": 93, "character": 17}, "end": {"line": 93, "character": 18}}, - "newText": "" - }] }] diff --git a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt index 4c826a3c55..8db5129032 100644 --- a/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt +++ b/tests/analysis_tests/tests/src/expected/DotPipeCompletionSpec.res.txt @@ -418,25 +418,25 @@ Path Array.joinWith Path Stdlib.String.includ Path includ [{ - "label": "->String.includesFrom", + "label": "->String.includes", "kind": 12, "tags": [], - "detail": "(string, string, int) => bool", - "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"}, - "sortText": "includesFrom", - "insertText": "->String.includesFrom", + "detail": "(string, string) => bool", + "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"}, + "sortText": "includes", + "insertText": "->String.includes", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" }] }, { - "label": "->String.includes", + "label": "->String.includesFrom", "kind": 12, "tags": [], - "detail": "(string, string) => bool", - "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"}, - "sortText": "includes", - "insertText": "->String.includes", + "detail": "(string, string, int) => bool", + "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"}, + "sortText": "includesFrom", + "insertText": "->String.includesFrom", "additionalTextEdits": [{ "range": {"start": {"line": 89, "character": 55}, "end": {"line": 89, "character": 56}}, "newText": "" From 4c86a31212f72a425104391678b8c44ec9b13a74 Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 23 Jun 2025 13:58:30 +0200 Subject: [PATCH 6/7] Revert "Add changelog entry" This reverts commit e28d75ee8e358309e91d40ad2314ed3d103e1b44. --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 231a91399f..bd9695b714 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,10 +27,6 @@ - Remove `@return(undefined_to_opt)` and `%undefined_to_opt` primitive. https://github.com/rescript-lang/rescript/pull/7462 -#### :boom: Breaking Change - -- Remove `String.getSymbol`, `String.getSymbolUnsafe` and `String.setSymbol`. https://github.com/rescript-lang/rescript/pull/7571 - # 12.0.0-alpha.14 #### :boom: Breaking Change From 374a0d063d8b78ac6f34dd7a17c4dfdb540b6b3b Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 23 Jun 2025 14:23:11 +0200 Subject: [PATCH 7/7] Update String doc samples --- runtime/Stdlib_String.res | 2 +- runtime/Stdlib_String.resi | 15 +++++++-------- .../tests/src/expected/CompletionJsx.res.txt | 2 +- tests/tests/src/core/Test.mjs | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/runtime/Stdlib_String.res b/runtime/Stdlib_String.res index 152a958036..7aaa139492 100644 --- a/runtime/Stdlib_String.res +++ b/runtime/Stdlib_String.res @@ -1,6 +1,6 @@ type t = string -@new external make: 'a => string = "String" +@val external make: 'a => string = "String" @val external fromCharCode: int => string = "String.fromCharCode" @variadic @val external fromCharCodeMany: array => string = "String.fromCharCode" diff --git a/runtime/Stdlib_String.resi b/runtime/Stdlib_String.resi index f930eb10f5..d4c8fa193e 100644 --- a/runtime/Stdlib_String.resi +++ b/runtime/Stdlib_String.resi @@ -42,7 +42,7 @@ String.make(3.5) == "3.5" String.make([1, 2, 3]) == "1,2,3" ``` */ -@new +@val external make: 'a => string = "String" /** @@ -1119,10 +1119,9 @@ Returns `None` if the symbol property doesn't exist. ## Examples ```rescript -let mySymbol = Symbol.make("test") let h = String.make("hello") -String.setSymbol(h, mySymbol, 42) -String.getSymbol(h, mySymbol) == Some(42) +let symbol = String.getSymbol(h, Symbol.iterator) +Option.isSome(symbol) == true ``` */ @get_index external getSymbol: (string, Stdlib_Symbol.t) => option<'a> = "" @@ -1135,10 +1134,10 @@ This is _unsafe_, meaning it will return `undefined` if the symbol property does ## Examples ```rescript -let mySymbol = Symbol.make("test") let h = String.make("hello") -String.setSymbol(h, mySymbol, 43) -String.getSymbolUnsafe(h, mySymbol) == 43 +// This does required direct access to the symbol property +// Storing the iterator in a variable first, will not work. +String.getSymbolUnsafe(h, Symbol.iterator)()->Iterator.toArray->Array.length == 5 ``` */ @get_index external getSymbolUnsafe: (string, Stdlib_Symbol.t) => 'a = "" @@ -1150,7 +1149,7 @@ String.getSymbolUnsafe(h, mySymbol) == 43 ```rescript let mySymbol = Symbol.make("test") -let h = String.make("hello") +let h = %raw(`new String("hello")`) String.setSymbol(h, mySymbol, 42) String.getSymbol(h, mySymbol) == Some(42) ``` diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt index d053698b97..a749612d28 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsx.res.txt @@ -874,7 +874,7 @@ Path s "kind": 12, "tags": [], "detail": "(string, Symbol.t, 'a) => unit", - "documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = String.make(\"hello\")\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"}, + "documentation": {"kind": "markdown", "value": "\n`setSymbol(str, symbol, value)` sets the given symbol property on the string to the specified value.\n\n## Examples\n\n```rescript\nlet mySymbol = Symbol.make(\"test\")\nlet h = %raw(`new String(\"hello\")`)\nString.setSymbol(h, mySymbol, 42)\nString.getSymbol(h, mySymbol) == Some(42)\n```\n"}, "sortText": "setSymbol", "insertText": "->String.setSymbol", "additionalTextEdits": [{ diff --git a/tests/tests/src/core/Test.mjs b/tests/tests/src/core/Test.mjs index 936183ec24..e4f2a10144 100644 --- a/tests/tests/src/core/Test.mjs +++ b/tests/tests/src/core/Test.mjs @@ -15,7 +15,7 @@ function print(value) { } else if (match === "string") { return Stdlib_Option.getExn(JSON.stringify(value), undefined); } else { - return String(value); + return new String(value); } }