From b043e64aca81ae43937ec1f52553598dcbc6c777 Mon Sep 17 00:00:00 2001 From: Release-Candidate Date: Sat, 13 Jul 2024 11:19:39 +0200 Subject: [PATCH 1/3] Add a popup un unsaved changes on eval, parse escaped quotes correctly Signed-off-by: Release-Candidate --- CHANGELOG.md | 10 ++++++++++ src/evalREPL.ts | 10 ++++++++++ src/sexps.ts | 27 +++++++++++++++++++++++++-- test/sexps-test.ts | 16 ++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c18a4f0..09cb867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Chez Scheme REPL for Visual Studio Code Changelog +## Version 0.7.1 (2024-07-13) + +Special thanks to [migraine-user](https://github.com/migraine-user) for helping with these: + +Add a popup warning if the file has unsaved changes before inline evaluating some expression. + +### Bugfixes + +- Fix the S-expression parser's handling of escaped quotes in strings + ## Version 0.7.0 (2024-07-12) New command `Chez Scheme REPL: Remove all evaluated values from the view.`, `chezScheme.removeEvalVals` to remove all evaluated values from the current view. diff --git a/src/evalREPL.ts b/src/evalREPL.ts index 16074c3..c6821f4 100644 --- a/src/evalREPL.ts +++ b/src/evalREPL.ts @@ -410,6 +410,16 @@ async function runREPLCommand( if (document.isUntitled) { await document.save(); } + if (document.isDirty) { + const response = await vscode.window.showWarningMessage( + "The file has unsaved changes, these will not be send to the REPL.", + "Save changes and eval", + "Eval without saving" + ); + if (response === "Save changes and eval") { + await document.save(); + } + } return h.runCommand({ root: root ? root.uri.fsPath : "./", args: [c.replQuietArg], diff --git a/src/sexps.ts b/src/sexps.ts index 87a07e9..06af454 100644 --- a/src/sexps.ts +++ b/src/sexps.ts @@ -377,6 +377,27 @@ function endOfSexp(data: { delimString: "{", }); } else if (data.s.endsWith('"') && data.delim === "Quote") { + // cHECK IF ESCAPED + let toCheck = data.s.slice(0, -1); + let numBackSlash = 0; + let backSlashes = ""; + while (toCheck.endsWith("\\")) { + toCheck = toCheck.slice(0, -1); + numBackSlash += 1; + backSlashes += "\\"; + } + // eslint-disable-next-line no-magic-numbers + if (numBackSlash % 2 === 1) { + return ( + parseSexpToLeft( + data.delimStack, + data.s.slice(0, -1 - numBackSlash), + data.level + ) + + backSlashes + + '"' + ); + } data.delimStack.pop(); const newLevel = data.level - 1; if (newLevel === 0) { @@ -385,9 +406,11 @@ function endOfSexp(data: { return ( parseSexpToLeft( data.delimStack, - data.s.slice(0, -1), + data.s.slice(0, -1 - numBackSlash), newLevel - ) + '"' + ) + + backSlashes + + '"' ); } } diff --git a/test/sexps-test.ts b/test/sexps-test.ts index 3d00efd..d7e8a8f 100644 --- a/test/sexps-test.ts +++ b/test/sexps-test.ts @@ -238,6 +238,22 @@ mocha.describe("Sexp parsing functions", () => { "Vector 'sdfgdgf #125vfx(255 0 255)' -> '#125vfx(255 0 255)' " ); }); + mocha.it( + 'Escaped Quotes `not this \'[1 ("asd" ) "as\\"d" asdasd () ]`', + () => { + chai.assert.deepEqual( + s.getSexpToLeft( + 'not this \'[1 ("asd" ) "as\\"d" asdasd () ]' + ), + { + sexp: '\'[1 ("asd" ) "as\\"d" asdasd () ]', + startCol: 9, + startLine: 0, + }, + 'Vector `not this \'[1 ("asd" ) "as\\"d" asdasd () ]` -> `\'[1 ("asd" ) "as\\"d" asdasd () ]`' + ); + } + ); mocha.it("Gensym 'sdfgdgf #{g0 gdfgez754123245}'", () => { chai.assert.deepEqual( s.getSexpToLeft("sdfgdgf #{g0 gdfgez754123245}"), From 943f7920d5de6c8fb687243abd716c8e38b6a3cb Mon Sep 17 00:00:00 2001 From: Release-Candidate Date: Sat, 13 Jul 2024 11:20:15 +0200 Subject: [PATCH 2/3] Update package version Signed-off-by: Release-Candidate --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 954c8cb..0787489 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vscode-scheme-repl", "displayName": "Chez Scheme REPL", - "version": "0.7.0", + "version": "0.7.1", "preview": false, "publisher": "release-candidate", "description": "Support for Chez Scheme: Highlighting, autocompletion, documentation on hover and syntax checks.", From 1c0b41f9be2d74cf8d32fdf2b6a94ea3b54d99b0 Mon Sep 17 00:00:00 2001 From: Release-Candidate Date: Sat, 13 Jul 2024 11:22:38 +0200 Subject: [PATCH 3/3] Remove unnecessary comment for eslint Signed-off-by: Release-Candidate --- src/sexps.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sexps.ts b/src/sexps.ts index 06af454..6c9dfa7 100644 --- a/src/sexps.ts +++ b/src/sexps.ts @@ -377,7 +377,6 @@ function endOfSexp(data: { delimString: "{", }); } else if (data.s.endsWith('"') && data.delim === "Quote") { - // cHECK IF ESCAPED let toCheck = data.s.slice(0, -1); let numBackSlash = 0; let backSlashes = "";