Add regex filtering to clangd navigation

This commit is contained in:
2026-06-04 16:15:54 +02:00
parent ca452f46e1
commit 3c709f07e6
3 changed files with 28 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
Examples:
python scripts/dev/clangd_nav.py symbols --file src/app_core/brush_ui.h
python scripts/dev/clangd_nav.py symbols --file src/app_core/brush_ui.h --name-regex "execute_.*preset"
python scripts/dev/clangd_nav.py definition --file src/node_panel_brush.cpp --line 410 --column 30
python scripts/dev/clangd_nav.py references --file src/app_core/brush_ui.h --line 192 --column 43
"""
@@ -14,6 +15,7 @@ import json
import os
from pathlib import Path
import queue
import re
import subprocess
import sys
import threading
@@ -324,6 +326,13 @@ def run(args: argparse.Namespace) -> int:
compile_commands_dir = _find_compile_commands_dir(repo_root, args.compile_commands_dir)
file_path = _resolve_file(repo_root, args.file)
name_regex = None
if args.name_regex:
try:
name_regex = re.compile(args.name_regex, re.IGNORECASE if args.ignore_case else 0)
except re.error as exc:
raise SystemExit(f"invalid --name-regex: {exc}") from exc
if args.command == "references" and not args.background_index and not args.allow_incomplete_references:
raise SystemExit(
"references may be incomplete without clangd background indexing. "
@@ -372,6 +381,11 @@ def run(args: argparse.Namespace) -> int:
symbol for symbol in flattened
if needle in symbol["qualifiedName"].lower()
]
if name_regex:
flattened = [
symbol for symbol in flattened
if name_regex.search(symbol["qualifiedName"])
]
result_count = len(flattened)
result, truncated = _limit_results(flattened, args.max_results)
elif command == "hover":
@@ -430,6 +444,13 @@ def main(argv: list[str]) -> int:
parser.add_argument("--clangd", default="clangd", help="clangd executable path.")
parser.add_argument("--timeout", type=float, default=20.0, help="Request timeout in seconds.")
parser.add_argument("--name", help="Case-insensitive symbol-name filter for symbols command.")
parser.add_argument("--name-regex", help="Regex filter for symbols command, matched against qualifiedName.")
parser.add_argument(
"--ignore-case",
action=argparse.BooleanOptionalAction,
default=True,
help="Use case-insensitive --name-regex matching. Enabled by default.",
)
parser.add_argument("--max-results", type=int, default=100, help="Maximum locations/symbols to print; <=0 disables.")
parser.add_argument(
"--background-index",