public async Task UpdateDocumentAsync(bool forceUpdate = false) { await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var activeDocument = DocumentHelper.GetActiveDocument(Dte); if (activeDocument == null) { return; } CodeDocumentViewModel.FilePath = activeDocument.FullName; // Do we need to change the side where the margin is displayed if (_margin?.MarginSide != null && _margin?.MarginSide != Settings.Default.MarginSide && Dte != null) { var filename = activeDocument.FullName; Dte.ExecuteCommand("File.Close"); Dte.ExecuteCommand("File.OpenFile", filename); } try { if (forceUpdate) { _cache = null; CodeDocumentViewModel.CodeDocument.Clear(); } // Do we have a cached version of this document if (_cache != null) { CodeDocumentViewModel.CodeDocument = _cache; } // If not show a loading item if (!CodeDocumentViewModel.CodeDocument.Any()) { CodeDocumentViewModel.CodeDocument = CreateLoadingItem(); } var codeItems = await SyntaxMapper.MapDocumentAsync(activeDocument, this, _workspace); if (codeItems == null) { // CodeNav for document updated, no results return; } // Filter all null items from the code document SyntaxMapper.FilterNullItems(codeItems); // Sort items CodeDocumentViewModel.SortOrder = Settings.Default.SortOrder; SortHelper.Sort(codeItems, Settings.Default.SortOrder); // Set currently active codeitem HighlightHelper.SetForeground(codeItems); // Set the new list of codeitems as DataContext CodeDocumentViewModel.CodeDocument = codeItems; _cache = codeItems; // Apply current visibility settings to the document VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel); // Apply bookmarks LoadBookmarksFromStorage(); BookmarkHelper.ApplyBookmarks(CodeDocumentViewModel, Dte?.Solution?.FileName); // Apply history items LoadHistoryItemsFromStorage(); HistoryHelper.ApplyHistoryIndicator(CodeDocumentViewModel); } catch (Exception e) { LogHelper.Log("Error running UpdateDocument", e); } try { // Sync all regions OutliningHelper.SyncAllRegions(OutliningManagerService, TextView, CodeDocumentViewModel.CodeDocument); // Should the margin be shown and are there any items to show, if not hide the margin VisibilityHelper.SetMarginHeight(_row, CodeDocumentViewModel.CodeDocument); } catch (Exception e) { LogHelper.Log("Error finishing UpdateDocument", e); } }