From a6dcca117b08b92c996bb9c3847e75ac9d1caf9a Mon Sep 17 00:00:00 2001 From: Steve Ashton Date: Wed, 12 Jan 2022 13:41:12 -0500 Subject: [PATCH] Fix forwardSexp function for metadata skipping --- CHANGELOG.md | 1 + src/cursor-doc/token-cursor.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 791f398d3..ef54d6088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changes to Calva. ## [Unreleased] - [Improve LSP startup feedback on status bar](https://github.com/BetterThanTomorrow/calva/pull/1454) +- 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) diff --git a/src/cursor-doc/token-cursor.ts b/src/cursor-doc/token-cursor.ts index 45d8d4b7c..535f41303 100644 --- a/src/cursor-doc/token-cursor.ts +++ b/src/cursor-doc/token-cursor.ts @@ -229,6 +229,7 @@ export class LispTokenCursor extends TokenCursor { if (this.getToken().type === 'close') { return false; } + const initialToken = this.getToken(); if (this.tokenBeginsMetadata()) { isMetadata = true; } @@ -258,7 +259,15 @@ export class LispTokenCursor extends TokenCursor { if (skipMetadata && this.getToken().raw.startsWith('^')) { this.next(); } else { - this.next(); + this.forwardWhitespace(skipComments); + // If the cursor is still pointed at the original token, + // or if the cursor is inside a nested sexp, move the cursor forward by one. + // Otherwise, the cursor has already moved past + // the original token, and should not be moved again + // for this invocation of forwardSexp. + if (token == initialToken || stack.length > 0) { + this.next(); + } if (stack.length <= 0) { return true; }