コード例 #1
0
        public async Task <ImmutableArray <AddImportFixData> > GetFixesAsync(
            Document document, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
            ISymbolSearchService symbolSearchService, bool searchReferenceAssemblies,
            ImmutableArray <PackageSource> packageSources, CancellationToken cancellationToken)
        {
            var callbackTarget = new RemoteSymbolSearchService(symbolSearchService, cancellationToken);
            var session        = await document.Project.Solution.TryCreateCodeAnalysisServiceSessionAsync(
                RemoteFeatureOptions.AddImportEnabled, callbackTarget, cancellationToken).ConfigureAwait(false);

            var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            using (session)
            {
                if (session == null)
                {
                    return(await GetFixesInCurrentProcessAsync(
                               document, span, diagnosticId, placeSystemNamespaceFirst,
                               symbolSearchService, searchReferenceAssemblies,
                               packageSources, cancellationToken).ConfigureAwait(false));
                }
                else
                {
                    return(await GetFixesInRemoteProcessAsync(
                               session, document, span, diagnosticId, placeSystemNamespaceFirst,
                               searchReferenceAssemblies, packageSources).ConfigureAwait(false));
                }
            }
        }
コード例 #2
0
        public async Task <ImmutableArray <AddImportFixData> > GetFixesAsync(
            Document document, TextSpan span, string diagnosticId, int maxResults, bool placeSystemNamespaceFirst,
            ISymbolSearchService symbolSearchService, bool searchReferenceAssemblies,
            ImmutableArray <PackageSource> packageSources, CancellationToken cancellationToken)
        {
            if (RemoteSupportedLanguages.IsSupported(document.Project.Language))
            {
                var callbackTarget = new RemoteSymbolSearchService(symbolSearchService, cancellationToken);
                var result         = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync <IList <AddImportFixData> >(
                    callbackTarget,
                    nameof(IRemoteAddImportFeatureService.GetFixesAsync),
                    new object[]
                {
                    document.Id,
                    span,
                    diagnosticId,
                    maxResults,
                    placeSystemNamespaceFirst,
                    searchReferenceAssemblies,
                    packageSources
                },
                    cancellationToken).ConfigureAwait(false);

                if (result != null)
                {
                    return(result.ToImmutableArray());
                }
            }

            return(await GetFixesInCurrentProcessAsync(
                       document, span, diagnosticId, maxResults, placeSystemNamespaceFirst,
                       symbolSearchService, searchReferenceAssemblies,
                       packageSources, cancellationToken).ConfigureAwait(false));
        }
コード例 #3
0
        public async Task <ImmutableArray <AddImportFixData> > GetFixesAsync(
            Document document, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
            ISymbolSearchService symbolSearchService, bool searchReferenceAssemblies,
            ImmutableArray <PackageSource> packageSources, CancellationToken cancellationToken)
        {
            var callbackTarget = new RemoteSymbolSearchService(symbolSearchService, cancellationToken);
            var result         = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync <ImmutableArray <AddImportFixData> >(
                RemoteFeatureOptions.AddImportEnabled,
                callbackTarget,
                nameof(IRemoteAddImportFeatureService.GetFixesAsync),
                new object[]
            {
                document.Id,
                span,
                diagnosticId,
                placeSystemNamespaceFirst,
                searchReferenceAssemblies,
                packageSources
            },
                cancellationToken).ConfigureAwait(false);

            var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

            if (!result.IsDefault)
            {
                return(result);
            }

            return(await GetFixesInCurrentProcessAsync(
                       document, span, diagnosticId, placeSystemNamespaceFirst,
                       symbolSearchService, searchReferenceAssemblies,
                       packageSources, cancellationToken).ConfigureAwait(false));
        }