Skip to content

Commit d3f0ef5

Browse files
author
Eric Wheeler
committed
feat: add support for enum declarations in tree-sitter TypeScript parser
Signed-off-by: Eric Wheeler <[email protected]>
1 parent 5d8e11a commit d3f0ef5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,30 @@ describe("parseSourceCodeDefinitions", () => {
486486
expect(result).toContain("VSCodeCheckbox")
487487
expect(result).toContain("VSCodeCheckboxProps")
488488
})
489+
490+
it("should parse enum declarations", async function () {
491+
const enumContent = `
492+
/**
493+
* Log levels for application logging
494+
* Used throughout the application to control log output
495+
* @enum {number}
496+
*/
497+
enum LogLevel {
498+
/** Critical errors that need immediate attention */
499+
Error = 1,
500+
/** Warning messages for potential issues */
501+
Warning = 2,
502+
/** Informational messages about normal operation */
503+
Info = 3,
504+
/** Detailed debug information */
505+
Debug = 4
506+
}
507+
`
508+
509+
const result = await testParseSourceCodeDefinitions("/test/enums.tsx", enumContent)
510+
expect(result).toBeDefined()
511+
expect(result).toContain("LogLevel")
512+
// Test that the enum name is captured
513+
expect(result).toContain("enum LogLevel")
514+
})
489515
})

src/services/tree-sitter/queries/typescript.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- module declarations
77
- arrow functions (lambda functions)
88
- switch/case statements with complex case blocks
9+
- enum declarations with members
910
*/
1011
export default `
1112
(function_signature
@@ -56,4 +57,8 @@ export default `
5657
5758
; Default clause
5859
(switch_default) @definition.default
60+
61+
; Enum declarations
62+
(enum_declaration
63+
name: (identifier) @name.definition.enum) @definition.enum
5964
`

0 commit comments

Comments
 (0)