fix(retrieval): end brace-language symbols at top-level braces

Code after a top-level closing brace belonged to the preceding function, for
example shell loops labeled as quote_toml. Attribute it to the module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian lechnerandClaude Opus 5.5 committed 2026-10-01 13:13:05 +02:00
1 parent e138c0277e
commit d60dd10c45
2 files changed
+4

No files matched your search

+1
View File
@@ -411,6 +411,7 @@ class RetrievalServerTests(unittest.TestCase):
('service.ts', 'export function load() {\n return 1;\n}\nexport const save = () => 2;\n', ['load', 'save']),
('service.cs', 'public class Service\n{\n public void Load()\n {\n }\n}\n', ['Service', 'Load']),
('setup.ps1', 'function Get-Result {\n return 1\n}\n', ['Get-Result']),
('build.sh', 'quote() {\n echo "$1"\n}\nfor shell in a b; do\n quote "$shell"\ndone\n', ['quote', '<module>']),
('schema.sql', 'CREATE TABLE users (id int);\nCREATE OR ALTER PROCEDURE dbo.GetUser AS SELECT 1;\n', ['users', 'dbo.GetUser']),
('Main.kt', 'fun main() {\n println(1)\n}\n', ['main']),
('config.toml', '[server]\nport = 1\n[client]\nport = 2\n', ['server', 'client']),
+3
View File
@@ -119,6 +119,9 @@ def sections(text: str, path: str):
if heading:
boundaries[number] = heading[1]
elif suffix in {".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".cs", ".java", ".kt", ".kts", ".go", ".rs", ".c", ".cpp", ".ps1", ".psm1", ".sh"}:
# A closing brace in column 0 ends a top-level declaration; code after it belongs to the module again.
if line.startswith("}"):
boundaries.setdefault(number + 1, "<module>")
symbol = re.match(
r"^\s*(?:(?:export|default|public|private|protected|internal|static|abstract|async|sealed|partial|pub)\s+)*"
r"(?:(?:class|interface|struct|enum|record|function|fun|fn|def)\s+([\w$-]+)"