
Hi,
I'm trying to parse some VB code using the following extension method, but it fails with errors regarding imports section:
public static IParseData Parse(this ISyntaxLanguage language, string header, string body, string footer)
{
language.ThrowArgumentNullException("language");
var parser = language.GetParser();
if (parser == null)
{
returnnull;
}
var codeDocument = newCodeDocument { Language = language };
codeDocument.SetHeaderAndFooterText(header, footer);
codeDocument.SetText(body);
var snapshot = codeDocument.CurrentSnapshot;
var reader = snapshot.GetReader(0); // should this be: -snapshot.HeaderText.Length?
var parseRequest = newParseRequest(Guid.NewGuid().ToString(), reader.BufferReader, language, codeDocument) { Snapshot = snapshot };
return parser.Parse(parseRequest);
}
The header is:
Public Partial Class MyClass
The body:
Sub MySub
End Sub
And the footer
End Class
I think it is failing because it does not consider the header when parsing the code. When the syntax editor returns the parse result for the same VB code, I note the snapshot start point is -27 and the EndPoint is larger than the snapshot I get from the code above. Is there some way to create a new snapshot for document or to modify the current one to use the header and footer?
Thanks in advance,
Nick
[Modified 11 years ago]