Variables Highlighting

Dec 26, 2013 at 1:52 PM
Hi,

Are you planning to implement variables highlighting in the editor? espcially in python, this is very important...

(just to be clear, I mean that one you stand or marking a variable, all the appearances of this variable in the rest of the file are highlighted)
Coordinator
Dec 26, 2013 at 3:17 PM
Yup, we have a feature request tracking this:
https://pytools.codeplex.com/workitem/129

Note that we do have "Find all references", which is semantically almost the same, just less convenient.
Dec 28, 2013 at 9:51 AM
I have to completly disagree. You want to track a variable in the context of a code. You want to see its "evolvement". You want to see how other variables were used in the same context. And you want to see it at one glance. This is far more sophisticated usage from "find all reference". Actually, maybe it's not more sophisticated, just serves different intentions
Coordinator
Dec 28, 2013 at 9:46 PM
My point is that the feature in the same in terms of what information it presents; it just presents it in a different way that, as you rightly note, is not appropriate for some scenarios. That's why we do track it as a separate feature :) but the knowledge of what variable is referenced where is already there, so this feature is really about bolting on the appropriate UI.

BTW, this is one of those features that can serve as a good intermediate-level entry point for an external contributor, if anyone's interested (to remind, we accept pull requests!). "Find All References" code can be used as an example of how to interact with the code model that would be backing it. And we're not actively working on this for the current release, so there wouldn't be duplication of effort.
Dec 29, 2013 at 8:15 AM
Edited Dec 29, 2013 at 8:16 AM
I would love to take part, but never did something like that before. If you guys will be willing to help me get started, I'm in. Also, I already have a bunch of other productiveness related issues, so maybe i'll be able to contribute on those too.
Coordinator
Dec 29, 2013 at 9:30 AM
If you want to give it a try, I'll be happy to help you set things up and guide around the code!

For setting up the build, we have a page at the wiki. Note that you really only need to build the core PythonTools project (and dependencies), so you don't need all the various external dependencies like PyKinect and HPC for this; you can just unload the corresponding projects. So the only thing you need is VS itself, and the VS SDK.

For the actual task at hand, we don't really have a comprehensive code guide, but in this case it should be relatively straightforward to just read the code itself, especially since all the pieces involved are already implemented elsewhere. You will probably want to start by looking at FindAllReferences method here:
https://pytools.codeplex.com/SourceControl/latest#Python/Product/PythonTools/PythonTools/Navigation/EditFilter.cs

This shows how to retrieve the code analysis information for the current position in the editor, and how to get "variables" (which are basically identifiers, either defined right here or a definition referenced from another point) and their locations in particular.

To see how to highlight them in the editor, you can have a look at the class that implements matched brace highlighting here (WatchBraceHighlights is the entry point that registers events etc, and is called from EditorFilter.cs):
https://pytools.codeplex.com/SourceControl/latest#Python/Product/PythonTools/PythonTools/Editor/BraceMatcher.cs

The logic for cursor tracking etc will be largely the same, except that all the parsing logic is much simpler because you'd just use the code analysis information - so you don't need to bother with manually parsing things, keeping track of comments etc.

I'll be happy to answer any more specific questions about the code, build etc that you might have once you start digging into it - you can ask here on the forum, use CodePlex contact user form, or just email me at pminaev@microsoft.com.
Dec 29, 2013 at 1:19 PM
Thanks, that seems comprehensive enough to start with :)