From 1d96305fc41a1fb860386dbcb7b98666ba2bd3ac Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Tue, 22 Feb 2022 10:15:06 -0500 Subject: [PATCH] Modify current count routine to only work for Feature.token Signed-off-by: Matthew Peveler --- src/count.ts | 11 +++++++++-- test/diagnostics.spec.ts | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/count.ts b/src/count.ts index fb4cfcd..13b68f9 100644 --- a/src/count.ts +++ b/src/count.ts @@ -28,7 +28,10 @@ export function countToken(tree: Tree, feature: Feature, token: string): number const cursor = tree.rootNode.walk(); while (true) { if (cursor.gotoFirstChild() || cursor.gotoNextSibling()) { - if (convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) { + if ( + feature === Feature.token && + convertTokenName(cursor.nodeType).toLowerCase() === tokenLower + ) { count++; } continue; @@ -41,7 +44,11 @@ export function countToken(tree: Tree, feature: Feature, token: string): number break; } } - if (hadSibling && convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) { + if ( + feature === Feature.token && + hadSibling && + convertTokenName(cursor.nodeType).toLowerCase() === tokenLower + ) { count++; } if (cursor.currentNode === tree.rootNode) { diff --git a/test/diagnostics.spec.ts b/test/diagnostics.spec.ts index fc4875a..116a2f1 100644 --- a/test/diagnostics.spec.ts +++ b/test/diagnostics.spec.ts @@ -63,6 +63,8 @@ describe('diagnostics', () => { }); }); + // Testing that we find tokens that are at end of lines, after tokens with + // children test('find all colon tokens', () => { const { tokens } = diagnostics( parseFile(Language.python, path.join(TEST_DATA, 'python', 'operators.py')),