Skip to content

Commit 84757b2

Browse files
committed
WIP add formatting test
1 parent 200b53a commit 84757b2

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

apps/vscode/src/providers/format.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,7 @@ async function formatBlock(doc: TextDocument, block: TokenMath | TokenCodeBlock,
233233
new Position(edit.range.end.line + block.range.start.line + 1, edit.range.end.character)
234234
);
235235
return new TextEdit(range, edit.newText);
236-
});
237-
238-
// Bail if any edit is out of range. We used to filter these edits out but
239-
// this could bork the cell.
240-
if (edits.some(edit => !blockRange.contains(edit.range))) {
241-
window.showInformationMessage(
242-
"Formatting edits were out of range and could not be applied to the code cell."
243-
);
244-
return [];
245-
}
236+
}).filter(edit => blockRange.contains(edit.range));
246237

247238
return adjustedEdits;
248239
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
See https://github.com/quarto-dev/quarto/issues/745 "Reformating R cell in VSCODE with air does not correctly close chunk."
2+
3+
```{r}
4+
list(foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar)
5+
```
6+
7+
```{r}
8+
9+
list(foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar, foobar)
10+
11+
```

apps/vscode/src/test/quartoDoc.test.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,43 @@ suite("Quarto basics", function () {
3030
assert.equal(before, after);
3131
});
3232

33-
roundtripSnapshotTest('valid-basics.qmd');
33+
// roundtripSnapshotTest('valid-basics.qmd');
3434

35-
roundtripSnapshotTest('valid-basics-2.qmd');
35+
// roundtripSnapshotTest('valid-basics-2.qmd');
3636

37-
roundtripSnapshotTest('valid-nesting.qmd');
37+
// roundtripSnapshotTest('valid-nesting.qmd');
3838

39-
roundtripSnapshotTest('invalid.qmd');
39+
// roundtripSnapshotTest('invalid.qmd');
4040

41-
roundtripSnapshotTest('capsule-leak.qmd');
41+
// roundtripSnapshotTest('capsule-leak.qmd');
42+
43+
test("cell formamtmtamt", async function () {
44+
const { doc } = await openAndShowTextDocument("cell-format.qmd");
45+
46+
//await vscode.commands.executeCommand("quarto.formatCell");
47+
setCursorPosition(3, 1);
48+
await vscode.commands.executeCommand("quarto.formatCell");
49+
await wait(6300);
50+
// const { before, after } = await roundtrip(doc);
51+
52+
// assert.equal(before, after);
53+
});
54+
55+
suiteTeardown(() => {
56+
vscode.window.showInformationMessage('All tests done!');
57+
});
4258
});
4359

60+
function setCursorPosition(line: number, character: number) {
61+
const editor = vscode.window.activeTextEditor;
62+
if (editor) {
63+
const position = new vscode.Position(line, character);
64+
const newSelection = new vscode.Selection(position, position);
65+
editor.selection = newSelection;
66+
editor.revealRange(newSelection, vscode.TextEditorRevealType.InCenter); // Optional: scroll to the new position
67+
}
68+
}
69+
4470
/**
4571
*
4672
* When the test is run on the dev's machine for the first time, saves the roundtripped file as a snapshot.

0 commit comments

Comments
 (0)