示例#1
0
        public IEnumerable <SuggestedActionSet> GetSuggestedActions(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
        {
            var list = new List <SuggestedActionSet>();

            if (_section != null)
            {
                var removeDuplicate = new RemoveDuplicatePropertiesAction(_section, _view);
                if (removeDuplicate.IsEnabled)
                {
                    list.AddRange(CreateActionSet(removeDuplicate));
                }

                var sortProperties    = new SortPropertiesAction(_section, _view);
                var sortAllProperties = new SortAllPropertiesAction(_document, _view);
                list.AddRange(CreateActionSet(sortProperties, sortAllProperties));

                var deleteSection = new DeleteSectionAction(range.Snapshot.TextBuffer, _section);
                list.AddRange(CreateActionSet(deleteSection));

                // Suppressions
                IEnumerable <ParseItem> items = _document.ItemsInSpan(range).Where(p => p.HasErrors);
                if (items.Any())
                {
                    IEnumerable <DisplayError> errors = items.SelectMany(i => i.Errors);
                    var actions = new List <SuppressErrorAction>();

                    foreach (DisplayError error in errors)
                    {
                        var action = new SuppressErrorAction(_document, error.Name);

                        if (action.IsEnabled)
                        {
                            actions.Add(action);
                        }
                    }
                    list.AddRange(CreateActionSet(actions.ToArray()));
                }

                // Missing rules
                List <Keyword> missingRules = AddMissingRulesAction.FindMissingRulesAll(_document.GetAllIncludedRules());
                if (missingRules.Count() != 0)
                {
                    var addMissingRules = new AddMissingRulesAction(missingRules, _document, _view);
                    list.AddRange(CreateActionSet(addMissingRules));
                }
            }

            return(list);
        }
        public override void Execute(CancellationToken cancellationToken)
        {
            SnapshotPoint caretPost = _view.Caret.Position.BufferPosition;

            using (ITextEdit edit = _document.TextBuffer.CreateEdit())
            {
                foreach (Section section in _document.Sections)
                {
                    SortPropertiesAction.SortSection(section, edit);
                }

                if (edit.HasEffectiveChanges)
                {
                    edit.Apply();
                }
            }

            _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPost));
        }