public void Attach(IVsTextView textViewAdapter) { // Try loading only once since this is a heavy operation. if (_loaded) { return; } _loaded = true; var shell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell; if (shell == null) { return; } IVsPackage package = null; var packageToBeLoadedGuid = new Guid(GuidList.GuidVsChromiumPkgString); shell.LoadPackage(ref packageToBeLoadedGuid, out package); // Ensure document is seen as loaded - This is necessary for the first // opened editor because the document is open before the package has a // chance to listen to TextDocumentFactoryService events. var textView = _adaptersFactoryService.GetWpfTextView(textViewAdapter); if (textView != null) { foreach (var buffer in textView.BufferGraph.GetTextBuffers(x => true)) { ITextDocument textDocument; if (_textDocumentFactoryService.TryGetTextDocument(buffer, out textDocument)) { _textDocumentService.OnDocumentOpen(textDocument); } } } }
private void TextDocumentFactoryServiceOnTextDocumentCreated(object sender, TextDocumentEventArgs textDocumentEventArgs) { _textDocumentService.OnDocumentOpen(textDocumentEventArgs.TextDocument); }