Exemplo n.º 1
0
        List <CommandItem> GetExpandSelectionCommands(CommandContext ctx)
        {
            var r         = new List <CommandItem>();
            var duplicate = ctx.RightClick;
            var node      = _Context.NodeIncludeTrivia;

            while (node != null)
            {
                if (node.FullSpan.Contains(ctx.View.Selection, false))
                {
                    var nodeKind = node.Kind();
                    if ((nodeKind.IsSyntaxBlock() || nodeKind.IsDeclaration() || nodeKind == SyntaxKind.VariableDeclarator) &&
                        nodeKind != SyntaxKind.VariableDeclaration)
                    {
                        var n = node;
                        r.Add(new CommandItem(CodeAnalysisHelper.GetImageId(n), (duplicate ? "Duplicate " : "Select ") + nodeKind.GetSyntaxBrief() + " " + n.GetDeclarationSignature(), ctx2 => {
                            ctx2.View.SelectNode(n, Keyboard.Modifiers == ModifierKeys.Shift ^ Config.Instance.SmartBarOptions.MatchFlags(SmartBarOptions.ExpansionIncludeTrivia) || n.Span.Contains(ctx2.View.Selection, false) == false);
                            if (Keyboard.Modifiers == ModifierKeys.Control)
                            {
                                TextEditorHelper.ExecuteEditorCommand("Edit.Copy");
                            }
                            if (duplicate)
                            {
                                TextEditorHelper.ExecuteEditorCommand("Edit.Duplicate");
                            }
                        }));
                    }
                }
                node = node.Parent;
            }
            r.Add(new CommandItem(IconIds.SelectAll, R.CMD_SelectAll, ctrl => ctrl.ToolTip = R.CMDT_SelectAll, ctx2 => TextEditorHelper.ExecuteEditorCommand("Edit.SelectAll")));
            return(r);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the selection state of the objects in the object picker based on which objects have been previously
        /// scaffolded.
        /// </summary>
        private async Task InitializeObjectSelectionState(IEnumerable <ObjectPickerObject> objects)
        {
            Project     project     = CodeAnalysisHelper.GetProject(this.Wizard.Context.ProjectHierarchy, this.Wizard.VisualStudioWorkspace);
            Compilation compilation = await project?.GetCompilationAsync();

            if (compilation != null)
            {
                string modelsNamespaceName =
                    ProjectHelper.GetProjectNamespace(ProjectHelper.GetProjectFromHierarchy(this.Wizard.Context.ProjectHierarchy))
                    + Type.Delimiter
                    + this.Wizard.DesignerData.GetDefaultedModelsHintPath().Replace(Path.DirectorySeparatorChar, Type.Delimiter);
                INamespaceSymbol modelsNamespace = CodeAnalysisHelper.GetNamespace(modelsNamespaceName, compilation);
                if (modelsNamespace != null)
                {
                    foreach (INamedTypeSymbol type in modelsNamespace.GetTypeMembers())
                    {
                        // Types are matched only on type name, it is hard to do much more because users are free to change
                        // the scaffolded code in a number of ways.
                        ObjectPickerObject pickerObject = objects.FirstOrDefault(c => c.Name == type.Name);
                        if (pickerObject != null)
                        {
                            pickerObject.IsChecked = true;
                            pickerObject.IsEnabled = false;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal void AddNamespaceItems(ISymbol[] symbols, ISymbol highlight)
        {
            var items = Array.ConvertAll(symbols, s => new SymbolItem(s, this, false));

            AddRange(items);
            if (highlight != null)
            {
                var c = CodeAnalysisHelper.GetSpecificSymbolComparer(highlight);
                SelectedItem = items.FirstOrDefault(s => c(s.Symbol));
            }
        }
Exemplo n.º 4
0
        void FindCallers(CommandContext context, ISymbol source)
        {
            var doc  = _Context.Document;
            var docs = System.Collections.Immutable.ImmutableHashSet.CreateRange(doc.Project.GetRelatedProjectDocuments());
            List <SymbolCallerInfo> callers;

            switch (source.Kind)
            {
            case SymbolKind.Method:
            case SymbolKind.Property:
            case SymbolKind.Event:
                callers = ThreadHelper.JoinableTaskFactory.Run(() => SymbolFinder.FindCallersAsync(source, doc.Project.Solution, docs, context.CancellationToken)).ToList();
                break;

            case SymbolKind.NamedType:
                var tempResults = new HashSet <SymbolCallerInfo>(SymbolCallerInfoComparer.Instance);
                ThreadHelper.JoinableTaskFactory.Run(async() => {
                    foreach (var item in (source as INamedTypeSymbol).InstanceConstructors)
                    {
                        foreach (var c in await SymbolFinder.FindCallersAsync(item, doc.Project.Solution, docs, context.CancellationToken))
                        {
                            tempResults.Add(c);
                        }
                    }
                });
                (callers = new List <SymbolCallerInfo>(tempResults.Count)).AddRange(tempResults);
                break;

            default: return;
            }
            callers.Sort((a, b) => CodeAnalysisHelper.CompareSymbol(a.CallingSymbol, b.CallingSymbol));
            var m = new SymbolMenu(this);

            m.Title.SetGlyph(ThemeHelper.GetImage(source.GetImageId()))
            .Append(source.ToDisplayString(WpfHelper.MemberNameFormat), true)
            .Append(" callers");
            var containerType = source.ContainingType;

            foreach (var caller in callers)
            {
                var s = caller.CallingSymbol;
                var i = m.Menu.Add(s, _Context, false);
                i.Location = caller.Locations.FirstOrDefault();
                if (s.ContainingType != containerType)
                {
                    i.Hint = s.ContainingType.ToDisplayString(WpfHelper.MemberNameFormat);
                }
            }
            m.Show();
        }