These are two different features.
One is what VS calls
- highlighting other mentions of symbol under the cursor in the same file. This is certainly doable, as we already have all the necessary information for it, to drive Find All References. We just need to implement the corresponding
VS API for highlighting. There is an open
for that in the tracker - please vote for it!
Marking "unresolved references" as errors is somewhat trickier. Because Python is a dynamic language, static code analysis cannot really determine that the identifier does not exist in a fully reliable way. Consider code like this:
globals()['a'] = 123
Note that there is no direct assignment to 'a' here - it's done through a dict - and yet print(a) is a valid reference. Now something like the above code can still be tracked, but the moment you start doing something more complicated, e.g. using computed values
rather than literals to index globals(), it becomes much harder if not outright impossible.
Another problem is that Python doesn't really have definitions - it's all just assignments to variables, and those can be inside conditional blocks. E.g.:
a = 1
b = 1
Neither 'a' nor 'b' are guaranteed to be defined by the time control flow reaches print - in fact, as written, this will always be a runtime error. Should they be marked as error because there's no guarantee? That would be a false positive on many common Python
All in all, this is something that can certainly be done on a best-effort basis, but since it will always have some false positives due to the nature of the language, it's probably something that's best run on explicit request, rather than all the time in the
background. I believe that the
feature would cover that, once we implement it.