Skip to content

Commit

Permalink
Merge pull request #2659 from BetterThanTomorrow/2655-top-level-eval-…
Browse files Browse the repository at this point in the history
…of-ignores

Add test for making sure the ignore marker is not included  in top le…

* Fixes #2655
  • Loading branch information
PEZ authored Oct 29, 2024
2 parents 6b6d861 + 4272c0c commit a8910fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes to Calva.

- [Add extension when contexts for Calva states such as project root, session type, ns](https://github.com/BetterThanTomorrow/calva/issues/2652)
- Fix: [Calva internals: The `backwardSexp` function can't handle skipping ignored forms, even though it says it can](https://github.com/BetterThanTomorrow/calva/issues/2657)
- Fix: [Keep support for evaluating top level form in ignored forms when at top level](https://github.com/BetterThanTomorrow/calva/issues/2655)

## [2.0.480] - 2024-10-21

Expand Down
4 changes: 3 additions & 1 deletion docs/site/evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Some of the commands also let you choose what should happen with the results:
* The `line` style is the default.
* The `ignore` style will put an ignore marker (`#_`) before the result.
* The `rcf` style will wrap the result in a rich comment form ( `(comment ...)`).

Here are some example keybindings for using the different comment styles with the **Evaluate Top Level Form (defun) to Comment** command:

```jsonc
Expand Down Expand Up @@ -108,6 +108,8 @@ The **current top-level form** means top-level in a structural sense. It is _not

An ”exception” is introduced by the `comment` form. It will create a new top level context, so that any forms immediately inside a `(comment ...)` form will be considered top-level by Calva. This is to support a workflow with what is often referred to the [Rich Comments](rich-comments.md).

A special case is ignored forms (using the `#_` marker) at the top level. They will always be selected as top level forms separately from their ignore marker, enabling evaluating them as top level forms. Similar to Rich Comments.

At the top level the selection of which form is the current top level form follows the same rules as those for [the current form](#current-form).

### Evaluate Enclosing Form
Expand Down
14 changes: 14 additions & 0 deletions src/extension-test/unit/cursor-doc/token-cursor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,13 @@ describe('Token Cursor', () => {
const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].active);
expect(cursor.rangeForDefun(a.selections[0].active)).toEqual(textAndSelection(b)[1]);
});
// https://github.com/BetterThanTomorrow/calva/issues/2655
it('Does not include ignore marker', () => {
const a = docFromTextNotation('a #_ [b (c|)] [d]');
const b = docFromTextNotation('a #_ |[b (c)]| [d]');
const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].active);
expect(cursor.rangeForDefun(a.selections[0].active)).toEqual(textAndSelection(b)[1]);
});
describe('Rich Comment Form top level context', () => {
it('Finds range for a top level form inside a comment', () => {
const a = docFromTextNotation('aaa (comment [bbb cc|c] ddd)');
Expand Down Expand Up @@ -954,6 +961,13 @@ describe('Token Cursor', () => {
const cursor: LispTokenCursor = a.getTokenCursor(0);
expect(cursor.rangeForDefun(a.selections[0].anchor)).toEqual(textAndSelection(b)[1]);
});
// https://github.com/BetterThanTomorrow/calva/issues/2655
it('Does not include ignore marker', () => {
const a = docFromTextNotation('aaa (comment #_ [bbb ccc|] ddd)');
const b = docFromTextNotation('aaa (comment #_ |[bbb ccc]| ddd)');
const cursor: LispTokenCursor = a.getTokenCursor(a.selections[0].active);
expect(cursor.rangeForDefun(a.selections[0].active)).toEqual(textAndSelection(b)[1]);
});
});
});

Expand Down

0 comments on commit a8910fe

Please sign in to comment.