public async Task <List <MSBuildCodeFix> > GetRefactorings( MSBuildParseResult result, SnapshotSpan selectedSpan, CancellationToken cancellationToken) { var refactorings = new List <MSBuildCodeFix> (); void ReportRefactoring(MSBuildAction a) { lock (refactorings) { refactorings.Add(new MSBuildCodeFix(a, ImmutableArray <MSBuildDiagnostic> .Empty)); } } var context = new MSBuildRefactoringContext( result.MSBuildDocument, new Xml.Dom.TextSpan(selectedSpan.Start, selectedSpan.Length), ReportRefactoring, cancellationToken); foreach (var provider in refactoringProviders) { if (cancellationToken.IsCancellationRequested) { return(null); } await provider.RegisterRefactoringsAsync(context); } return(refactorings); }
public async Task <bool> HasRefactorings(MSBuildParseResult result, SnapshotSpan selectedSpan, CancellationToken cancellationToken) { bool foundRefactoring = false; void ReportRefactoring(MSBuildAction a) => foundRefactoring = true; var context = new MSBuildRefactoringContext( result.MSBuildDocument, new Xml.Dom.TextSpan(selectedSpan.Start, selectedSpan.Length), ReportRefactoring, cancellationToken); foreach (var provider in refactoringProviders) { if (cancellationToken.IsCancellationRequested) { return(false); } await provider.RegisterRefactoringsAsync(context); if (foundRefactoring) { return(true); } } return(false); }
public async Task <MSBuildDiagnosticSeverity> GetFixSeverity( ITextBuffer buffer, MSBuildParseResult result, SnapshotSpan range, MSBuildDiagnosticSeverity severities, CancellationToken cancellationToken) { var filteredDiags = result.Diagnostics.Where(d => range.IntersectsWith(new SnapshotSpan(range.Snapshot, d.Span.Start, d.Span.Length))); var severity = MSBuildDiagnosticSeverity.None; void ReportFix(MSBuildAction a, ImmutableArray <MSBuildDiagnostic> diags) { foreach (var d in diags) { severity |= d.Descriptor.Severity; } }; //TODO invoke the provider once for all the diagnostics it supports foreach (var diagnostic in filteredDiags) { if (cancellationToken.IsCancellationRequested) { return(severity); } if (range.IntersectsWith(new SnapshotSpan(range.Snapshot, diagnostic.Span.Start, diagnostic.Span.Length))) { if (diagnosticIdToFixProviderMap.TryGetValue(diagnostic.Descriptor.Id, out var fixProvider)) { var ctx = new MSBuildFixContext( buffer, result.MSBuildDocument, result.MSBuildDocument.XDocument, new Xml.Dom.TextSpan(range.Start, range.Length), ImmutableArray.Create(diagnostic), ReportFix, cancellationToken); await fixProvider.RegisterCodeFixesAsync(ctx); //callers only really care about the highest severity, so if we got error, we can early out if ((severity | MSBuildDiagnosticSeverity.Error) != 0) { return(severity); } } } } return(severity); }
/// <remarks> /// FIXME: The buffer parameter is workaround for the spellchecker. It can be removed when /// there is a better concept of a durable context/scope to which information can be bound. /// </remarks> public async Task <List <MSBuildCodeFix> > GetFixes( ITextBuffer buffer, MSBuildParseResult result, SnapshotSpan range, MSBuildDiagnosticSeverity requestedSeverities, CancellationToken cancellationToken) { var filteredDiags = ImmutableArray.CreateRange( result.Diagnostics.Where(d => range.IntersectsWith(new SnapshotSpan(range.Snapshot, d.Span.Start, d.Span.Length)))); var fixes = new List <MSBuildCodeFix> (); void ReportFix(MSBuildAction a, ImmutableArray <MSBuildDiagnostic> d) { lock (fixes) { fixes.Add(new MSBuildCodeFix(a, d)); } } //TODO invoke the provider once for all the diagnostics it supports foreach (var diagnostic in filteredDiags) { if ((diagnostic.Descriptor.Severity | requestedSeverities) == 0) { continue; } if (cancellationToken.IsCancellationRequested) { return(null); } if (range.IntersectsWith(new SnapshotSpan(range.Snapshot, diagnostic.Span.Start, diagnostic.Span.Length))) { if (diagnosticIdToFixProviderMap.TryGetValue(diagnostic.Descriptor.Id, out var fixProvider)) { var ctx = new MSBuildFixContext( buffer, result.MSBuildDocument, result.MSBuildDocument.XDocument, new Xml.Dom.TextSpan(range.Start, range.Length), ImmutableArray.Create(diagnostic), ReportFix, cancellationToken); await fixProvider.RegisterCodeFixesAsync(ctx); } } } return(fixes); }