I am attempting to extend visual studio functionality by adding support
for a language I frequently need to use.
I am trying to setup outlining (collapsible regions) for code written
in the editor. I have set AutoOutlining to true. The VS SDK documents
say that this should then cause VS to automatically call ParseSource
and provide the AuthoringSink for my code to then fill with the hidden
(collapsible) regions. My problem is that ParseSource is never being
called.
Have I misunderstood what to do? Or am I just missing something? It
appears the *only* time I can get ParseSource to fire, is when I right
click some of the code in the editor, and chose "goto definition", it
then correctly calls ParseSource with "Goto" as the reason. This is the
only time it seems to fire. It is not being automatically called when
the document loads as the SDK documentation suggests.
Any help would be appreciated.
Andy Savage.
Related sections of code follow:
public override LanguagePreferences GetLanguagePreferences()
{
LanguagePreferences preferences = new
LanguagePreferences(this.Site, typeof(ASLanguageService).GUID,
this.Name);
preferences.Init();
preferences.AutoOutlining = true;
// <.. Other preferences cut from here to make this
snippet shorter ...>
return preferences;
}
public override AuthoringScope ParseSource(ParseRequest req)
{
Debug.WriteLine(String.Format("ParseSource at ({0}:{1}),
reason {2}", req.Line, req.Col, req.Reason));
// <... code to generate and walk AST here ommited in
snippet ...>
// Always Need To Return A Valid Authoring Scope
return new ASAuthoringScope();
}
nospam@starsphere.net - 22 Jul 2006 03:24 GMT
After a day of searching I seem to have found the answer. There are
several steps you need to do:
1) Implement the IOleComponent interface as part of your VSPackage.
2) Register your package with the OleComponentManager with parameters
indicating idle time.
3) Implement your FDoIdle method (from the IOleComponent interface) to
call your language service's DoIdle(...) method.
More information on steps 1-3 can be found at:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=192211&SiteID=1
4) Override your language service OnIdle function to tell the Source
object it has not been parsed. Something like:
public override void OnIdle(bool periodic)
{
Source src = GetSource(this.LastActiveTextView);
if (src != null && src.LastParseTime == Int32.MaxValue)
{
src.LastParseTime = 0;
}
base.OnIdle(periodic);
}
This will then cause the ParseSource(...) to be called as expected.
Most of this is shown in the IronPythonIntegration\LanguageService
example. However it is not at all documented in the SDK help. I feel it
should be mentioned, particularly in the MPF section steps specifically
to add outlining.