[ty] Skip global search for references if identifier is not externally visible (#25033)
## Summary
Part of https://github.com/astral-sh/ty/issues/1720 to improve the find
references performance.
Avoid searching for cross-file references if the identifier isn't
visible across modules. For example, avoid searching for cross-file
references for function scoped variables.
```py
def test():
x = 10
print(x<CURSOR)
```
`x` can never be visible outside of the function.