Skip to content

Commit

Permalink
Merge pull request #1466 from sashton/custom-command-with-fn-metadata
Browse files Browse the repository at this point in the history
Fix currentTopLevelFunction function for metadata skipping
  • Loading branch information
PEZ authored Jan 22, 2022
2 parents 79c7f84 + bf2273c commit 6c87145
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Changes to Calva.
## [2.0.234] - 2022-01-16
- [Improve LSP startup feedback on status bar](https://github.com/BetterThanTomorrow/calva/pull/1454)
- [Fix errors in test output when fixtures throw exceptions](https://github.com/BetterThanTomorrow/calva/issues/1456).
- Fix: [Snippet in custom command doesn't work with function metadata] (https://github.com/BetterThanTomorrow/calva/issues/1463)


## [2.0.233] - 2022-01-07
- [Add experimental support for Test Explorer](https://github.com/BetterThanTomorrow/calva/issues/953)
Expand Down
7 changes: 7 additions & 0 deletions src/extension-test/unit/util/cursor-get-text-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ describe('get text', () => {
expect(getText.currentTopLevelFunction(a)).toEqual([range, b.model.getText(...range)]);
});

it('Finds top level function when function has metadata', () => {
const a = docFromTextNotation('(foo bar)•(deftest ^{:some :thing} a-test• (baz |gaz))');
const b = docFromTextNotation('(foo bar)•(deftest ^{:some :thing} |a-test|• (baz gaz))');
const range: [number, number] = [b.selectionLeft, b.selectionRight];
expect(getText.currentTopLevelFunction(a)).toEqual([range, b.model.getText(...range)]);
});

});

describe('getTopLevelForm', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/util/cursor-get-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export function currentTopLevelFunction(doc: EditableDocument): RangeAndText {
cursor.forwardWhitespace();
while (cursor.forwardSexp(true, true, true)) {
cursor.forwardWhitespace();
// skip over metadata, if present
while (cursor.getToken().raw.startsWith('^')) {
cursor.forwardSexp(true, false, true);
cursor.forwardWhitespace();
}
const symbol = cursor.getToken();
if (symbol.type === 'id') {
return [[cursor.offsetStart, cursor.offsetEnd], symbol.raw];
Expand Down

0 comments on commit 6c87145

Please sign in to comment.