public static void TestAssertingEndText( string sampleClassCode, TextSpan refactoringSiteTextSpan, Action <string> assertion, int refactoringNumber = 0) { TestAsertingRefactorings( sampleClassCode, refactoringSiteTextSpan, (workspace, document, proposedCodeRefactorings) => { CodeAction refactoring = proposedCodeRefactorings.ElementAt(refactoringNumber); CodeActionOperation operation = refactoring .GetOperationsAsync(CancellationToken.None) .Result .Single(); operation.Apply(workspace, CancellationToken.None); Document newDocument = workspace.CurrentSolution.GetDocument(document.Id); SourceText newText = newDocument.GetTextAsync(CancellationToken.None).Result; string text = newText.ToString(); assertion(text); }); }
internal static Project ApplyOperation(this Project project, CodeActionOperation operation) { var workspace = project.Solution.Workspace; operation.Apply(workspace, CancellationToken.None); return(workspace.CurrentSolution.GetProject(project.Id) !); }
public InstallPackageDirectlyCodeAction( IPackageInstallerService installerService, Document document, string source, string packageName, string versionOpt, bool includePrerelease, bool isLocal ) { Title = versionOpt == null ? FeaturesResources.Find_and_install_latest_version : isLocal ? string.Format(FeaturesResources.Use_local_version_0, versionOpt) : string.Format(FeaturesResources.Install_version_0, versionOpt); _installPackageOperation = new InstallPackageDirectlyCodeActionOperation( installerService, document, source, packageName, versionOpt, includePrerelease, isLocal ); }
protected override async Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync( object options, CancellationToken cancellationToken ) { var operations = SpecializedCollections.EmptyEnumerable <CodeActionOperation>(); if ( options is ExtractInterfaceOptionsResult extractInterfaceOptions && !extractInterfaceOptions.IsCancelled ) { var extractInterfaceResult = await _extractInterfaceService .ExtractInterfaceFromAnalyzedTypeAsync( _typeAnalysisResult, extractInterfaceOptions, cancellationToken ) .ConfigureAwait(false); if (extractInterfaceResult.Succeeded) { operations = new CodeActionOperation[] { new ApplyChangesOperation(extractInterfaceResult.UpdatedSolution), new DocumentNavigationOperation( extractInterfaceResult.NavigationDocumentId, position: 0 ) }; } } return(operations); }
// Возвращаем операцию навигации в определённый документ и определённую позицию // как результат нашего CodeAction'а protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync( CancellationToken cancellationToken) { IEnumerable <CodeActionOperation> operations = new CodeActionOperation[] { new DocumentNavigationOperation(_documentId, _position), }; return(Task.FromResult(operations)); }
protected override async Task <IEnumerable <CodeActionOperation> > ComputePreviewOperationsAsync(CancellationToken cancellationToken) { var addedDocument = CreateTextFixtureDocument(cancellationToken); IEnumerable <CodeActionOperation> operations = new CodeActionOperation[] { new ApplyChangesOperation(addedDocument.Project.Solution), }; return(await Task.FromResult(operations).ConfigureAwait(false)); }
protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken) { var addedDocument = CreateTextFixtureDocument(cancellationToken); IEnumerable <CodeActionOperation> operations = new CodeActionOperation[] { new ApplyChangesOperation(addedDocument.Project.Solution), new OpenDocumentOperation(addedDocument.Id, true) }; return(Task.FromResult(operations)); }
private static void VerifyOperationText([NotNull] CodeActionOperation operation, [NotNull] string expectedCode, [NotNull] Document document) { Workspace workspace = document.Project.Solution.Workspace; operation.Apply(workspace, CancellationToken.None); Document newDocument = workspace.CurrentSolution.GetDocument(document.Id); SourceText sourceText = newDocument.GetTextAsync().Result; string text = sourceText.ToString(); text.Should().Be(expectedCode); }
private async Task CodeActionAsync(CodeAction codeAction, Document document, string expectedCode) { ImmutableArray <CodeActionOperation> operations = codeAction.GetOperationsAsync(CancellationToken.None).Result; Assert.Single(operations); CodeActionOperation operation = operations.First(); Workspace workspace = document.Project.Solution.Workspace; operation.Apply(workspace, CancellationToken.None); Document newDocument = workspace.CurrentSolution.GetDocument(document.Id); SourceText sourceText = await newDocument.GetTextAsync(CancellationToken.None).ConfigureAwait(false); string text = sourceText.ToString(); Assert.Equal(expectedCode, text); }
protected override Task <IEnumerable <CodeActionOperation> > ComputeOperationsAsync(object options, CancellationToken cancellationToken) { IEnumerable <CodeActionOperation> operations = null; if (options is ExtractInterfaceOptionsResult extractInterfaceOptions && !extractInterfaceOptions.IsCancelled) { var extractInterfaceResult = _extractInterfaceService.ExtractInterfaceFromAnalyzedType(_typeAnalysisResult, extractInterfaceOptions, cancellationToken); if (extractInterfaceResult.Succeeded) { operations = new CodeActionOperation[] { new ApplyChangesOperation(extractInterfaceResult.UpdatedSolution), new DocumentNavigationOperation(extractInterfaceResult.NavigationDocumentId, position: 0) }; } } return(Task.FromResult(operations)); }
public static void CodeAction([NotNull] CodeAction codeAction, [NotNull] Document document, [NotNull] string expectedCode) { Guard.NotNull(codeAction, nameof(codeAction)); Guard.NotNull(document, nameof(document)); Guard.NotNull(expectedCode, nameof(expectedCode)); ImmutableArray <CodeActionOperation> operations = codeAction.GetOperationsAsync(CancellationToken.None).Result; operations.Should().HaveCount(1); CodeActionOperation operation = operations.Single(); Workspace workspace = document.Project.Solution.Workspace; operation.Apply(workspace, CancellationToken.None); Document newDocument = workspace.CurrentSolution.GetDocument(document.Id); SourceText sourceText = newDocument.GetTextAsync().Result; string text = sourceText.ToString(); text.Should().Be(expectedCode); }
public RoslynCodeActionOperation(CodeActionOperation inner) { _inner = inner; }