I actually did almost the same thing. You can see complete source code on Visual Localizer.
Basically you need to do two things:
- Obtain IVsTextView instance for the file
- call its SetSelection() method which takes range (start line, end line, start column, end column) as parameters. You may also want to call the EnsureSpanVisible() to scroll down.
Obtaining IVsTextView is quite easy as well. In my project (Visual Localizer) there's a class called DocumentViewsManager, located in VLlib/components that has fairly straightforward method called GetTextViewForFile(), which takes only file path as an argument. It does the following:
- use VsShellUtilities.IsDocumentOpen method to obtain IVsWindowFrame for given file path
- pass this to the VsShellUtilities.GetTextView method, which returns IVsTextView
Hope it helps.