Example #1
0
        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                var result = e.Result as BackgroundWorkerResult;

                if (result?.CodeItems == null)
                {
                    LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated, no results");
                    return;
                }

                // Filter all null items from the code document
                SyntaxMapper.FilterNullItems(result.CodeItems);

                // Do we need to update the DataContext?
                var areEqual = AreDocumentsEqual(CodeDocumentViewModel.CodeDocument, result.CodeItems);
                if (result.ForceUpdate == false && areEqual)
                {
                    LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated, document did not change");

                    // Should the margin be shown and are there any items to show, if not hide the margin
                    VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument);

                    return;
                }

                // Set the new list of codeitems as DataContext
                CodeDocumentViewModel.CodeDocument = result.CodeItems;
                _cache = result.CodeItems;

                // Set currently active codeitem
                HighlightHelper.SetForeground(CodeDocumentViewModel.CodeDocument);

                // Should the margin be shown and are there any items to show, if not hide the margin
                VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument);

                // Apply current visibility settings to the document
                VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel.CodeDocument);

                // Sync all regions
                OutliningHelper.SyncAllRegions(OutliningManager, TextView, CodeDocumentViewModel.CodeDocument);

                // Sort items
                CodeDocumentViewModel.SortOrder = Settings.Default.SortOrder;
                SortHelper.Sort(CodeDocumentViewModel);

                // Apply bookmarks
                LoadBookmarksFromStorage();
                BookmarkHelper.ApplyBookmarks(CodeDocumentViewModel, Dte?.Solution?.FileName);

                LogHelper.Log($"CodeNav for '{DocumentHelper.GetName(_window)}' updated");
            }
            catch (ObjectDisposedException ex)
            {
                LogHelper.Log($"CodeNav: RunWorkerCompleted exception: {ex.Message}");
                LogHelper.Log("RunWorkerCompleted exception", ex);
            }
        }
Example #2
0
        public static List <CodeItem> MapFunction(Node function, NodeArray <ParameterDeclaration> parameters, string id, ICodeViewUserControl control)
        {
            if (function == null)
            {
                return(null);
            }

            List <CodeItem> children;

            try
            {
                children = function.Children
                           .FirstOrDefault(c => c.Kind == SyntaxKind.Block)?.Children
                           .SelectMany(SyntaxMapperJS.MapMember)
                           .ToList();
            }
            catch (NullReferenceException)
            {
                return(new List <CodeItem>());
            }

            if (children != null && children.Any())
            {
                SyntaxMapper.FilterNullItems(children);

                var item = BaseMapperJS.MapBase <CodeClassItem>(function, id, control);

                item.BorderColor = Colors.DarkGray;

                item.Kind       = CodeItemKindEnum.Method;
                item.Parameters = $"({string.Join(", ", parameters.Select(p => p.IdentifierStr))})";
                item.Tooltip    = TooltipMapper.Map(item.Access, null, item.Name, item.Parameters);
                item.Id         = IdMapper.MapId(item.FullName, parameters);
                item.Moniker    = IconMapper.MapMoniker(item.Kind, item.Access);

                item.Members = children;

                return(new List <CodeItem> {
                    item
                });
            }

            CodeFunctionItem functionItem = BaseMapperJS.MapBase <CodeFunctionItem>(function, id, control);

            functionItem.Kind       = CodeItemKindEnum.Method;
            functionItem.Parameters = $"({string.Join(", ", parameters.Select(p => p.IdentifierStr))})";
            functionItem.Tooltip    = TooltipMapper.Map(functionItem.Access, null, functionItem.Name, functionItem.Parameters);
            functionItem.Id         = IdMapper.MapId(functionItem.FullName, parameters);
            functionItem.Moniker    = IconMapper.MapMoniker(functionItem.Kind, functionItem.Access);

            return(new List <CodeItem> {
                functionItem
            });
        }
        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var result = e.Result as BackgroundWorkerResult;

            if (result?.CodeItems == null)
            {
                LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated, no results");
                return;
            }

            // Filter all null items from the code document
            SyntaxMapper.FilterNullItems(result.CodeItems);

            // Do we need to update the DataContext?
            var areEqual = AreDocumentsEqual(CodeDocumentViewModel.CodeDocument, result.CodeItems);

            if (result.ForceUpdate == false && areEqual)
            {
                LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated, document did not change");
                return;
            }

            // Set the new list of codeitems as DataContext
            CodeDocumentViewModel.CodeDocument = result.CodeItems;
            _cache = result.CodeItems;

            // Set currently active codeitem
            HighlightHelper.SetForeground(CodeDocumentViewModel.CodeDocument);

            // Are there any items to show, if not hide the margin
            VisibilityHelper.SetMarginWidth(_column, CodeDocumentViewModel.CodeDocument);

            // Apply current visibility settings to the document
            VisibilityHelper.SetCodeItemVisibility(CodeDocumentViewModel.CodeDocument);

            // Sync all regions
            OutliningHelper.SyncAllRegions(_outliningManager, _textView, CodeDocumentViewModel.CodeDocument);

            LogHelper.Log($"CodeNav for '{_window.Document.Name}' updated");
        }
        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);
            }
        }