private void RemoveUnusedImports(ITextBuffer subjectBuffer, CancellationToken cancellationToken) { var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document != null) { var newDocument = RemoveUnnecessaryImportsService.RemoveUnnecessaryImportsAsync(document, cancellationToken).WaitAndGetResult(cancellationToken); if (document != newDocument) { ApplyTextChange(document, newDocument); } } }
private void SortAndRemoveUnusedImports(ITextBuffer subjectBuffer, CancellationToken cancellationToken) { var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges(); if (document != null) { var newDocument = RemoveUnnecessaryImportsService.RemoveUnnecessaryImportsAsync(document, cancellationToken).WaitAndGetResult(cancellationToken); newDocument = OrganizeImportsService.OrganizeImportsAsync(newDocument, subjectBuffer.GetOption(OrganizerOptions.PlaceSystemNamespaceFirst), cancellationToken).WaitAndGetResult(cancellationToken); if (document != newDocument) { ApplyTextChange(document, newDocument); } } }