Пример #1
0
        public override async Task <TextChange?> GetTextChangeAsync(Document document, CompletionItem selectedItem, char?ch, CancellationToken cancellationToken)
        {
            string insertionText;

            if (ch == null)
            {
                insertionText = SymbolCompletionItem.GetInsertionText(selectedItem);
            }
            else
            {
                var position = SymbolCompletionItem.GetContextPosition(selectedItem);
                var context  = await this.CreateContext(document, position, cancellationToken).ConfigureAwait(false);

                var symbols = await SymbolCompletionItem.GetSymbolsAsync(selectedItem, document, cancellationToken).ConfigureAwait(false);

                if (symbols.Length > 0)
                {
                    insertionText = GetInsertionText(symbols[0], context, ch.Value);
                }
                else
                {
                    insertionText = selectedItem.DisplayText;
                }
            }

            return(new TextChange(selectedItem.Span, insertionText));
        }
        internal override async Task <CompletionDescription> GetDescriptionWorkerAsync(
            Document document, CompletionItem item, CompletionOptions options, SymbolDescriptionOptions displayOptions, CancellationToken cancellationToken)
        {
            var position = SymbolCompletionItem.GetContextPosition(item);

            // What EditorBrowsable settings were we previously passed in (if it mattered)?
            if (item.Properties.TryGetValue(HideAdvancedMembers, out var hideAdvancedMembersString) &&
                bool.TryParse(hideAdvancedMembersString, out var hideAdvancedMembers))
            {
                options = options with {
                    HideAdvancedMembers = hideAdvancedMembers
                };
            }

            var(token, semanticModel, symbols) = await GetSymbolsAsync(document, position, options, cancellationToken).ConfigureAwait(false);

            if (symbols.Length == 0)
            {
                return(CompletionDescription.Empty);
            }

            Contract.ThrowIfNull(semanticModel);

            var name        = SymbolCompletionItem.GetSymbolName(item);
            var kind        = SymbolCompletionItem.GetKind(item);
            var bestSymbols = symbols.WhereAsArray(s => s.Kind == kind && s.Name == name);

            return(await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, semanticModel, displayOptions, cancellationToken).ConfigureAwait(false));
        }
Пример #3
0
        protected override async Task <CompletionDescription> GetDescriptionWorkerAsync(
            Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            var position           = SymbolCompletionItem.GetContextPosition(item);
            var name               = SymbolCompletionItem.GetSymbolName(item);
            var kind               = SymbolCompletionItem.GetKind(item);
            var relatedDocumentIds = document.Project.Solution.GetRelatedDocumentIds(document.Id).Concat(document.Id);
            var options            = document.Project.Solution.Workspace.Options;
            var totalSymbols       = await base.GetPerContextSymbols(document, position, options, relatedDocumentIds, preselect : false, cancellationToken : cancellationToken).ConfigureAwait(false);

            foreach (var info in totalSymbols)
            {
                var bestSymbols = info.symbols.Where(s => kind != null && s.Kind == kind && s.Name == name).ToImmutableArray();
                if (bestSymbols.Any())
                {
                    return(await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, info.syntaxContext.SemanticModel, cancellationToken).ConfigureAwait(false));
                }
            }

            return(CompletionDescription.Empty);
        }
Пример #4
0
        protected override async Task <CompletionDescription> GetDescriptionWorkerAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            var position = SymbolCompletionItem.GetContextPosition(item);

            // What EditorBrowsable settings were we previously passed in (if it mattered)?
            bool hideAdvancedMembers = false;

            if (item.Properties.TryGetValue(HideAdvancedMembers, out var hideAdvancedMembersString))
            {
                bool.TryParse(hideAdvancedMembersString, out hideAdvancedMembers);
            }

            var options = document.Project.Solution.Workspace.Options
                          .WithChangedOption(new OptionKey(CompletionOptions.HideAdvancedMembers, document.Project.Language), hideAdvancedMembers);

            var(token, semanticModel, symbols) = await GetSymbolsAsync(document, position, options, cancellationToken).ConfigureAwait(false);

            var name        = SymbolCompletionItem.GetSymbolName(item);
            var kind        = SymbolCompletionItem.GetKind(item);
            var bestSymbols = symbols.WhereAsArray(s => s.Kind == kind && s.Name == name);

            return(await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, semanticModel, cancellationToken).ConfigureAwait(false));
        }