Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(cpp): use byte-safe AST node text (#1734)
hushen5793308358b1
diff --git a/packages/core/src/repowise/core/ingestion/extractors/visibility.py b/packages/core/src/repowise/core/ingestion/extractors/visibility.pyindex 9cd50bd87..ee97dfb7e 100644--- a/packages/core/src/repowise/core/ingestion/extractors/visibility.py+++ b/packages/core/src/repowise/core/ingestion/extractors/visibility.py@@ -16,6 +16,8 @@ import refrom collections.abc import Callablefrom typing import TYPE_CHECKING+from .helpers import node_text+if TYPE_CHECKING:from tree_sitter import Node@@ -412,7 +414,7 @@ def _has_export_marker(def_node: Node, src: str) -> bool:sibling = def_node.prev_siblingseen = 0while sibling is not None and seen < 4:- text = src[sibling.start_byte : sibling.end_byte]+ text = node_text(sibling, src)if any(marker in text for marker in _CPP_EXPORT_MARKERS):return Truesibling = sibling.prev_sibling@@ -420,7 +422,7 @@ def _has_export_marker(def_node: Node, src: str) -> bool:# Also check the def_node's own leading children — some grammars# nest the declspec inside the function_definition.for child in def_node.children[:3]:- text = src[child.start_byte : child.end_byte]+ text = node_text(child, src)if any(marker in text for marker in _CPP_EXPORT_MARKERS):return Truereturn False@@ -430,7 +432,7 @@ def _has_file_scope_static(def_node: Node, src: str) -> bool:"""Return True if a ``static`` storage-class specifier appears in the leading declarators."""for child in def_node.children[:4]:if child.type == "storage_class_specifier":- text = src[child.start_byte : child.end_byte]+ text = node_text(child, src)if "static" in text:return Truereturn Falsediff --git a/packages/core/src/repowise/core/ingestion/parser_helpers.py b/packages/core/src/repowise/core/ingestion/parser_helpers.pyindex af48000de..c3b5d31d2 100644--- a/packages/core/src/repowise/core/ingestion/parser_helpers.py+++ b/packages/core/src/repowise/core/ingestion/parser_helpers.py@@ -113,7 +113,7 @@ def _qualified_cpp_parent(name_node: Node, src: str) -> str | None:scope = parent.child_by_field_name("scope")if scope is None:return None- text = src[scope.start_byte : scope.end_byte].strip()+ text = node_text(scope, src).strip()# ``scope`` may itself be a qualified path (``NS::Foo``); take the# last component — that's the immediate enclosing type.return text.rsplit("::", 1)[-1] or Nonediff --git a/tests/unit/ingestion/test_cpp_extractors.py b/tests/unit/ingestion/test_cpp_extractors.pyindex ae1d779f6..8ce2e5ee1 100644--- a/tests/unit/ingestion/test_cpp_extractors.py+++ b/tests/unit/ingestion/test_cpp_extractors.py@@ -121,6 +121,18 @@ void Free() { }assert by_name["Free"].kind == "function"assert by_name["Free"].parent_name is None+ def test_qualified_definition_after_multibyte_text_binds_to_class(+ self, parser: ASTParser+ ) -> None:+ src = """\+// Author: 李+void Foo::DoWork() { }+""".encode()+ result = parser.parse_file(_file(), src)+ sym = next(s for s in result.symbols if s.name == "DoWork")+ assert sym.kind == "method"+ assert sym.parent_name == "Foo"+def test_dllexport_marks_exported_symbol(self, parser: ASTParser) -> None:src = b"""\extern "C" __declspec(dllexport) HRESULT DllRegisterServer(void) { return 0; }@@ -130,6 +142,16 @@ extern "C" __declspec(dllexport) HRESULT DllRegisterServer(void) { return 0; }assert sym.visibility == "public"assert sym.is_exported_symbol is True+ def test_dllexport_after_multibyte_text_marks_exported_symbol(self, parser: ASTParser) -> None:+ src = """\+// Author: 李+extern "C" __declspec(dllexport) HRESULT DllRegisterServer(void) { return 0; }+""".encode()+ result = parser.parse_file(_file(), src)+ sym = next(s for s in result.symbols if s.name == "DllRegisterServer")+ assert sym.visibility == "public"+ assert sym.is_exported_symbol is True+def test_two_letter_i_prefix_not_misclassified(self, parser: ASTParser) -> None:"""``IO`` / ``ID`` etc. aren't COM interfaces — must stay extends."""src = b"""\