protected static bool IsSnippetItem(CompletionItem item)
 => item.Tags.Contains(WellKnownTags.Snippet);
Exemplo n.º 2
0
 protected virtual int CompareMatches(PatternMatch match1, PatternMatch match2, CompletionItem item1, CompletionItem item2)
 {
     return(match1.CompareTo(match2));
 }
 protected static bool IsKeywordItem(CompletionItem item)
 => item.Tags.Contains(WellKnownTags.Keyword);
Exemplo n.º 4
0
        public void PresentItems(
            ITrackingSpan triggerSpan,
            IList <RoslynCompletion.CompletionItem> completionItems,
            RoslynCompletion.CompletionItem selectedItem,
            RoslynCompletion.CompletionItem suggestionModeItem,
            bool suggestionMode,
            bool isSoftSelected,
            ImmutableArray <CompletionItemFilter> completionItemFilters,
            string filterText)
        {
            AssertIsForeground();

            // check if this update is still relevant
            if (_textView.IsClosed || _isDismissed)
            {
                return;
            }

            if (triggerSpan != null)
            {
                _completionSet.SetTrackingSpan(triggerSpan);
            }

            _ignoreSelectionStatusChangedEvent = true;
            try
            {
                _completionSet.SetCompletionItems(
                    completionItems, selectedItem, suggestionModeItem, suggestionMode,
                    isSoftSelected, completionItemFilters, filterText);
            }
            finally
            {
                _ignoreSelectionStatusChangedEvent = false;
            }

            if (_editorSessionOpt == null)
            {
                // We're tracking the caret.  Don't have the editor do it.
                // Map the span instead of a point to avoid affinity problems.
                _editorSessionOpt = _completionBroker.CreateCompletionSession(
                    _textView,
                    triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative),
                    trackCaret: false);

                if (_textView is IDebuggerTextView debugTextView && !debugTextView.IsImmediateWindow)
                {
                    debugTextView.HACK_StartCompletionSession(_editorSessionOpt);
                }

                _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed();

                // So here's the deal.  We cannot create the editor session and give it the right
                // items (even though we know what they are).  Instead, the session will call
                // back into the ICompletionSourceProvider (which is us) to get those values. It
                // will pass itself along with the calls back into ICompletionSourceProvider.
                // So, in order to make that connection work, we add properties to the session
                // so that we can call back into ourselves, get the items and add it to the
                // session.
                _editorSessionOpt.Properties.AddProperty(Key, this);
                _editorSessionOpt.Start();
            }

            // Call so that the editor will refresh the completion text to embolden.
            _editorSessionOpt?.Match();
        }
Exemplo n.º 5
0
 public static bool IsObjectCreationCompletionItem(this CompletionItem item) => GetProviderName(item) == ObjectCreationCompletionProvider;
Exemplo n.º 6
0
 /// <summary>
 /// Determines if the items are similar enough they should be represented by a single item in the list.
 /// </summary>
 protected virtual bool ItemsMatch(CompletionItem item, CompletionItem existingItem)
 {
     return(item.Span == existingItem.Span &&
            item.SortText == existingItem.SortText);
 }
Exemplo n.º 7
0
        public override Task <CompletionDescription> GetDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken = default(CancellationToken))
        {
            var provider = GetProvider(item);

            if (provider != null)
            {
                return(provider.GetDescriptionAsync(document, item, cancellationToken));
            }
            else
            {
                return(Task.FromResult(CompletionDescription.Empty));
            }
        }
Exemplo n.º 8
0
 protected virtual bool IsFilterCharacterCore(CompletionItem completionItem, char ch, string textTypedSoFar)
 {
     return(false);
 }
Exemplo n.º 9
0
 protected virtual bool SendEnterThroughToEditorCore(CompletionItem completionItem, string textTypedSoFar, OptionSet options)
 {
     return(false);
 }
Exemplo n.º 10
0
 protected virtual TextChange GetTextChangeCore(CompletionItem selectedItem, char?ch = null, string textTypedSoFar = null)
 {
     return(new TextChange(selectedItem.FilterSpan, selectedItem.DisplayText));
 }
Exemplo n.º 11
0
 protected virtual bool IsCommitCharacterCore(CompletionItem completionItem, char ch, string textTypedSoFar)
 {
     return(s_defaultCommitCharacters.Contains(ch));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Returns true if item1 and item2 are similar enough that only one should be shown in the completion list; otherwise, false.
 /// </summary>
 public virtual bool ItemsMatch(CompletionItem item1, CompletionItem item2)
 {
     return(item1.FilterSpan == item2.FilterSpan &&
            item1.SortText == item2.SortText);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Called by completion engine when a completion item is committed.  Completion rules can
 /// use this information to affect future calls to MatchesFilterText or IsBetterFilterMatch.
 /// </summary>
 public virtual void CompletionItemCommitted(CompletionItem item)
 {
     _completionService.CompletionItemCommitted(item);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Returns true if the completion item should be "soft" selected, or false if it should be "hard"
 /// selected.
 /// </summary>
 public virtual bool ShouldSoftSelectItem(CompletionItem item, string filterText, CompletionTriggerInfo triggerInfo)
 {
     return(filterText.Length == 0 && !item.Preselect);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a copy of this <see cref="CompletionList"/> with the <see cref="SuggestionModeItem"/> property changed.
 /// </summary>
 public CompletionList WithSuggestionModeItem(CompletionItem suggestionModeItem)
 {
     return(With(suggestionModeItem: suggestionModeItem));
 }
Exemplo n.º 16
0
        public override async Task <CompletionChange> GetChangeAsync(Document document, CompletionItem item, char?commitKey = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var change = (await GetTextChangeAsync(document, item, commitKey, cancellationToken).ConfigureAwait(false))
                         ?? new TextChange(item.Span, item.DisplayText);

            return(CompletionChange.Create(change));
        }
Exemplo n.º 17
0
 public static bool HasDescription(CompletionItem item)
 => item.Properties.ContainsKey(DescriptionProperty);
Exemplo n.º 18
0
 public virtual Task <TextChange?> GetTextChangeAsync(Document document, CompletionItem selectedItem, char?ch, CancellationToken cancellationToken)
 {
     return(GetTextChangeAsync(selectedItem, ch, cancellationToken));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Determines which of two items should represent the matching pair.
 /// </summary>
 protected virtual CompletionItem GetBetterItem(CompletionItem item, CompletionItem existingItem)
 {
     // the item later in the sort order (determined by provider order) wins?
     return(item);
 }
Exemplo n.º 20
0
 protected virtual Task <TextChange?> GetTextChangeAsync(CompletionItem selectedItem, char?ch, CancellationToken cancellationToken)
 {
     return(Task.FromResult <TextChange?>(null));
 }
Exemplo n.º 21
0
 internal void OnCompletionItemCommitted(RoslynCompletion.CompletionItem completionItem)
 {
     AssertIsForeground();
     this.ItemCommitted?.Invoke(this, new CompletionItemEventArgs(completionItem));
 }
Exemplo n.º 22
0
 protected static bool IsKeywordItem(CompletionItem item)
 {
     return(item.Tags.Contains(CompletionTags.Keyword));
 }
Exemplo n.º 23
0
 internal static string GetProviderName(this CompletionItem item) => (string)_getProviderName.GetValue(item);
Exemplo n.º 24
0
 protected static bool IsSnippetItem(CompletionItem item)
 {
     return(item.Tags.Contains(CompletionTags.Snippet));
 }
Exemplo n.º 25
0
        public (ImmutableArray <CompletionFilter> filters, int data) GetFiltersAndAddToSet(RoslynCompletionItem item)
        {
            var listBuilder         = new ArrayBuilder <CompletionFilter>();
            var vectorForSingleItem = new BitVector32();

            if (item.Flags.IsExpanded())
            {
                listBuilder.Add(Expander);
                vectorForSingleItem[s_expanderMask] = _vector[s_expanderMask] = true;
            }

            foreach (var tag in item.Tags)
            {
                if (s_filterMap.TryGetValue(tag, out var filterWithMask))
                {
                    listBuilder.Add(filterWithMask.Filter);
                    vectorForSingleItem[filterWithMask.Mask] = _vector[filterWithMask.Mask] = true;
                }
            }

            return(listBuilder.ToImmutableAndFree(), vectorForSingleItem.Data);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Gets the description of the item.
        /// </summary>
        /// <param name="document">This will be the  original document that
        /// <paramref name="item"/> was created against.</param>
        /// <param name="item">The item to get the description for.</param>
        /// <param name="options">Completion options</param>
        /// <param name="displayOptions">Display options</param>
        /// <param name="cancellationToken"></param>
        internal virtual async Task <CompletionDescription?> GetDescriptionAsync(Document document, CompletionItem item, CompletionOptions options, SymbolDescriptionOptions displayOptions, CancellationToken cancellationToken = default)
        {
            var provider = GetProvider(item, document.Project);

            if (provider is null)
            {
                return(CompletionDescription.Empty);
            }

            // We don't need SemanticModel here, just want to make sure it won't get GC'd before CompletionProviders are able to get it.
            (document, var semanticModel) = await GetDocumentWithFrozenPartialSemanticsAsync(document, cancellationToken).ConfigureAwait(false);

            var description = await provider.GetDescriptionAsync(document, item, options, displayOptions, cancellationToken).ConfigureAwait(false);

            GC.KeepAlive(semanticModel);
            return(description);
        }