Skip to content

Commit

Permalink
Merge pull request #1346 from BetterThanTomorrow/1345-top-level-deref
Browse files Browse the repository at this point in the history
Fix select top level deref in comment
  • Loading branch information
PEZ committed Oct 17, 2021
2 parents 1840fe2 + 1ff22cd commit ee1b956
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changes to Calva.

## [Unreleased]
- [Select top level form fails for top level derefs in comment forms](https://github.com/BetterThanTomorrow/calva/issues/1345)

## [2.0.217] - 2021-10-17
- [Support setting the cider-nrepl print-fn to whatever](https://github.com/BetterThanTomorrow/calva/issues/1340)
Expand Down
3 changes: 2 additions & 1 deletion src/cursor-doc/token-cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export class LispTokenCursor extends TokenCursor {
backwardListOfType(openingBracket: string): boolean {
let cursor = this.clone();
while (cursor.backwardList()) {
if (cursor.getPrevToken().raw === openingBracket) {
if (cursor.getPrevToken().raw.endsWith(openingBracket)) {
this.set(cursor);
return true;
}
Expand Down Expand Up @@ -610,6 +610,7 @@ export class LispTokenCursor extends TokenCursor {
rangeForDefun(offset: number, commentCreatesTopLevel = true): [number, number] {
const cursor = this.doc.getTokenCursor(offset);
let lastCandidateRange: [number, number] = cursor.rangeForCurrentForm(offset);
console.log(lastCandidateRange);
while (cursor.forwardList() && cursor.upList()) {
const commentCursor = cursor.clone();
commentCursor.backwardDownList();
Expand Down
6 changes: 6 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 @@ -500,6 +500,12 @@ describe('Token Cursor', () => {
const cursor: LispTokenCursor = a.getTokenCursor(0);
expect(cursor.rangeForDefun(a.selectionLeft)).toEqual(textAndSelection(b)[1]);
});
it('Finds top level form when deref in comment', () => {
const a = docFromTextNotation('(comment @(foo [bar|]))');
const b = docFromTextNotation('(comment |@(foo [bar])|)');
const cursor: LispTokenCursor = a.getTokenCursor(0);
expect(cursor.rangeForDefun(a.selectionLeft)).toEqual(textAndSelection(b)[1]);
})
});

describe('Location State', () => {
Expand Down
3 changes: 3 additions & 0 deletions test-data/select.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(comment
@(rf/subscribe [:foo])
)

0 comments on commit ee1b956

Please sign in to comment.