I've been trying to get my feet wet with vs extensions & roslyn though I seem to have hit a roadblock pretty early on. I'm trying to detect when a file is saved, then analyse it to find certain base classes, properties etc.
I've got the following code in my package at the moment which successfully gets the contents of the saved file:
protected override void Initialize()
{
base.Initialize();
SetupEvents();
}
private DTE _dte;
private Events _dteEvents;
private DocumentEvents _dteDocEvents;
private void SetupEvents()
{
_dte = (DTE)GetService(typeof(SDTE));
_dteEvents = _dte.Events;
_dteDocEvents = _dteEvents.DocumentEvents;
_dteDocEvents.DocumentSaved += _dteDocEvents_DocumentSaved;
}
private void _dteDocEvents_DocumentSaved(Document document)
{
string text = document.GetDocumentText();
//var syntaxTree = Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(text);
}
I've got a breakpoint on the first line of my _dteDocEvents_DocumentSaved handler where I can see that the code is being hit. However, if I just uncomment the syntaxTree declaration line, my handler suddenly isn't getting called any more. This behaviour makes absolutely no sense to me, how can an additional line of code in my handler prevent the handler from being called at all?
Does anyone have any possible suggestions what could be going on here?
Thanks
James