private static async Task <InstallPackageAndAddImportData> GetInstallDataAsync( PackageReference reference, string versionOpt, bool isLocal, Document document, SyntaxNode node, bool placeSystemNamespaceFirst, CancellationToken cancellationToken) { var oldDocument = document; reference.ReplaceNameNode(ref node, ref document, cancellationToken); var newDocument = await reference.provider.AddImportAsync( node, reference.SearchResult.NameParts, document, placeSystemNamespaceFirst, cancellationToken).ConfigureAwait(false); // We're going to be manually applying this new document to the workspace // (so we can roll it back ourselves if installing the nuget package fails). // As such, we need to do the postprocessing ourselves of tihs document to // ensure things like formatting/simplification happen to it. newDocument = await CleanupDocumentAsync( newDocument, cancellationToken).ConfigureAwait(false); var installOperation = new InstallPackageDirectlyCodeActionOperation( reference._installerService, document, reference._source, reference._packageName, versionOpt, includePrerelease: false, isLocal: isLocal); return(new InstallPackageAndAddImportData( oldDocument, newDocument, installOperation)); }
private async Task <ImmutableArray <CodeActionOperation> > GetOperationsAsync( string versionOpt, bool isLocal, Document document, SyntaxNode node, bool placeSystemNamespaceFirst, CancellationToken cancellationToken) { _reference.ReplaceNameNode(ref node, ref document, cancellationToken); var newDocument = await _reference.provider.AddImportAsync( node, _reference.SearchResult.NameParts, document, placeSystemNamespaceFirst, cancellationToken).ConfigureAwait(false); var newSolution = newDocument.Project.Solution; var operation1 = new ApplyChangesOperation(newSolution); var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); var operation2 = new InstallNugetPackageOperation( _reference._installerService, document, _reference._source, _reference._packageName, versionOpt, isLocal); var operations = ImmutableArray.Create <CodeActionOperation>(operation1, operation2); return(operations); }