From d93f5d8c4699b2f5d75fed9237641bf59fd1146f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Sun, 30 Jul 2023 17:02:11 +0200 Subject: [PATCH] Examine all forms in ns form * Fixes #2266 --- CHANGELOG.md | 2 ++ src/extension-test/unit/util/ns-form-test.ts | 9 ++++++--- src/util/ns-form.ts | 11 ++++++----- test-data/ns_form.cljc | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 test-data/ns_form.cljc diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a85807ef..2b61415c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/extension-test/unit/util/ns-form-test.ts b/src/extension-test/unit/util/ns-form-test.ts index 322438817..6bfc9cdf2 100644 --- a/src/extension-test/unit/util/ns-form-test.ts +++ b/src/extension-test/unit/util/ns-form-test.ts @@ -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( @@ -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 () { diff --git a/src/util/ns-form.ts b/src/util/ns-form.ts index 9988dd395..0aae8aa88 100644 --- a/src/util/ns-form.ts +++ b/src/util/ns-form.ts @@ -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); + } } } } diff --git a/test-data/ns_form.cljc b/test-data/ns_form.cljc new file mode 100644 index 000000000..04fe3aa4a --- /dev/null +++ b/test-data/ns_form.cljc @@ -0,0 +1,2 @@ +(ns ^:a ns-form) +(def a) \ No newline at end of file