提交 44c572ce 编写于 作者: S Sam Harwell

Cleanup from code reviews

上级 c6c91360
......@@ -215,7 +215,7 @@ public async Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(Document docu
return result.ToImmutableAndFree();
}
public async Task<CodeFixCollection> GetDocumentFixAllForIdInSpan(Document document, TextSpan range, string diagnosticId, CancellationToken cancellationToken)
public async Task<CodeFixCollection> GetDocumentFixAllForIdInSpanAsync(Document document, TextSpan range, string diagnosticId, CancellationToken cancellationToken)
{
var diagnostics = (await _diagnosticService.GetDiagnosticsForSpanAsync(document, range, diagnosticId, includeSuppressedDiagnostics: false, cancellationToken: cancellationToken).ConfigureAwait(false)).ToList();
if (diagnostics.Count == 0)
......@@ -231,12 +231,12 @@ public async Task<CodeFixCollection> GetDocumentFixAllForIdInSpan(Document docum
return result.ToImmutableAndFree().FirstOrDefault();
}
public async Task<Document> ApplyCodeFixesForSpecificDiagnosticId(Document document, string diagnosticId, IProgressTracker progressTracker, CancellationToken cancellationToken)
public async Task<Document> ApplyCodeFixesForSpecificDiagnosticIdAsync(Document document, string diagnosticId, IProgressTracker progressTracker, CancellationToken cancellationToken)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
var textSpan = new TextSpan(0, tree.Length);
var fixCollection = await GetDocumentFixAllForIdInSpan(
var fixCollection = await GetDocumentFixAllForIdInSpanAsync(
document, textSpan, diagnosticId, cancellationToken).ConfigureAwait(false);
if (fixCollection == null)
{
......
......@@ -206,13 +206,13 @@ public EnabledDiagnosticOptions GetAllDiagnostics()
return new EnabledDiagnosticOptions(diagnosticSets, new OrganizeUsingsSet(true, true));
}
public EnabledDiagnosticOptions GetEnabledDiagnostics(DocumentOptionSet docOptions)
public EnabledDiagnosticOptions GetEnabledDiagnostics(OptionSet optionSet)
{
var diagnosticSets = ArrayBuilder<DiagnosticSet>.GetInstance();
foreach (var (diagnosticSet, option) in _optionDiagnosticsMappings)
{
if (docOptions.GetOption(option))
if (optionSet.GetOption(option, LanguageNames.CSharp))
{
diagnosticSets.AddRange(diagnosticSet);
}
......@@ -220,7 +220,7 @@ public EnabledDiagnosticOptions GetEnabledDiagnostics(DocumentOptionSet docOptio
var desc = CSharpFeaturesResources.Organize_Usings;
return new EnabledDiagnosticOptions(diagnosticSets.ToImmutableArray(), new OrganizeUsingsSet(docOptions));
return new EnabledDiagnosticOptions(diagnosticSets.ToImmutableArray(), new OrganizeUsingsSet(optionSet, LanguageNames.CSharp));
}
}
}
......@@ -12,6 +12,6 @@ internal interface ICodeCleanupService : ILanguageService
{
Task<Document> CleanupAsync(Document document, EnabledDiagnosticOptions enabledDiagnostics, IProgressTracker progressTracker, CancellationToken cancellationToken);
EnabledDiagnosticOptions GetAllDiagnostics();
EnabledDiagnosticOptions GetEnabledDiagnostics(DocumentOptionSet docOptions);
EnabledDiagnosticOptions GetEnabledDiagnostics(OptionSet optionSet);
}
}
......@@ -6,13 +6,13 @@ namespace Microsoft.CodeAnalysis.CodeCleanup
{
internal class OrganizeUsingsSet
{
public bool IsRemoveUnusedImportEnabled { get; private set; }
public bool IsSortImportsEnabled { get; private set; }
public bool IsRemoveUnusedImportEnabled { get; }
public bool IsSortImportsEnabled { get; }
public OrganizeUsingsSet(DocumentOptionSet docOptions)
public OrganizeUsingsSet(OptionSet optionSet, string language)
{
IsRemoveUnusedImportEnabled = docOptions.GetOption(CodeCleanupOptions.RemoveUnusedImports);
IsSortImportsEnabled = docOptions.GetOption(CodeCleanupOptions.SortImports);
IsRemoveUnusedImportEnabled = optionSet.GetOption(CodeCleanupOptions.RemoveUnusedImports, language);
IsSortImportsEnabled = optionSet.GetOption(CodeCleanupOptions.SortImports, language);
}
public OrganizeUsingsSet(bool isRemoveUnusedImportEnabled, bool isSortImportsEnabled)
......
......@@ -3,10 +3,14 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Language.CodeCleanUp;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeCleanup
{
/// <summary>
/// Roslyn implementations of <see cref="ICodeCleanUpFixer"/> extend this class. Since other extensions could also
/// be implementing the <see cref="ICodeCleanUpFixer"/> interface, this abstract base class allows Roslyn to operate
/// on MEF instances of fixers known to be relevant in the context of Roslyn languages.
/// </summary>
internal abstract class CodeCleanUpFixer : ICodeCleanUpFixer
{
public abstract Task<bool> FixAsync(ICodeCleanUpScope scope, ICodeCleanUpExecutionContext context, CancellationToken cancellationToken);
......
......@@ -12,10 +12,15 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.CodeCleanup
{
[Export(typeof(CodeCleanUpFixerProvider))]
/// <summary>
/// This is intentionally not exported as a concrete type and not an instance of
/// <see cref="ICodeCleanUpFixerProvider"/>. Roslyn is responsible for registering its own fixer provider, as
/// opposed to the implementation importing the instances of some interface.
/// </summary>
[Export]
internal class CodeCleanUpFixerProvider : ICodeCleanUpFixerProvider
{
private IList<Lazy<CodeCleanUpFixer, ContentTypeMetadata>> _codeCleanUpFixers = new List<Lazy<CodeCleanUpFixer, ContentTypeMetadata>>();
private readonly IList<Lazy<CodeCleanUpFixer, ContentTypeMetadata>> _codeCleanUpFixers;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
......@@ -41,7 +46,7 @@ public IReadOnlyCollection<ICodeCleanUpFixer> GetFixers(IContentType contentType
var fixers = _codeCleanUpFixers
.Where(handler => handler.Metadata.ContentTypes.Contains(contentType.TypeName)).ToList();
return fixers.Any() ? fixers.ConvertAll(l => l.Value) : SpecializedCollections.EmptyReadOnlyList<ICodeCleanUpFixer>();
return fixers.ConvertAll(l => l.Value);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册