Unable to "Go To Definition" on django function

Aug 31, 2011 at 12:19 PM

I have created a new project from existing (django project) code. When I right click on any django function and click "Go To Definition", I get the error "Cannot go to definition x." When I try to run the code however, it runs just fine, no errors.

I am using the following software:
-PTVS 1.0
-Python 2.7 (x86)
-Visual Studio 2010
-Windows 7 (x64)

Django is installed in "C:\Python27\Lib\site-packages\django". I think the problem might be that PTVS does not search for the code files in the same directories as the python interpreter. I have already tried the following things myself:
-Because I did not have a PYTHONPATH environment variable, I created one with value "C:\Python27\Lib\site-packages\;C:\Python27\Lib\".
-I have added various relevant paths to the "Search Path" in the Solution Explorer.
-I have done Options - >"Generate Completion Database"  -> "Generate built-in and standard library database"

None of this had any effect. I believe this could be a bug because the library code files are available to the interpreter (the code runs) but i am unable to "Go To Definition" on library functions. Also, the problem is not django specific, I have the same issue with other libraries installed in site-packages.

Sep 1, 2011 at 2:03 AM

Thanks for the feedback - I think this is bug 396 http://pytools.codeplex.com/workitem/396 

Feel free to vote on it but I think it'll get fixed no matter what for 1.1.  We don't store the location for definitions in the cached analysis right now but it won't be hard to save it and read it back in.


Sep 1, 2011 at 10:12 AM

It could be that bug. However, there is a difference between my situation and the one described in the bug.

In my code the source (the .py files) for the library is available, the bug talks about a built-in library.

Sep 1, 2011 at 1:25 PM

My experience is exactly what arnokalkman describes.  The Go To Definition feature is the #1 reason I use an IDE vs a "simple text editor".   What I'm finding is that the feature works for anything defined in the current file or within any files in the same directory.  I did the same things arnokalkman did regarding setting up the environment, path, etc.  Despite the fact autocomplete is able to help me find a specific module and function to import, once imported, it is unable to Go To Definition.

It is with some excitement I await a stable release of PTVS!  Thanks!

Sep 1, 2011 at 2:26 PM
Edited Sep 1, 2011 at 2:29 PM

I actually think this is the by-design behavior (though obviously it's not the behavior you're expecting).

Go To Definition right now goes to definition only in user code (code within the current project).  

The reason is that our intellisense implementation handles your project and the packages in your site-packages differently: for packages in your Python installation, we generate a database containing all the intellisense info once and only update it periodically.  For your user code, we're constantly updating our code analysis so we can do things like "Find all References", "Refactor/Rename", and "Go to Definition" in real time. 

We could change the design so that our intellisense database contains file/line number, and try to come up with a performant way to balance keeping the database correct but not constantly scanning site-packages; and in fact we have an open feature for improvements to the intellisense database. We just didn't get to it in the 1.0 timeframe. 

I'll open a separate issue in the issue tracker for you: bug 496, "Go to Definition should be able to go to definitions in site-packages"