private void EnsureBufferHasTokenizer(IContentType contentType, ITextBuffer buffer) { if (contentType.IsOfType(PowerShellConstants.LanguageName) && !buffer.Properties.ContainsProperty(BufferProperties.PowerShellTokenizer)) { IPowerShellTokenizationService psts = new PowerShellTokenizationService(buffer); buffer.PostChanged += (o, args) => psts.StartTokenization(); buffer.Properties.AddProperty(BufferProperties.PowerShellTokenizer, psts); } }
private static void TextBufferFactoryService_TextBufferCreated(object sender, TextBufferCreatedEventArgs e) { e.TextBuffer.ContentTypeChanged += TextBuffer_ContentTypeChanged; if (e.TextBuffer.ContentType.IsOfType("PowerShell")) { var psts = new PowerShellTokenizationService(e.TextBuffer); _gotoDefinitionCommand.AddTextBuffer(e.TextBuffer); e.TextBuffer.ChangedLowPriority += (o, args) => psts.StartTokenization(); e.TextBuffer.Properties.AddProperty("HasTokenizer", true); } }
static void TextBuffer_ContentTypeChanged(object sender, ContentTypeChangedEventArgs e) { var buffer = sender as ITextBuffer; if (buffer == null) { return; } if (e.AfterContentType.IsOfType("PowerShell") && !buffer.Properties.ContainsProperty("HasTokenizer")) { var psts = new PowerShellTokenizationService(buffer); _gotoDefinitionCommand.AddTextBuffer(buffer); buffer.ChangedLowPriority += (o, args) => psts.StartTokenization(); buffer.Properties.AddProperty("HasTokenizer", true); } }