public void TestGetDiagnostics1() { using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic)) { var set = new ManualResetEvent(false); var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", string.Empty); var source = new TestDiagnosticUpdateSource(false, null); var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonCollection(source), AggregateAsynchronousOperationListener.EmptyListeners); diagnosticService.DiagnosticsUpdated += (s, o) => { set.Set(); }; var id = Tuple.Create(workspace, document); var diagnostic = RaiseDiagnosticEvent(set, source, workspace, document.Project.Id, document.Id, id); var data1 = diagnosticService.GetDiagnostics(workspace, null, null, null, CancellationToken.None); Assert.Equal(diagnostic, data1.Single()); var data2 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, null, null, CancellationToken.None); Assert.Equal(diagnostic, data2.Single()); var data3 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, null, CancellationToken.None); Assert.Equal(diagnostic, data3.Single()); var data4 = diagnosticService.GetDiagnostics(workspace, document.Project.Id, document.Id, id, CancellationToken.None); Assert.Equal(diagnostic, data4.Single()); } }
private void RaiseTagsChanged(ITextBuffer buffer, NormalizedSnapshotSpanCollection difference) { this.AssertIsForeground(); if (difference.Count == 0) { // nothing changed. return; } RaiseTagsChanged(SpecializedCollections.SingletonCollection( new KeyValuePair <ITextBuffer, NormalizedSnapshotSpanCollection>(buffer, difference))); }
private void RaiseTagsChanged(ITextBuffer buffer, DiffResult difference) { this.AssertIsForeground(); if (difference.Count == 0) { // nothing changed. return; } OnTagsChangedForBuffer(SpecializedCollections.SingletonCollection( new KeyValuePair <ITextBuffer, DiffResult>(buffer, difference)), initialTags: false); }
private void RaiseTagsChanged(ITextBuffer buffer, DiffResult difference) { _dataSource.ThreadingContext.ThrowIfNotOnUIThread(); if (difference.Count == 0) { // nothing changed. return; } OnTagsChangedForBuffer(SpecializedCollections.SingletonCollection( new KeyValuePair <ITextBuffer, DiffResult>(buffer, difference)), highPriority: false); }
protected static IEnumerable <TypeInferenceInfo> GetCollectionElementType(INamedTypeSymbol type) { if (type != null) { var parameters = type.TypeArguments; var elementType = parameters.ElementAtOrDefault(0); if (elementType != null) { return(SpecializedCollections.SingletonCollection(new TypeInferenceInfo(elementType))); } } return(SpecializedCollections.EmptyEnumerable <TypeInferenceInfo>()); }
protected override async Task <ImmutableArray <DiagnosticData>?> GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId documentId, AnalysisKind kind, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var stateSets = SpecializedCollections.SingletonCollection(stateSet); // Here, we don't care what kind of analyzer (StateSet) is given. // We just create and use AnalyzerDriver with the given analyzer (StateSet). var forceAnalyzerRun = true; var analyzerDriverOpt = await Owner._compilationManager.CreateAnalyzerDriverAsync(project, stateSets, IncludeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false); if (documentId != null) { var document = project.Solution.GetDocument(documentId); Contract.ThrowIfNull(document); switch (kind) { case AnalysisKind.Syntax: case AnalysisKind.Semantic: { var result = await Owner._executor.GetDocumentAnalysisDataAsync(analyzerDriverOpt, document, stateSet, kind, cancellationToken).ConfigureAwait(false); return(result.Items); } case AnalysisKind.NonLocal: { var nonLocalDocumentResult = await Owner._executor.GetProjectAnalysisDataAsync(analyzerDriverOpt, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false); var analysisResult = nonLocalDocumentResult.GetResult(stateSet.Analyzer); return(GetResult(analysisResult, AnalysisKind.NonLocal, documentId)); } default: return(Contract.FailWithReturn <ImmutableArray <DiagnosticData>?>("shouldn't reach here")); } } Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal); var projectResult = await Owner._executor.GetProjectAnalysisDataAsync(analyzerDriverOpt, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false); return(projectResult.GetResult(stateSet.Analyzer).Others); }
protected override async Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(StateSet stateSet, Project project, DocumentId?documentId, AnalysisKind kind, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var stateSets = SpecializedCollections.SingletonCollection(stateSet); // Here, we don't care what kind of analyzer (StateSet) is given. var forceAnalyzerRun = true; var compilation = await CreateCompilationWithAnalyzersAsync(project, stateSets, IncludeSuppressedDiagnostics, cancellationToken).ConfigureAwait(false); if (documentId != null) { var document = project.Solution.GetDocument(documentId); Contract.ThrowIfNull(document); switch (kind) { case AnalysisKind.Syntax: case AnalysisKind.Semantic: return((await Owner.GetDocumentAnalysisDataAsync(compilation, document, stateSet, kind, cancellationToken).ConfigureAwait(false)).Items); case AnalysisKind.NonLocal: var nonLocalDocumentResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false); var analysisResult = nonLocalDocumentResult.GetResult(stateSet.Analyzer); return(analysisResult.GetDocumentDiagnostics(documentId, AnalysisKind.NonLocal)); default: throw ExceptionUtilities.UnexpectedValue(kind); } } Contract.ThrowIfFalse(kind == AnalysisKind.NonLocal); var projectResult = await Owner.GetProjectAnalysisDataAsync(compilation, project, stateSets, forceAnalyzerRun, cancellationToken).ConfigureAwait(false); return(projectResult.GetResult(stateSet.Analyzer).GetOtherDiagnostics()); }