예제 #1
0
        public static async Task <CompletionDescription> GetCompletionDescriptionAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
        {
            var metadataName = GetMetadataName(item);

            if (!string.IsNullOrEmpty(metadataName))
            {
                var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

                var symbol = compilation.GetTypeByMetadataName(metadataName);
                if (symbol != null)
                {
                    var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                    // We choose not to display the number of "type overloads" for simplicity.
                    // Otherwise, we need additonal logic to track internal and public visible
                    // types separately, and cache both completion items.
                    return(await CommonCompletionUtilities.CreateDescriptionAsync(
                               document.Project.Solution.Workspace,
                               semanticModel,
                               position : 0,
                               symbol,
                               overloadCount : 0,
                               supportedPlatforms : null,
                               cancellationToken).ConfigureAwait(false));
                }
            }

            return(null);
        }
예제 #2
0
        public static async Task <CompletionDescription> GetDescriptionAsync(
            CompletionItem item, Document document, CancellationToken cancellationToken)
        {
            var workspace = document.Project.Solution.Workspace;

            var position = GetDescriptionPosition(item);

            if (position == -1)
            {
                position = item.Span.Start;
            }

            var supportedPlatforms = GetSupportedPlatforms(item, workspace);

            var contextDocument = FindAppropriateDocumentForDescriptionContext(document, supportedPlatforms);

            var semanticModel = await contextDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

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

            if (symbols.Length > 0)
            {
                return(await CommonCompletionUtilities.CreateDescriptionAsync(workspace, semanticModel, position, symbols, supportedPlatforms, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                return(CompletionDescription.Empty);
            }
        }
예제 #3
0
        public static async Task <CompletionDescription> GetDescriptionAsync(
            CompletionItem item,
            IReadOnlyList <ISymbol> symbols,
            Document document,
            SemanticModel semanticModel,
            CancellationToken cancellationToken
            )
        {
            var workspace = document.Project.Solution.Workspace;

            var position           = GetDescriptionPosition(item);
            var supportedPlatforms = GetSupportedPlatforms(item, workspace);

            if (symbols.Count != 0)
            {
                return(await CommonCompletionUtilities
                       .CreateDescriptionAsync(
                           workspace,
                           semanticModel,
                           position,
                           symbols,
                           supportedPlatforms,
                           cancellationToken
                           )
                       .ConfigureAwait(false));
            }
            else
            {
                return(CompletionDescription.Empty);
            }
        }
예제 #4
0
        public static async Task <CompletionDescription> GetDescriptionAsync(CompletionItem item, ImmutableArray <ISymbol> symbols, Document document, SemanticModel semanticModel, CancellationToken cancellationToken)
        {
            var workspace = document.Project.Solution.Workspace;

            var position           = SymbolCompletionItem.GetDescriptionPosition(item);
            var supportedPlatforms = SymbolCompletionItem.GetSupportedPlatforms(item, workspace);

            var contextDocument = FindAppropriateDocumentForDescriptionContext(document, supportedPlatforms);

            if (symbols.Length != 0)
            {
                return(await CommonCompletionUtilities.CreateDescriptionAsync(workspace, semanticModel, position, symbols, supportedPlatforms, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                return(CompletionDescription.Empty);
            }
        }
예제 #5
0
        public static async Task <CompletionDescription> GetDescriptionAsync(CompletionItem item, Document document, CancellationToken cancellationToken)
        {
            var workspace = document.Project.Solution.Workspace;

            var position = GetDescriptionPosition(item);

            if (position == -1)
            {
                position = item.Span.Start;
            }

            var supportedPlatforms = GetSupportedPlatforms(item, workspace);

            // find appropriate document for descripton context
            var contextDocument = document;

            if (supportedPlatforms != null && supportedPlatforms.InvalidProjects.Contains(document.Id.ProjectId))
            {
                var contextId = document.GetLinkedDocumentIds().FirstOrDefault(id => !supportedPlatforms.InvalidProjects.Contains(id.ProjectId));
                if (contextId != null)
                {
                    contextDocument = document.Project.Solution.GetDocument(contextId);
                }
            }

            var semanticModel = await contextDocument.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

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

            if (symbols.Length > 0)
            {
                return(await CommonCompletionUtilities.CreateDescriptionAsync(workspace, semanticModel, position, symbols, supportedPlatforms, cancellationToken).ConfigureAwait(false));
            }
            else
            {
                return(CompletionDescription.Empty);
            }
        }
예제 #6
0
        public static async Task <CompletionDescription> GetDescriptionForSymbolsAsync(
            CompletionItem item, Document document, ImmutableArray <ISymbol> symbols, SymbolDescriptionOptions options, CancellationToken cancellationToken)
        {
            if (symbols.Length == 0)
            {
                return(CompletionDescription.Empty);
            }

            var position = GetDescriptionPosition(item);

            if (position == -1)
            {
                position = item.Span.Start;
            }

            var supportedPlatforms = GetSupportedPlatforms(item, document.Project.Solution);
            var contextDocument    = FindAppropriateDocumentForDescriptionContext(document, supportedPlatforms);
            var semanticModel      = await contextDocument.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var services = document.Project.Solution.Services;

            return(await CommonCompletionUtilities.CreateDescriptionAsync(services, semanticModel, position, symbols, options, supportedPlatforms, cancellationToken).ConfigureAwait(false));
        }