Skip to content

Commit 614f856

Browse files
authored
Merge pull request #42 from theodevelop/feat/issue-39
feat: add Code Lens "N references" for Flex abbreviations (closes #39)
2 parents eb882a0 + 52a94a2 commit 614f856

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
All notable changes to the **Bison/Flex Language Support** extension will be documented in this file.
44

5-
## [1.5.2] - 2026-04-03
5+
## [1.5.2] - 2026-04-05
6+
7+
### Added
8+
9+
- **Flex — Code Lens for abbreviations** (#39): abbreviation definitions in the definitions section now show a clickable "N references" Code Lens, consistent with start conditions and Bison rules. Clicking opens the References panel with all `{ABBR}` usages in the rules section.
610

711
### Fixed
812

server/src/providers/codeLens.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { DocumentModel, BisonDocument, FlexDocument, isBisonDocument } from '../
33

44
/**
55
* Code Lenses:
6-
* Bison rules → "N references" + "⬤ entry point" (start symbol only)
7-
* Flex SC decls → "N references"
6+
* Bison rules → "N references" + "⬤ entry point" (start symbol only)
7+
* Flex SC decls → "N references"
8+
* Flex abbreviations → "N references"
89
*
910
* The "N references" lens triggers `bisonFlex.showReferences` (registered
1011
* client-side) which calls `editor.action.showReferences` with pre-built args.
@@ -71,5 +72,21 @@ function getFlexCodeLenses(doc: FlexDocument, uri: string): CodeLens[] {
7172
});
7273
}
7374

75+
for (const [name, abbr] of doc.abbreviations) {
76+
const line = abbr.location.start.line;
77+
const lensRange = Range.create(line, 0, line, 0);
78+
const refCount = doc.abbreviationRefs.get(name)?.length ?? 0;
79+
80+
lenses.push({
81+
range: lensRange,
82+
command: Command.create(
83+
`$(references) ${refCount} reference${refCount !== 1 ? 's' : ''}`,
84+
'bisonFlex.showReferences',
85+
uri,
86+
{ line, character: abbr.location.start.character },
87+
),
88+
});
89+
}
90+
7491
return lenses;
7592
}

tests/test-diagnostic-codes.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,35 @@ console.log('\n=== TEST: isWordPattern — complex patterns do not shadow keywor
622622
assert(unreachable.length >= 1, 'isWordPattern: simple [A-Z_]+ still shadows keyword "IF" → flex/unreachable-rule expected');
623623
}
624624

625+
// ─────────────────────────────────────────────────────────────────────────────
626+
// Issue #39 — Code Lens for abbreviations
627+
// ─────────────────────────────────────────────────────────────────────────────
628+
console.log('\n=== TEST: Issue #39 — Code Lens for abbreviations ===');
629+
630+
{
631+
const { getCodeLenses } = require('../server/src/providers/codeLens');
632+
const src = [
633+
'%option noyywrap',
634+
'DIGIT [0-9]+',
635+
'WORD [a-z]+',
636+
'%%',
637+
'{DIGIT} { return 1; }',
638+
'{DIGIT} { return 2; }',
639+
'%%',
640+
].join('\n');
641+
const doc = require('../server/src/parser/flexParser').parseFlexDocument(src);
642+
const lenses = getCodeLenses(doc, 'file:///test.l');
643+
644+
// DIGIT is on line 1, WORD on line 2
645+
const digitLens = lenses.find((l: any) => l.range.start.line === 1);
646+
const wordLens = lenses.find((l: any) => l.range.start.line === 2);
647+
648+
assert(!!digitLens, '#39: Code Lens produced for DIGIT abbreviation');
649+
assert(digitLens?.command?.title?.includes('2'), '#39: DIGIT lens shows 2 references (used twice in rules)');
650+
assert(!!wordLens, '#39: Code Lens produced for WORD abbreviation');
651+
assert(wordLens?.command?.title?.includes('0'), '#39: WORD lens shows 0 references (unused)');
652+
}
653+
625654
// ─────────────────────────────────────────────────────────────────────────────
626655
// Bison audit checks
627656
// ─────────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)