Skip to content

Commit

Permalink
Examine all forms in ns form
Browse files Browse the repository at this point in the history
* Fixes #2266
  • Loading branch information
PEZ committed Jul 30, 2023
1 parent ca8cf2f commit d93f5d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- Fix: [Calva can't seem to parse a ns form with metadata after 2.0.376](https://github.com/BetterThanTomorrow/calva/issues/2266)

## [2.0.381] - 2023-07-19

- Fix: [There are som nREPL messages missing from the diagnostics log](https://github.com/BetterThanTomorrow/calva/issues/2261)
Expand Down
9 changes: 6 additions & 3 deletions src/extension-test/unit/util/ns-form-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ describe('ns-form util', () => {
expect(nsFormUtil.nsFromCursorDoc(docFromTextNotation('(ns a-b.c-d) (a b c)|'))).toBe(
'a-b.c-d'
);
expect(
nsFormUtil.nsFromCursorDoc(docFromTextNotation('(ns ^:no-doc a-b.c-d) (a b c)|'))
).toBe('a-b.c-d');
});
it('finds in-ns', function () {
expect(nsFormUtil.nsFromCursorDoc(docFromTextNotation("(in-ns 'a-b.c-d) (a b c)|"))).toBe(
Expand Down Expand Up @@ -186,6 +183,12 @@ describe('ns-form util', () => {
'a'
);
});
// https://github.com/BetterThanTomorrow/calva/issues/2266
it('finds ns when symbol has metadata', function () {
expect(
nsFormUtil.nsFromCursorDoc(docFromTextNotation('(ns ^:no-doc a-b.c-d) (a b c)|'))
).toBe('a-b.c-d');
});
});

describe('nsFromText', function () {
Expand Down
11 changes: 6 additions & 5 deletions src/util/ns-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ function nsSymbolOfCurrentForm(
nsCheckCursor.forwardWhitespace(true);
const formToken = nsCheckCursor.getToken();
if (formToken.type === 'id' && ['ns', 'in-ns'].includes(formToken.raw)) {
nsCheckCursor.forwardSexp(true, true, true);
nsCheckCursor.forwardWhitespace(true);
const nsToken = nsCheckCursor.getToken();
if (nsToken.type === 'id') {
return formToken.raw === 'ns' ? nsToken.raw : nsToken.raw.substring(1);
while (nsCheckCursor.forwardSexp(true, false, true)) {
nsCheckCursor.forwardWhitespace(true);
const nsToken = nsCheckCursor.getToken();
if (nsToken.type === 'id') {
return formToken.raw === 'ns' ? nsToken.raw : nsToken.raw.substring(1);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test-data/ns_form.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(ns ^:a ns-form)
(def a)

0 comments on commit d93f5d8

Please sign in to comment.