public static SyntaxTree GetSyntaxTree(this ITextSnapshot snapshot) { ITextBuffer buffer = snapshot.TextBuffer; SyntaxTree syntaxTree = null; // try get syntax tree lock (buffer.Properties.GetOrCreateSingletonProperty("SyntaxLock", () => new object())) { buffer.Properties.TryGetProperty <SyntaxTree>(typeof(SyntaxTree), out syntaxTree); // not found, or not for current snapshot if (syntaxTree == null || syntaxTree.Snapshot != snapshot) { // parse ISyntacticParser lexicalParser = null; if (buffer.Properties.TryGetProperty <ISyntacticParser>(typeof(ISyntacticParser), out lexicalParser)) { syntaxTree = lexicalParser.Parse(snapshot); // overwrite syntax tree for current snapshot if (snapshot == buffer.CurrentSnapshot) { buffer.Properties.RemoveProperty(typeof(SyntaxTree)); buffer.Properties.AddProperty(typeof(SyntaxTree), syntaxTree); } } } } return(syntaxTree); }
/// <summary> /// Initializes a new instance of the <see cref="RobotsTxtClassifier"/> class. /// </summary> /// <param name="registry">Classification registry.</param> public RobotsTxtClassifier(ITextBuffer buffer, ISyntacticParser syntacticParser, IClassificationTypeRegistryService registry) { buffer.Properties.AddProperty(typeof(ISyntacticParser), syntacticParser); _commentType = registry.GetClassificationType(PredefinedClassificationTypeNames.Comment); _delimiterType = registry.GetClassificationType("RobotsTxt/Delimiter"); _propertyNameType = registry.GetClassificationType("RobotsTxt/PropertyName"); _propertyValueType = registry.GetClassificationType("RobotsTxt/PropertyValue"); }
/// <summary> /// Registrytializes a new instance of the <see cref="RegistryClassifier"/> class. /// </summary> /// <param name="registry">Classification registry.</param> public RegistryClassifier(ITextBuffer buffer, ISyntacticParser syntacticParser, IClassificationTypeRegistryService registry) { buffer.Properties.AddProperty(typeof(ISyntacticParser), syntacticParser); }