Definitions and references are powered by the symbol list, which comes from every file that’s currently being indexed in the current project as well as any files that happen to be open.
You can use View Package File
from the command palette to open Default/symbol.py
and see the implementation of this. In particular, lookup_symbol()
and lookup_references()
perform the symbol lookups and the on_hover
event handler in the ShowDefinitions
event listener is responsible for displaying the popup.
From looking at the implementation you can see that it combines symbols from the symbol index as well as the list of open files, but it doesn’t try to filter those based on the language or type of file that’s currently being used.
As such I’m not aware of any default way to get it to constrain the results based on the source languages, but the code here could be modified via an override or replaced wholesale with something that has that sort of logic in it.
If I had to guess I would say that it works this way due to a combination of most projects would only contain the same sorts of files, and that if they don’t the symbols may be related anyway (for example if you were writing native code to combine with Java code).