public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets) { if (_disposed || _document.IsParsing) return; ITextSnapshot snapshot = _buffer.CurrentSnapshot; SnapshotPoint? triggerPoint = session.GetTriggerPoint(snapshot); if (triggerPoint == null || !triggerPoint.HasValue) return; SnapshotSpan line = triggerPoint.Value.GetContainingLine().Extent; var list = new List<Completion4>(); int position = triggerPoint.Value.Position; ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(position, 0, SpanTrackingMode.EdgeInclusive); ParseItem prev = _document.ParseItems.LastOrDefault(p => p.Span.Start < position && !p.Span.Contains(position - 1)); ParseItem parseItem = _document.ItemAtPosition(position); string moniker = null; // Property if (string.IsNullOrWhiteSpace(line.GetText()) || parseItem?.ItemType == ItemType.Keyword) { bool isInRoot = !_document.ParseItems.Exists(p => p.ItemType == ItemType.Section && p.Span.Start < position); if (isInRoot) { if (SchemaCatalog.TryGetKeyword(SchemaCatalog.Root, out Keyword root)) list.Add(CreateCompletion(root, root.Category)); } else { IEnumerable<Keyword> properties = EditorConfigPackage.CompletionOptions.ShowHiddenKeywords ? SchemaCatalog.AllKeywords : SchemaCatalog.VisibleKeywords; IEnumerable<Keyword> items = properties.Where(i => i.Name != SchemaCatalog.Root); IEnumerable<string> usedKeywords = _document.GetAllIncludedRules(); ParseItem parseItemSection = _document.ParseItems.LastOrDefault(p => p.ItemType == ItemType.Section && p.Span.Start < position); if (parseItemSection != null) { Section section = _document.Sections.FirstOrDefault(x => x.Item.Text.Equals(parseItemSection.Text, StringComparison.OrdinalIgnoreCase)); if (section != null) { // Set keywords scope to current section usedKeywords = section.Properties.Select(x => x.Keyword.Text).ToList(); } } foreach (Keyword property in items) { string keyword = property.Name; // Keyword already used and keyword does not qualify as repeatable if (usedKeywords.Contains(keyword) && !keyword.StartsWith("dotnet_naming_", StringComparison.OrdinalIgnoreCase)) continue; list.Add(CreateCompletion(property, property.Category)); } } moniker = "keyword"; } // Value else if (parseItem?.ItemType == ItemType.Value) { if (SchemaCatalog.TryGetKeyword(prev.Text, out Keyword item)) { if (!item.SupportsMultipleValues && parseItem.Text.Contains(",")) { return; } foreach (Value value in item.Values) list.Add(CreateCompletion(value, iconAutomation: "value")); } moniker = "value"; } // Severity else if ((position > 0 && snapshot.Length > 1 && snapshot.GetText(position - 1, 1) == ":") || parseItem?.ItemType == ItemType.Severity) { if (prev?.ItemType == ItemType.Value || parseItem?.ItemType == ItemType.Severity) { Property prop = _document.PropertyAtPosition(prev.Span.Start); if (SchemaCatalog.TryGetKeyword(prop?.Keyword?.Text, out Keyword key) && key.RequiresSeverity) AddSeverity(list); moniker = "severity"; } } // Suppression else if (parseItem?.ItemType == ItemType.Suppression) { foreach (Error code in ErrorCatalog.All.OrderBy(e => e.Code)) list.Add(CreateCompletion(code)); moniker = "suppression"; } if (!list.Any()) { if (SchemaCatalog.TryGetKeyword(prev?.Text, out Keyword property)) { int eq = line.GetText().IndexOf("="); if (eq != -1) { int eqPos = eq + line.Start.Position; if (position > eqPos) foreach (Value value in property.Values) list.Add(CreateCompletion(value)); } moniker = "value"; } } else { ITrackingSpan trackingSpan = FindTokenSpanAtPosition(session); SnapshotSpan span = trackingSpan.GetSpan(snapshot); string text = span.GetText(); if (text == ":" || text == ",") applicableTo = snapshot.CreateTrackingSpan(new Span(span.Start + 1, 0), SpanTrackingMode.EdgeInclusive); else if (!string.IsNullOrWhiteSpace(text)) applicableTo = trackingSpan; } CreateCompletionSet(moniker, completionSets, list, applicableTo); }
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); }