Exemple #1
0
            protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken)
            {
                SourceText   text;
                StateMachine stateMachine;
                ITextBuffer  textBuffer;

                if (_document.TryGetText(out text))
                {
                    textBuffer = text.Container.TryGetTextBuffer();
                    if (textBuffer == null)
                    {
                        Environment.FailFast(string.Format("document with name {0} is open but textBuffer is null. Textcontainer is of type {1}. SourceText is: {2}",
                                                           _document.Name, text.Container.GetType().FullName, text.ToString()));
                    }

                    if (textBuffer.Properties.TryGetProperty(typeof(StateMachine), out stateMachine))
                    {
                        TrackingSession trackingSession;
                        if (stateMachine.CanInvokeRename(out trackingSession, cancellationToken: cancellationToken))
                        {
                            var snapshotSpan       = stateMachine.TrackingSession.TrackingSpan.GetSpan(stateMachine.Buffer.CurrentSnapshot);
                            var str                = string.Format(EditorFeaturesResources.RenameTo, stateMachine.TrackingSession.OriginalName, snapshotSpan.GetText());
                            var committerOperation = new RenameTrackingCommitterOperation(new RenameTrackingCommitter(stateMachine, snapshotSpan, _refactorNotifyServices, _undoHistoryRegistry, str, showPreview: _showPreview));
                            return(Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation)));
                        }

                        Debug.Assert(false, "RenameTracking codefix invoked on a document with a StateMachine which cannot invoke rename.");
                    }
                }

                Debug.Assert(false, "RenameTracking codefix invoked on a document for which the text or StateMachine is not available.");
                return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>());
            }
Exemple #2
0
            public Task <IEnumerable <ITagSpan <AbstractNavigatableReferenceHighlightingTag> > > ProduceTagsAsync(
                IEnumerable <DocumentSnapshotSpan> snapshotSpans, SnapshotPoint?caretPosition, CancellationToken cancellationToken)
            {
                // NOTE(cyrusn): Normally we'd limit ourselves to producing tags in the span we were
                // asked about.  However, we want to produce all tags here so that the user can actually
                // navigate between all of them using the appropriate tag navigation commands.  If we
                // don't generate all the tags then the user will cycle through an incorrect subset.
                if (caretPosition == null)
                {
                    return(SpecializedTasks.EmptyEnumerable <ITagSpan <AbstractNavigatableReferenceHighlightingTag> >());
                }

                var position = caretPosition.Value;

                Workspace workspace;

                if (!Workspace.TryGetWorkspace(position.Snapshot.AsText().Container, out workspace))
                {
                    return(SpecializedTasks.EmptyEnumerable <ITagSpan <AbstractNavigatableReferenceHighlightingTag> >());
                }

                var document = snapshotSpans.First(vt => vt.SnapshotSpan.Snapshot == position.Snapshot).Document;

                if (document == null)
                {
                    return(SpecializedTasks.EmptyEnumerable <ITagSpan <AbstractNavigatableReferenceHighlightingTag> >());
                }

                return(ProduceTagsAsync(snapshotSpans, position, workspace, document, cancellationToken));
            }
Exemple #3
0
        protected override Task <IEnumerable <Document> > DetermineDocumentsToSearchAsync(
            TSymbol symbol,
            Project project,
            IImmutableSet <Document> documents,
            CancellationToken cancellationToken)
        {
            var location = symbol.Locations.FirstOrDefault();

            if (location == null || !location.IsInSource)
            {
                return(SpecializedTasks.EmptyEnumerable <Document>());
            }

            var document = project.GetDocument(location.SourceTree);

            if (document == null)
            {
                return(SpecializedTasks.EmptyEnumerable <Document>());
            }

            if (documents != null && !documents.Contains(document))
            {
                return(SpecializedTasks.EmptyEnumerable <Document>());
            }

            return(Task.FromResult(SpecializedCollections.SingletonEnumerable <Document>(document)));
        }
Exemple #4
0
        private Task <IEnumerable <ISymbol> > GetSymbolsAsync(
            Project project,
            SyntaxNode node,
            SemanticModel semanticModel,
            ISyntaxFactsService syntaxFacts,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // See if the name binds.  If it does, there's nothing further we need to do.
            if (ExpressionBinds(node, semanticModel, cancellationToken, checkForExtensionMethods: true))
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            string name;
            int    arity;

            syntaxFacts.GetNameAndArityOfSimpleName(node, out name, out arity);
            if (name == null)
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            return(SymbolFinder.FindDeclarationsAsync(project, name, this.IgnoreCase, SymbolFilter.Member, cancellationToken));
        }
Exemple #5
0
 protected override Task <IEnumerable <ReferenceLocation> > FindReferencesInDocumentAsync(
     IMethodSymbol methodSymbol,
     Document document,
     CancellationToken cancellationToken)
 {
     return(SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
 }
Exemple #6
0
        private static Task <IEnumerable <SymbolAndProjectId <INamedTypeSymbol> > > FindDerivedClassesAsync(
            SymbolAndProjectId <INamedTypeSymbol> type,
            Solution solution,
            IImmutableSet <Project> projects,
            bool transitive,
            CancellationToken cancellationToken)
        {
            if (s_isNonSealedClass(type.Symbol))
            {
                Func <SymbolAndProjectIdSet, INamedTypeSymbol, bool> metadataTypeMatches =
                    (set, metadataType) => TypeDerivesFrom(set, metadataType, transitive);

                Func <SymbolAndProjectIdSet, INamedTypeSymbol, bool> sourceTypeImmediatelyMatches =
                    (set, metadataType) => set.Contains(SymbolAndProjectId.Create(metadataType.BaseType?.OriginalDefinition, projectId: null));

                return(FindTypesAsync(type, solution, projects,
                                      metadataTypeMatches: metadataTypeMatches,
                                      sourceTypeImmediatelyMatches: sourceTypeImmediatelyMatches,
                                      shouldContinueSearching: s_isNonSealedClass,
                                      transitive: transitive,
                                      cancellationToken: cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <SymbolAndProjectId <INamedTypeSymbol> >());
        }
        protected override Task <IEnumerable <SymbolAndProjectId> > DetermineCascadedSymbolsAsync(
            SymbolAndProjectId <ITypeParameterSymbol> symbolAndProjectId,
            Solution solution,
            IImmutableSet <Project> projects,
            CancellationToken cancellationToken)
        {
            var symbol  = symbolAndProjectId.Symbol;
            var method  = (IMethodSymbol)symbol.ContainingSymbol;
            var ordinal = method.TypeParameters.IndexOf(symbol);

            if (ordinal >= 0)
            {
                if (method.PartialDefinitionPart != null && ordinal < method.PartialDefinitionPart.TypeParameters.Length)
                {
                    return(Task.FromResult(SpecializedCollections.SingletonEnumerable(
                                               symbolAndProjectId.WithSymbol((ISymbol)method.PartialDefinitionPart.TypeParameters[ordinal]))));
                }

                if (method.PartialImplementationPart != null && ordinal < method.PartialImplementationPart.TypeParameters.Length)
                {
                    return(Task.FromResult(SpecializedCollections.SingletonEnumerable(
                                               symbolAndProjectId.WithSymbol((ISymbol)method.PartialImplementationPart.TypeParameters[ordinal]))));
                }
            }

            return(SpecializedTasks.EmptyEnumerable <SymbolAndProjectId>());
        }
Exemple #8
0
 protected override Task <IEnumerable <SymbolAndProjectId> > DetermineCascadedSymbolsAsync(
     SymbolAndProjectId <IMethodSymbol> symbol,
     Solution solution,
     IImmutableSet <Project> projects,
     CancellationToken cancellationToken)
 {
     return(SpecializedTasks.EmptyEnumerable <SymbolAndProjectId>());
 }
Exemple #9
0
 protected override Task <IEnumerable <Document> > DetermineDocumentsToSearchAsync(
     IMethodSymbol symbol,
     Project project,
     IImmutableSet <Document> documents,
     CancellationToken cancellationToken)
 {
     return(SpecializedTasks.EmptyEnumerable <Document>());
 }
Exemple #10
0
        public Task <IEnumerable <ReferenceLocation> > FindReferencesInDocumentAsync(
            SymbolAndProjectId symbolAndProjectId, Document document, CancellationToken cancellationToken)
        {
            var symbol = symbolAndProjectId.Symbol;

            return(symbol is TSymbol && CanFind((TSymbol)symbol)
                ? FindReferencesInDocumentAsync((TSymbol)symbol, document, cancellationToken)
                : SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
        }
Exemple #11
0
            public override Task <IEnumerable <Diagnostic> > GetProjectDiagnosticsAsync(Project project, CancellationToken cancellationToken)
            {
                if (ProjectDiagnosticsMap.TryGetValue(project, out var diagnostics))
                {
                    return(Task.FromResult <IEnumerable <Diagnostic> >(diagnostics));
                }

                return(SpecializedTasks.EmptyEnumerable <Diagnostic>());
            }
Exemple #12
0
        public Task <IEnumerable <DiagnosticData> > GetDiagnosticsForSpanAsync(Document document, TextSpan range, bool includeSuppressedDiagnostics = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_map.TryGetValue(document.Project.Solution.Workspace, out var analyzer))
            {
                // always make sure that analyzer is called on background thread.
                return(Task.Run(() => analyzer.GetDiagnosticsForSpanAsync(document, range, includeSuppressedDiagnostics, cancellationToken), cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <DiagnosticData>());
        }
Exemple #13
0
        public Task <IEnumerable <DiagnosticData> > GetDiagnosticsForSpanAsync(Document document, TextSpan range, string?diagnosticId = null, bool includeSuppressedDiagnostics = false, Func <string, IDisposable?>?addOperationScope = null, CancellationToken cancellationToken = default)
        {
            if (_map.TryGetValue(document.Project.Solution.Workspace, out var analyzer))
            {
                // always make sure that analyzer is called on background thread.
                return(Task.Run(() => analyzer.GetDiagnosticsForSpanAsync(document, range, diagnosticId, includeSuppressedDiagnostics, blockForData: true, addOperationScope, cancellationToken), cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <DiagnosticData>());
        }
 protected override Task <IEnumerable <ISymbol> > DetermineCascadedSymbolsAsync(IFieldSymbol symbol, Solution solution, IImmutableSet <Project> projects, CancellationToken cancellationToken)
 {
     if (symbol.AssociatedSymbol != null)
     {
         return(Task.FromResult <IEnumerable <ISymbol> >(new ISymbol[] { symbol.AssociatedSymbol }));
     }
     else
     {
         return(SpecializedTasks.EmptyEnumerable <ISymbol>());
     }
 }
Exemple #15
0
        public Task <IEnumerable <DiagnosticData> > GetDiagnosticsForSpanAsync(Document document, TextSpan range, CancellationToken cancellationToken)
        {
            DiagnosticIncrementalAnalyzer analyzer;

            if (this.map.TryGetValue(document.Project.Solution.Workspace, out analyzer))
            {
                // always make sure that analyzer is called on background thread.
                return(Task.Run(async() => await analyzer.GetDiagnosticsAsync(document, range, cancellationToken).ConfigureAwait(false), cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <DiagnosticData>());
        }
Exemple #16
0
        public override Task <IEnumerable <ITagSpan <BraceHighlightTag> > > ProduceTagsAsync(
            Document document, SnapshotSpan snapshotSpan, int?caretPosition, CancellationToken cancellationToken)
        {
            var snapshot = snapshotSpan.Snapshot;

            if (!caretPosition.HasValue || document == null)
            {
                return(SpecializedTasks.EmptyEnumerable <ITagSpan <BraceHighlightTag> >());
            }

            return(ProduceTagsAsync(document, snapshotSpan.Snapshot, caretPosition.Value, cancellationToken));
        }
Exemple #17
0
            protected override async Task <IEnumerable <CodeActionOperation> > ComputePreviewOperationsAsync(CancellationToken cancellationToken)
            {
                if (!_document.Options.GetOption(FeatureOnOffOptions.RenameTrackingPreview) ||
                    !TryInitializeRenameTrackingCommitter(cancellationToken))
                {
                    return(await SpecializedTasks.EmptyEnumerable <CodeActionOperation>().ConfigureAwait(false));
                }

                var solutionSet = await _renameTrackingCommitter.RenameSymbolAsync(cancellationToken).ConfigureAwait(false);

                return(SpecializedCollections.SingletonEnumerable(
                           (CodeActionOperation) new ApplyChangesOperation(solutionSet.RenamedSolution)));
            }
Exemple #18
0
        private Task <IEnumerable <ReferenceLocation> > FindAttributeReferencesAsync(
            IMethodSymbol symbol,
            Document document,
            CancellationToken cancellationToken)
        {
            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            string simpleName;

            return(TryGetNameWithoutAttributeSuffix(symbol.ContainingType.Name, syntaxFacts, out simpleName)
                ? FindReferencesInDocumentUsingIdentifierAsync(symbol, simpleName, document, cancellationToken)
                : SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
        }
        private static Task <IEnumerable <ReferenceLocation> > FindAttributeReferencesAsync(
            INamedTypeSymbol namedType,
            Document document,
            CancellationToken cancellationToken)
        {
            var symbolsMatch = GetStandardSymbolsMatchFunction(namedType, null, document.Project.Solution, cancellationToken);
            var syntaxFacts  = document.GetLanguageService <ISyntaxFactsService>();

            string simpleName;

            return(TryGetNameWithoutAttributeSuffix(namedType.Name, syntaxFacts, out simpleName)
                ? FindReferencesInDocumentUsingIdentifierAsync(simpleName, document, symbolsMatch, cancellationToken)
                : SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
        }
Exemple #20
0
        protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken)
        {
            if (options is ChangeSignatureOptionsResult changeSignatureOptions && !changeSignatureOptions.IsCancelled)
            {
                var changeSignatureResult = _changeSignatureService.ChangeSignatureWithContext(_context, changeSignatureOptions, cancellationToken);

                if (changeSignatureResult.Succeeded)
                {
                    return(Task.FromResult <IEnumerable <CodeActionOperation> >(new CodeActionOperation[] { new ApplyChangesOperation(changeSignatureResult.UpdatedSolution) }));
                }
            }

            return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>());
        }
        /// <summary>
        /// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name.
        /// </summary>
        public static Task <IEnumerable <ISymbol> > FindDeclarationsAsync(Project project, string name, bool ignoreCase, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            return(FindDeclarationsAsync(project, SearchQuery.Create(name, ignoreCase), cancellationToken: cancellationToken));
        }
Exemple #22
0
        public Task <IEnumerable <SymbolAndProjectId> > DetermineCascadedSymbolsAsync(
            SymbolAndProjectId symbolAndProjectId, Solution solution, IImmutableSet <Project> projects, CancellationToken cancellationToken)
        {
            var symbol = symbolAndProjectId.Symbol;

            if (symbol is TSymbol && CanFind((TSymbol)symbol))
            {
                return(DetermineCascadedSymbolsAsync(
                           symbolAndProjectId.WithSymbol((TSymbol)symbol),
                           solution, projects, cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <SymbolAndProjectId>());
        }
Exemple #23
0
            protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(CancellationToken cancellationToken)
            {
                // Invoked directly without previewing.
                if (_renameTrackingCommitter == null)
                {
                    if (!TryInitializeRenameTrackingCommitter(cancellationToken))
                    {
                        return(SpecializedTasks.EmptyEnumerable <CodeActionOperation>());
                    }
                }

                var committerOperation = new RenameTrackingCommitterOperation(_renameTrackingCommitter);

                return(Task.FromResult(SpecializedCollections.SingletonEnumerable(committerOperation as CodeActionOperation)));
            }
        public Task <IEnumerable <ITagSpan <TTag> > > ProduceTagsAsync(IEnumerable <DocumentSnapshotSpan> snapshotSpans, SnapshotPoint?caretPosition, CancellationToken cancellationToken)
        {
            // This abstract class should only be used in places where the tagger will only ever be analyzing at most one
            // document and span. The .Single()s are appropriate here, and if you find yourself "fixing" a bug by replacing
            // them with .First() you don't understand this class in the first place.

            var snapshotSpan = snapshotSpans.Single().SnapshotSpan;
            var document     = snapshotSpans.Single().Document;

            if (document == null)
            {
                return(SpecializedTasks.EmptyEnumerable <ITagSpan <TTag> >());
            }

            return(ProduceTagsAsync(document, snapshotSpan, GetCaretPosition(caretPosition, snapshotSpan), cancellationToken));
        }
        private static Task <IEnumerable <ReferencedSymbol> > FindCallReferencesAsync(
            Solution solution,
            ISymbol symbol,
            IImmutableSet <Document> documents,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (symbol != null)
            {
                if (symbol.Kind == SymbolKind.Event ||
                    symbol.Kind == SymbolKind.Method ||
                    symbol.Kind == SymbolKind.Property)
                {
                    return(SymbolFinder.FindReferencesAsync(symbol, solution, documents, cancellationToken));
                }
            }

            return(SpecializedTasks.EmptyEnumerable <ReferencedSymbol>());
        }
Exemple #26
0
        private Task <IEnumerable <ReferenceLocation> > FindPredefinedTypeReferencesAsync(
            IMethodSymbol symbol,
            Document document,
            CancellationToken cancellationToken)
        {
            var predefinedType = symbol.ContainingType.SpecialType.ToPredefinedType();

            if (predefinedType == PredefinedType.None)
            {
                return(SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
            }

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            return(FindReferencesInDocumentAsync(symbol, document,
                                                 t => IsPotentialReference(predefinedType, syntaxFacts, t),
                                                 cancellationToken));
        }
        public static Task <IEnumerable <INamedTypeSymbol> > GetTypesImmediatelyDerivedFromClassesAsync(
            INamedTypeSymbol type,
            Solution solution,
            CancellationToken cancellationToken)
        {
            if (type != null && type.TypeKind == TypeKind.Class)
            {
                return(GetDependentTypesAsync(
                           type,
                           solution,
                           null,
                           (t1, t2) => t1.BaseType == t2,
                           s_derivedClassesCache,
                           cancellationToken));
            }

            return(SpecializedTasks.EmptyEnumerable <INamedTypeSymbol>());
        }
        internal static Task <IEnumerable <ISymbol> > FindDeclarationsAsync(
            Project project, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (query.Name != null && string.IsNullOrWhiteSpace(query.Name))
            {
                return(SpecializedTasks.EmptyEnumerable <ISymbol>());
            }

            using (Logger.LogBlock(FunctionId.SymbolFinder_FindDeclarationsAsync, cancellationToken))
            {
                return(FindDeclarationsAsyncImpl(project, query, filter, cancellationToken));
            }
        }
        protected override Task <IEnumerable <SymbolAndProjectId> > DetermineCascadedSymbolsAsync(
            SymbolAndProjectId <IFieldSymbol> symbolAndProjectId,
            Solution solution,
            IImmutableSet <Project> projects,
            CancellationToken cancellationToken)
        {
            var symbol = symbolAndProjectId.Symbol;

            if (symbol.AssociatedSymbol != null)
            {
                return(Task.FromResult(
                           SpecializedCollections.SingletonEnumerable(
                               symbolAndProjectId.WithSymbol(symbol.AssociatedSymbol))));
            }
            else
            {
                return(SpecializedTasks.EmptyEnumerable <SymbolAndProjectId>());
            }
        }
        private static Task <IEnumerable <ReferenceLocation> > FindPredefinedTypeReferencesAsync(
            INamedTypeSymbol symbol,
            Document document,
            CancellationToken cancellationToken)
        {
            var predefinedType = symbol.SpecialType.ToPredefinedType();

            if (predefinedType == PredefinedType.None)
            {
                return(SpecializedTasks.EmptyEnumerable <ReferenceLocation>());
            }

            var syntaxFacts = document.GetLanguageService <ISyntaxFactsService>();

            return(FindReferencesInDocumentAsync(symbol, document, t =>
                                                 IsPotentialReference(predefinedType, syntaxFacts, t),
                                                 (t, m) => ValueTuple.Create(true, CandidateReason.None),
                                                 cancellationToken));
        }