private async Task AnalyzeForKind(Document document, AnalysisKind kind, CancellationToken cancellationToken)
            {
                var diagnosticData = await _service._analyzerService.GetDiagnosticsAsync(document, GetAnalyzers(), kind, cancellationToken).ConfigureAwait(false);

                _service.RaiseDiagnosticsUpdated(
                    DiagnosticsUpdatedArgs.DiagnosticsCreated(new DefaultUpdateArgsId(_workspace.Kind, kind, document.Id),
                                                              _workspace, document.Project.Solution, document.Project.Id, document.Id, diagnosticData.ToImmutableArrayOrEmpty()));

                IEnumerable <DiagnosticAnalyzer> GetAnalyzers()
                {
                    // C# or VB document that supports compiler
                    var compilerAnalyzer = _service._analyzerService.GetCompilerDiagnosticAnalyzer(document.Project.Language);

                    if (compilerAnalyzer != null)
                    {
                        return(SpecializedCollections.SingletonEnumerable(compilerAnalyzer));
                    }

                    // document that doesn't support compiler diagnostics such as fsharp or typescript
                    return(_service._analyzerService.GetDiagnosticAnalyzers(document.Project));
                }
            }
Exemplo n.º 2
0
            public void OnAnalyzerLoadFailed(object sender, AnalyzerLoadFailureEventArgs e)
            {
                var reference = sender as AnalyzerFileReference;

                if (reference == null)
                {
                    return;
                }

                var diagnostic = AnalyzerHelper.CreateAnalyzerLoadFailureDiagnostic(reference.FullPath, e);

                // diagnostic from host analyzer can never go away
                var args = DiagnosticsUpdatedArgs.DiagnosticsCreated(
                    id: Tuple.Create(this, reference.FullPath, e.ErrorCode, e.TypeName),
                    workspace: _primaryWorkspace.Workspace,
                    solution: null,
                    projectId: null,
                    documentId: null,
                    diagnostics: ImmutableArray.Create <DiagnosticData>(diagnostic));

                // this can be null in test. but in product code, this should never be null.
                _hostUpdateSource?.RaiseDiagnosticsUpdated(args);
            }
Exemplo n.º 3
0
 public void RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs args)
 {
     this.DiagnosticsUpdated?.Invoke(this, args);
 }
Exemplo n.º 4
0
 private DiagnosticsUpdatedArgs MakeRemovedArgs(DiagnosticAnalyzer analyzer, Project project)
 {
     return(DiagnosticsUpdatedArgs.DiagnosticsRemoved(
                CreateId(analyzer, project), this.Workspace, project?.Solution, project?.Id, documentId: null));
 }
Exemplo n.º 5
0
 private DiagnosticsUpdatedArgs MakeCreatedArgs(DiagnosticAnalyzer analyzer, ImmutableHashSet <DiagnosticData> items, Project project)
 {
     return(DiagnosticsUpdatedArgs.DiagnosticsCreated(
                CreateId(analyzer, project), this.Workspace, project?.Solution, project?.Id, documentId: null, diagnostics: items.ToImmutableArray()));
 }
 internal void RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs state)
 {
     this.DiagnosticsUpdated?.Invoke(this, state);
 }
 private void RaiseEmptyDiagnosticUpdated(AnalysisKind kind, DocumentId documentId)
 {
     _service.RaiseDiagnosticsUpdated(DiagnosticsUpdatedArgs.DiagnosticsRemoved(
                                          new DefaultUpdateArgsId(_workspace.Kind, kind, documentId), _workspace, null, documentId.ProjectId, documentId));
 }
Exemplo n.º 8
0
 private void OnDiagnosticsUpdated(object sender, DiagnosticsUpdatedArgs e)
 {
     AssertIfNull(e.Diagnostics);
     RaiseDiagnosticsUpdated(sender, e);
 }