@@ -550,6 +550,10 @@ def pretty_location(loc: clang.SourceLocation | clang.Cursor):
550
550
# location, but have an extent. Use the start of the extent instead.
551
551
extent_start = loc .extent .start # type: clang.SourceLocation
552
552
loc = extent_start
553
+ # NOTE: not using normpath_for_file() here because we don't want to convert
554
+ # bazel-out/blah/src/mongo/beep to src/mongo/beep. All paths output by pretty_location
555
+ # should be relative to the repo root. This is important for the browser to be able to
556
+ # load the file. We still want to use os.path.normpath to fix up foo/bar/../baz to foo/baz.
553
557
name = os .path .normpath (loc .file .name ) if loc .file else "<unknown>"
554
558
# return f"{name}({loc.line},{loc.column})" # MSVC format
555
559
return f"{ name } :{ loc .line } :{ loc .column } " # gcc format
@@ -743,6 +747,21 @@ def find_usages(mod: str, c: Cursor):
743
747
assert not ref .location .file or mod_for_file (ref .location .file ) is None
744
748
return
745
749
750
+ if c .kind == CursorKind .CALL_EXPR and c .referenced .kind != CursorKind .CONSTRUCTOR :
751
+ # For a call expression like a.b(c) or a::b(c) the whole thing is considered a reference of
752
+ # a.b, but unfortunately the reported location is that of a, while we'd really want it to be
753
+ # that of b. This was frequently resulting in two usage locations being reported for each
754
+ # method call. Luckily, in most cases, the first child of the call expression (or one of its
755
+ # transitive children) is the sub-expression a.b, which has a reference to b with the right
756
+ # location. So we can safely ignore the call expression and rely on the post-order traversal
757
+ # already adding a relevant used_from reference for this expression. The one exception is
758
+ # that for constructor calls, the child refers to the *type* a::b, rather than the specific
759
+ # constructor a::b::b() chosen, so we still need to add this location (even if not ideal) to
760
+ # ensure that we mark the constructor's usage. I ran this with an assert to check that this
761
+ # doesn't cause us to lose any usages, but it is too slow to keep (O(n^2) for n calls to a
762
+ # method in a TU, causing some TUs to take several minutes).
763
+ return
764
+
746
765
if is_local_decl (ref ):
747
766
return
748
767
0 commit comments