Skip to content

Commit

Permalink
Merge pull request #26 from Release-Candidate/warning_opoup_on_unsave…
Browse files Browse the repository at this point in the history
…d_eval_and_escaped_quote_parsing

Warning popup on unsaved changes when evaluating inline and fix parsing of escaped quotes
  • Loading branch information
Release-Candidate authored Jul 13, 2024
2 parents c6308b5 + 1c0b41f commit c09d540
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
10 changes: 10 additions & 0 deletions src/evalREPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
26 changes: 24 additions & 2 deletions src/sexps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ function endOfSexp(data: {
delimString: "{",
});
} else if (data.s.endsWith('"') && data.delim === "Quote") {
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) {
Expand All @@ -385,9 +405,11 @@ function endOfSexp(data: {
return (
parseSexpToLeft(
data.delimStack,
data.s.slice(0, -1),
data.s.slice(0, -1 - numBackSlash),
newLevel
) + '"'
) +
backSlashes +
'"'
);
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/sexps-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand Down

0 comments on commit c09d540

Please sign in to comment.