Skip to content

Commit 7446f33

Browse files
committed
fix(tree-sitter): preserve Scala structural parsing
1 parent c8b5491 commit 7446f33

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎src/services/shared/fallback-extensions.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
*/
55
export const fallbackExtensions = [".txt", ".vb", ".scala", ".swift"] as const
66

7+
/**
8+
* Fallback extensions that do not have a structural parser. Scala and Swift
9+
* still support structural parsing outside code indexing.
10+
*/
11+
export const nonStructuralExtensions = [".txt", ".vb"] as const
12+
713
/**
814
* Check whether a file extension should bypass structural parsing.
915
*
@@ -12,3 +18,12 @@ export const fallbackExtensions = [".txt", ".vb", ".scala", ".swift"] as const
1218
export function isFallbackExtension(extension: string): boolean {
1319
return (fallbackExtensions as readonly string[]).includes(extension.toLowerCase())
1420
}
21+
22+
/**
23+
* Check whether a file extension should bypass structural parsing entirely.
24+
*
25+
* @param extension File extension, including the leading dot
26+
*/
27+
export function isNonStructuralExtension(extension: string): boolean {
28+
return (nonStructuralExtensions as readonly string[]).includes(extension.toLowerCase())
29+
}

‎src/services/tree-sitter/__tests__/plainTextIntegration.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import * as fs from "fs/promises"
1616
import { loadRequiredLanguageParsers } from "../languageParser"
1717
import { parseSourceCodeDefinitionsForFile } from "../index"
1818

19-
describe("Fallback Extension Integration Tests", () => {
19+
describe("Non-structural Extension Integration Tests", () => {
2020
beforeEach(() => {
2121
vi.clearAllMocks()
2222
})
2323

24-
it.each(["manual.txt", "legacy.vb", "service.scala", "client.swift"])(
24+
it.each(["manual.txt", "legacy.vb"])(
2525
"returns undefined for %s without loading a tree-sitter parser",
2626
async (filePath) => {
2727
const result = await parseSourceCodeDefinitionsForFile(filePath)

‎src/services/tree-sitter/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileExistsAtPath } from "../../utils/fs"
55
import { parseMarkdown } from "./markdownParser"
66
import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
77
import { QueryCapture } from "web-tree-sitter"
8-
import { isFallbackExtension } from "../shared/fallback-extensions"
8+
import { isNonStructuralExtension } from "../shared/fallback-extensions"
99

1010
// Private constant
1111
const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4
@@ -114,8 +114,8 @@ export async function parseSourceCodeDefinitionsForFile(
114114
return undefined
115115
}
116116

117-
// Fallback files have no structural definitions to extract
118-
if (isFallbackExtension(ext)) {
117+
// Files without a structural parser have no definitions to extract
118+
if (isNonStructuralExtension(ext)) {
119119
return undefined
120120
}
121121

0 commit comments

Comments
 (0)