/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using System.Collections.Generic; using dnSpy.Contracts.Images; using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Text; namespace dnSpy.Contracts.Language.Intellisense { /// /// A completion item /// public class DsCompletion : Completion2 { /// /// Gets the suffix or null /// public string? Suffix { get; } /// /// Gets the text that is used to filter this item /// public string FilterText { get; } /// /// Gets the icon /// public virtual ImageReference ImageReference => imageReference ??= GetImageReference(); ImageReference? imageReference; /// /// Constructor /// /// Text shown in the UI /// Text used to filter out items or null to use /// Text that gets inserted in the text buffer or null to use /// Description or null /// Icon moniker or null /// Icon automation text or null /// Attribute icons shown on the right side /// Text shown after the normal completion text public DsCompletion(string displayText, string? filterText = null, string? insertionText = null, string? description = null, ImageReference imageReference = default, string? iconAutomationText = null, IEnumerable? attributeIcons = null, string? suffix = null) : base(displayText, insertionText, description, default, iconAutomationText, attributeIcons) { if (displayText is null) throw new ArgumentNullException(nameof(displayText)); FilterText = filterText ?? displayText; InsertionText = insertionText ?? displayText; Suffix = suffix; this.imageReference = imageReference.IsDefault ? (ImageReference?)null : imageReference; } /// /// Gets the image reference. Only called if hasn't been initialized. /// /// protected virtual ImageReference GetImageReference() => default; /// /// Adds the new text to the text buffer /// /// Span to replace with new content public virtual void Commit(ITrackingSpan replaceSpan) { var buffer = replaceSpan.TextBuffer; var span = replaceSpan.GetSpan(buffer.CurrentSnapshot); buffer.Replace(span.Span, InsertionText); } } }