
I have an issue when using the .SourceProjectContent.LoadForCode() method of DotNetProjectResolver object.
The problem is that the event SourceProjectContent.SemanticParseComplete object of does not get raised consistently after calling LoadForCode method. Sometimes the event is raised and sometimes not.
Which means it is not possible to ensure that the DotNetProjectResolver object has parsed the new code loaded before using it.
I will explain the situation in my code.
I have a document object _memorysourceDocument and a DotNetProjectResolver object _resolver.
I need these two to be always in sync, because I use the offsets from AstNodes in ICompilationUnit of the _resolver to extract segments of code from _memorysourceDocument.Text.
So I make the call
LoadForCode(new CSharpSyntaxLanguage(), fileName, _memorysourceDocument.Text)
everytime the _memorysourceDocument.Text is updated.
But sometimes by the time I used the _resolver, the parsing is not complete and the AstNodes offsets are all wrong with respect to latest _memorysourceDocument.
I have tried using SemanticParserService.WaitForParse method. But doesn't help.
Below is the code
The problem is that the event SourceProjectContent.SemanticParseComplete object of does not get raised consistently after calling LoadForCode method. Sometimes the event is raised and sometimes not.
Which means it is not possible to ensure that the DotNetProjectResolver object has parsed the new code loaded before using it.
I will explain the situation in my code.
I have a document object _memorysourceDocument and a DotNetProjectResolver object _resolver.
I need these two to be always in sync, because I use the offsets from AstNodes in ICompilationUnit of the _resolver to extract segments of code from _memorysourceDocument.Text.
So I make the call
LoadForCode(new CSharpSyntaxLanguage(), fileName, _memorysourceDocument.Text)
everytime the _memorysourceDocument.Text is updated.
But sometimes by the time I used the _resolver, the parsing is not complete and the AstNodes offsets are all wrong with respect to latest _memorysourceDocument.
I have tried using SemanticParserService.WaitForParse method. But doesn't help.
Below is the code
ctor
{
_resolver.SourceProjectContent.SemanticParseComplete += new SemanticParseEventHandler(SourceProjectContent_SemanticParseComplete);
}
private DotNetProjectResolver _resolver;
private Document _memorysourceDocument;
void SynchronizeDocument(string fileName)
{
_memorysourceDocument.LoadFile(fileName);
_resolver.SourceProjectContent.LoadForCode(new CSharpSyntaxLanguage(), fileName, _memorysourceDocument.Text);
}
void SourceProjectContent_SemanticParseComplete(object sender, SemanticParseEventArgs e)
{
...
}