private async void AssertResetInteractive( TestWorkspace workspace, Project project, bool buildSucceeds, List <string> expectedReferences = null, List <string> expectedUsings = null) { expectedReferences = expectedReferences ?? new List <string>(); expectedUsings = expectedUsings ?? new List <string>(); InteractiveWindowTestHost testHost = new InteractiveWindowTestHost(); List <string> executedSubmissionCalls = new List <string>(); EventHandler <string> ExecuteSubmission = (_, code) => { executedSubmissionCalls.Add(code); }; testHost.Evaluator.OnExecute += ExecuteSubmission; IWaitIndicator waitIndicator = workspace.GetService <IWaitIndicator>(); IEditorOptionsFactoryService editorOptionsFactoryService = workspace.GetService <IEditorOptionsFactoryService>(); var editorOptions = editorOptionsFactoryService.GetOptions(testHost.Window.CurrentLanguageBuffer); var newLineCharacter = editorOptions.GetNewLineCharacter(); TestResetInteractive resetInteractive = new TestResetInteractive( waitIndicator, editorOptionsFactoryService, CreateReplReferenceCommand, CreateImport, buildSucceeds: buildSucceeds) { References = ImmutableArray.CreateRange(GetProjectReferences(workspace, project)), ReferenceSearchPaths = ImmutableArray.Create("rsp1", "rsp2"), SourceSearchPaths = ImmutableArray.Create("ssp1", "ssp2"), ProjectNamespaces = ImmutableArray.Create("System", "ResetInteractiveTestsDocument", "VisualBasicResetInteractiveTestsDocument"), NamespacesToImport = ImmutableArray.Create("System", "ResetInteractiveTestsDocument"), ProjectDirectory = "pj", }; await resetInteractive.Execute(testHost.Window, "Interactive C#"); // Validate that the project was rebuilt. Assert.Equal(1, resetInteractive.BuildProjectCount); Assert.Equal(0, resetInteractive.CancelBuildProjectCount); var expectedSubmissions = new List <string>(); if (expectedReferences.Any()) { expectedSubmissions.AddRange(expectedReferences.Select(r => r + newLineCharacter)); } if (expectedUsings.Any()) { expectedSubmissions.Add(string.Join(newLineCharacter, expectedUsings) + newLineCharacter); } AssertEx.Equal(expectedSubmissions, executedSubmissionCalls); testHost.Evaluator.OnExecute -= ExecuteSubmission; }
internal void InitializeWorkspace(TestWorkspace workspace) { _provider = new NavigateToItemProvider( workspace, workspace.GetService <IThreadingContext>(), workspace.GetService <IUIThreadOperationExecutor>(), AsynchronousOperationListenerProvider.NullListener); _aggregator = new NavigateToTestAggregator(_provider); }
private IQuickInfoProvider CreateProvider(TestWorkspace workspace) { return(new SyntacticQuickInfoProvider( workspace.GetService <IProjectionBufferFactoryService>(), workspace.GetService <IEditorOptionsFactoryService>(), workspace.GetService <ITextEditorFactoryService>(), workspace.GetService <IGlyphService>(), workspace.GetService <ClassificationTypeMap>())); }
public DiagnosticTaggerWrapper( TestWorkspace workspace, IReadOnlyDictionary <string, ImmutableArray <DiagnosticAnalyzer> >?analyzerMap = null, IDiagnosticUpdateSource?updateSource = null, bool createTaggerProvider = true ) { _threadingContext = workspace.GetService <IThreadingContext>(); _listenerProvider = workspace.GetService <IAsynchronousOperationListenerProvider>(); var analyzerReference = new TestAnalyzerReferenceByLanguage( analyzerMap ?? DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap() ); workspace.TryApplyChanges( workspace.CurrentSolution.WithAnalyzerReferences(new[] { analyzerReference }) ); _workspace = workspace; _registrationService = (SolutionCrawlerRegistrationService)workspace.Services.GetRequiredService <ISolutionCrawlerRegistrationService>(); _registrationService.Register(workspace); if ( !_registrationService .GetTestAccessor() .TryGetWorkCoordinator(workspace, out var coordinator) ) { throw new InvalidOperationException(); } AnalyzerService = (DiagnosticAnalyzerService?)_registrationService .GetTestAccessor() .AnalyzerProviders.SelectMany(pair => pair.Value) .SingleOrDefault( lazyProvider => lazyProvider.Metadata.Name == WellKnownSolutionCrawlerAnalyzers.Diagnostic && lazyProvider.Metadata.HighPriorityForActiveFile ) ?.Value; DiagnosticService = (DiagnosticService)workspace.ExportProvider.GetExportedValue <IDiagnosticService>(); if (updateSource is object) { DiagnosticService.Register(updateSource); } if (createTaggerProvider) { _ = TaggerProvider; } }
public TestContext(string projectLanguage = null, IEnumerable <string> metadataSources = null, bool includeXmlDocComments = false, string sourceWithSymbolReference = null) { projectLanguage = projectLanguage ?? LanguageNames.CSharp; metadataSources = metadataSources ?? SpecializedCollections.EmptyEnumerable <string>(); metadataSources = !metadataSources.Any() ? new[] { AbstractMetadataAsSourceTests.DefaultMetadataSource } : metadataSources; _workspace = CreateWorkspace(projectLanguage, metadataSources, includeXmlDocComments, sourceWithSymbolReference); _metadataAsSourceService = _workspace.GetService <IMetadataAsSourceFileService>(); _textBufferFactoryService = _workspace.GetService <ITextBufferFactoryService>(); }
private DiagnosticTaggerWrapper(TestWorkspace workspace, DiagnosticAnalyzerService analyzerService, IDiagnosticUpdateSource updateSource) { if (updateSource == null) { updateSource = analyzerService; } this.workspace = workspace; this.registrationService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>(); registrationService.Register(workspace); this.asyncListener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener)); this.analyzerService = analyzerService; var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable(updateSource), listeners); this.TaggerProvider = new DiagnosticsSquiggleTaggerProvider( workspace.Services.GetService <IOptionService>(), diagnosticService, workspace.GetService <IForegroundNotificationService>(), listeners); if (analyzerService != null) { this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace)); this.solutionCrawlerService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; } }
internal static IList <ITagSpan <IErrorTag> > GetErrorsFromUpdateSource(TestWorkspace workspace, TestHostDocument document, DiagnosticsUpdatedArgs updateArgs) { var source = new TestDiagnosticUpdateSource(); var listener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, listener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener)); var optionsService = workspace.Services.GetService <IOptionService>(); var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable <IDiagnosticUpdateSource>(source), listeners); var foregroundService = workspace.GetService <IForegroundNotificationService>(); //new TestForegroundNotificationService(); var buffer = document.GetTextBuffer(); var provider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners); var tagger = provider.CreateTagger <IErrorTag>(buffer); using (var disposable = tagger as IDisposable) { source.RaiseDiagnosticsUpdated(updateArgs); listener.CreateWaitTask().PumpingWait(); var snapshot = buffer.CurrentSnapshot; var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToImmutableArray(); return(spans); } }
private static (string quoteCharSnapshotText, int quoteCharCaretPosition) TypeQuoteChar( TestWorkspace workspace ) { var view = workspace.Documents.Single().GetTextView(); var commandHandler = workspace.ExportProvider.GetCommandHandler <FixInterpolatedVerbatimStringCommandHandler>( nameof(FixInterpolatedVerbatimStringCommandHandler) ); string quoteCharSnapshotText = null; int quoteCharCaretPosition = default; commandHandler.ExecuteCommand( new TypeCharCommandArgs(view, view.TextBuffer, '"'), () => { var editorOperations = workspace .GetService <IEditorOperationsFactoryService>() .GetEditorOperations(view); editorOperations.InsertText("\""); quoteCharSnapshotText = view.TextBuffer.CurrentSnapshot.GetText(); quoteCharCaretPosition = view.Caret.Position.BufferPosition.Position; }, TestCommandExecutionContext.Create() ); return(quoteCharSnapshotText, quoteCharCaretPosition); }
static VisualStudioInProcLanguageServer CreateLanguageServer(Stream inputStream, Stream outputStream, TestWorkspace workspace, IDiagnosticService mockDiagnosticService) { var dispatcherFactory = workspace.ExportProvider.GetExportedValue <RequestDispatcherFactory>(); var listenerProvider = workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>(); var lspWorkspaceRegistrationService = workspace.ExportProvider.GetExportedValue <ILspWorkspaceRegistrationService>(); var capabilitiesProvider = workspace.ExportProvider.GetExportedValue <DefaultCapabilitiesProvider>(); var jsonRpc = new JsonRpc(new HeaderDelimitedMessageHandler(outputStream, inputStream)) { ExceptionStrategy = ExceptionProcessing.ISerializable, }; var globalOptions = workspace.GetService <IGlobalOptionService>(); var languageServer = new VisualStudioInProcLanguageServer( dispatcherFactory, jsonRpc, capabilitiesProvider, lspWorkspaceRegistrationService, globalOptions, listenerProvider, NoOpLspLogger.Instance, mockDiagnosticService, ProtocolConstants.RoslynLspLanguages, clientName: null, userVisibleServerName: string.Empty, telemetryServerTypeName: string.Empty); jsonRpc.StartListening(); return(languageServer); }
private static LanguageServerTarget CreateLanguageServer(Stream inputStream, Stream outputStream, TestWorkspace workspace, WellKnownLspServerKinds serverKind) { var dispatcherFactory = workspace.ExportProvider.GetExportedValue <RequestDispatcherFactory>(); var listenerProvider = workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>(); var lspWorkspaceRegistrationService = workspace.ExportProvider.GetExportedValue <LspWorkspaceRegistrationService>(); var capabilitiesProvider = workspace.ExportProvider.GetExportedValue <DefaultCapabilitiesProvider>(); var jsonRpc = new JsonRpc(new HeaderDelimitedMessageHandler(outputStream, inputStream, CreateJsonMessageFormatter())) { ExceptionStrategy = ExceptionProcessing.ISerializable, }; var globalOptions = workspace.GetService <IGlobalOptionService>(); var languageServer = new LanguageServerTarget( dispatcherFactory, jsonRpc, capabilitiesProvider, lspWorkspaceRegistrationService, new LspMiscellaneousFilesWorkspace(NoOpLspLogger.Instance), globalOptions, listenerProvider, NoOpLspLogger.Instance, ProtocolConstants.RoslynLspLanguages, serverKind); jsonRpc.StartListening(); return(languageServer); }
private static LanguageServerTarget CreateLanguageServer(Stream inputStream, Stream outputStream, TestWorkspace workspace) { var dispatcherFactory = workspace.ExportProvider.GetExportedValue <VSTypeScriptRequestDispatcherFactory>(); var listenerProvider = workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>(); var lspWorkspaceRegistrationService = workspace.ExportProvider.GetExportedValue <LspWorkspaceRegistrationService>(); var capabilitiesProvider = workspace.ExportProvider.GetExportedValue <DefaultCapabilitiesProvider>(); var jsonRpc = new JsonRpc(new HeaderDelimitedMessageHandler(outputStream, inputStream)) { ExceptionStrategy = ExceptionProcessing.ISerializable, }; var globalOptions = workspace.GetService <IGlobalOptionService>(); var languageServer = new LanguageServerTarget( dispatcherFactory, jsonRpc, capabilitiesProvider, lspWorkspaceRegistrationService, new LspMiscellaneousFilesWorkspace(NoOpLspLogger.Instance), globalOptions, listenerProvider, NoOpLspLogger.Instance, ImmutableArray.Create(InternalLanguageNames.TypeScript), clientName: null, WellKnownLspServerKinds.RoslynTypeScriptLspServer); jsonRpc.StartListening(); return(languageServer); }
internal override IChainedCommandHandler <AutomaticLineEnderCommandArgs> GetCommandHandler(TestWorkspace workspace) { return(Assert.IsType <AutomaticLineEnderCommandHandler>( workspace.GetService <ICommandHandler>( ContentTypeNames.CSharpContentType, PredefinedCommandHandlerNames.AutomaticLineEnder))); }
public DiagnosticTaggerWrapper( TestWorkspace workspace, IReadOnlyDictionary <string, ImmutableArray <DiagnosticAnalyzer> >?analyzerMap = null, IDiagnosticUpdateSource?updateSource = null, bool createTaggerProvider = true) { _threadingContext = workspace.GetService <IThreadingContext>(); _listenerProvider = workspace.GetService <IAsynchronousOperationListenerProvider>(); var analyzerReference = new TestAnalyzerReferenceByLanguage(analyzerMap ?? DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()); workspace.TryApplyChanges(workspace.CurrentSolution.WithAnalyzerReferences(new[] { analyzerReference })); // Change the background analysis scope to OpenFiles instead of ActiveFile (default), // so that every diagnostic tagger test does not need to mark test files as "active" file. var csKey = new OptionKey2(SolutionCrawlerOptions.BackgroundAnalysisScopeOption, LanguageNames.CSharp); var vbKey = new OptionKey2(SolutionCrawlerOptions.BackgroundAnalysisScopeOption, LanguageNames.VisualBasic); workspace.SetOptions(workspace.Options .WithChangedOption(csKey, BackgroundAnalysisScope.OpenFiles) .WithChangedOption(vbKey, BackgroundAnalysisScope.OpenFiles)); _workspace = workspace; _registrationService = (SolutionCrawlerRegistrationService)workspace.Services.GetRequiredService <ISolutionCrawlerRegistrationService>(); _registrationService.Register(workspace); if (!_registrationService.GetTestAccessor().TryGetWorkCoordinator(workspace, out var coordinator)) { throw new InvalidOperationException(); } AnalyzerService = (DiagnosticAnalyzerService?)_registrationService.GetTestAccessor().AnalyzerProviders.SelectMany(pair => pair.Value).SingleOrDefault(lazyProvider => lazyProvider.Metadata.Name == WellKnownSolutionCrawlerAnalyzers.Diagnostic && lazyProvider.Metadata.HighPriorityForActiveFile)?.Value; DiagnosticService = (DiagnosticService)workspace.ExportProvider.GetExportedValue <IDiagnosticService>(); if (updateSource is object) { DiagnosticService.Register(updateSource); } if (createTaggerProvider) { _ = TaggerProvider; } }
private static async Task <IEnumerable <ITagSpan <BraceHighlightTag> > > ProduceTagsAsync( TestWorkspace workspace, ITextBuffer buffer, int position) { var producer = new BraceHighlightingViewTaggerProvider( workspace.ExportProvider.GetExportedValue <IThreadingContext>(), workspace.GetService <IBraceMatchingService>(), workspace.GetService <IGlobalOptionService>(), AsynchronousOperationListenerProvider.NullProvider); var context = new TaggerContext <BraceHighlightTag>( buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault(), buffer.CurrentSnapshot, new SnapshotPoint(buffer.CurrentSnapshot, position)); await producer.GetTestAccessor().ProduceTagsAsync(context); return(context.tagSpans); }
private async Task <IEnumerable <ITagSpan <BraceHighlightTag> > > ProduceTagsAsync( TestWorkspace workspace, ITextBuffer buffer, int position) { var view = new Mock <ITextView>(); var producer = new BraceHighlightingViewTaggerProvider( workspace.GetService <IBraceMatchingService>(), workspace.GetService <IForegroundNotificationService>(), AggregateAsynchronousOperationListener.EmptyListeners); var context = new TaggerContext <BraceHighlightTag>( buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault(), buffer.CurrentSnapshot, new SnapshotPoint(buffer.CurrentSnapshot, position)); await producer.ProduceTagsAsync_ForTestingPurposesOnly(context); return(context.tagSpans); }
public RenameTrackingTestState( TestWorkspace workspace, string languageName, bool onBeforeGlobalSymbolRenamedReturnValue = true, bool onAfterGlobalSymbolRenamedReturnValue = true ) { this.Workspace = workspace; _hostDocument = Workspace.Documents.First(); _view = _hostDocument.GetTextView(); _view.Caret.MoveTo( new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value) ); _editorOperations = Workspace .GetService <IEditorOperationsFactoryService>() .GetEditorOperations(_view); _historyRegistry = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value; _mockRefactorNotifyService = new MockRefactorNotifyService { OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue, OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue }; // Mock the action taken by the workspace INotificationService var notificationService = (INotificationServiceCallback)Workspace.Services.GetRequiredService <INotificationService>(); var callback = new Action <string, string, NotificationSeverity>( (message, title, severity) => _notificationMessage = message ); notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( Workspace.ExportProvider.GetExportedValue <IThreadingContext>(), Workspace.ExportProvider.GetExport <IInlineRenameService>().Value, Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value, Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>() ); _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer()); if (languageName == LanguageNames.CSharp || languageName == LanguageNames.VisualBasic) { _codeRefactoringProvider = new RenameTrackingCodeRefactoringProvider( _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService) ); } else { throw new ArgumentException( "Invalid language name: " + languageName, nameof(languageName) ); } }
public RenameTrackingTestState( string markup, string languageName, bool onBeforeGlobalSymbolRenamedReturnValue = true, bool onAfterGlobalSymbolRenamedReturnValue = true) { this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic()); _hostDocument = Workspace.Documents.First(); _view = _hostDocument.GetTextView(); _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value)); _editorOperations = Workspace.GetService <IEditorOperationsFactoryService>().GetEditorOperations(_view); _historyRegistry = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value; _mockRefactorNotifyService = new MockRefactorNotifyService { OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue, OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue }; var optionService = this.Workspace.Services.GetService <IOptionService>(); // Mock the action taken by the workspace INotificationService var notificationService = Workspace.Services.GetService <INotificationService>() as INotificationServiceCallback; var callback = new Action <string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message); notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( _historyRegistry, Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, Workspace.ExportProvider.GetExport <IInlineRenameService>().Value, Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService), Workspace.ExportProvider.GetExports <IAsynchronousOperationListener, FeatureMetadata>()); _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer()); if (languageName == LanguageNames.CSharp) { _codeFixProvider = new CSharpRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else if (languageName == LanguageNames.VisualBasic) { _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else { throw new ArgumentException("Invalid langauge name: " + languageName, "languageName"); } }
private static async Task <List <IOutliningRegionTag> > GetTagsFromWorkspaceAsync(TestWorkspace workspace) { var hostdoc = workspace.Documents.First(); var view = hostdoc.GetTextView(); var textService = workspace.GetService <ITextEditorFactoryService>(); var editorService = workspace.GetService <IEditorOptionsFactoryService>(); var projectionService = workspace.GetService <IProjectionBufferFactoryService>(); var provider = new VisualStudio14StructureTaggerProvider( workspace.ExportProvider.GetExportedValue <IForegroundNotificationService>(), textService, editorService, projectionService, AggregateAsynchronousOperationListener.EmptyListeners); var document = workspace.CurrentSolution.GetDocument(hostdoc.Id); var context = new TaggerContext <IOutliningRegionTag>(document, view.TextSnapshot); await provider.ProduceTagsAsync_ForTestingPurposesOnly(context); return(context.tagSpans.Select(x => x.Tag).ToList()); }
private static List <IOutliningRegionTag> GetTagsFromWorkspace(TestWorkspace workspace) { var hostdoc = workspace.Documents.First(); var view = hostdoc.GetTextView(); var textService = workspace.GetService <ITextEditorFactoryService>(); var editorService = workspace.GetService <IEditorOptionsFactoryService>(); var projectionService = workspace.GetService <IProjectionBufferFactoryService>(); var provider = new OutliningTaggerProvider.TagProducer( textService, editorService, projectionService); Document document = workspace.CurrentSolution.GetDocument(hostdoc.Id); return(provider.ProduceTagsAsync( document, new SnapshotSpan(view.TextSnapshot, 0, view.TextSnapshot.Length), null, CancellationToken.None).Result.Select(x => x.Tag).ToList()); }
public AbstractCompletionCommandHandlerTestState(XElement workspaceElement) { _workspace = TestWorkspaceFactory.CreateWorkspace(workspaceElement); _view = _workspace.Documents.Single().GetTextView(); int caretPosition = _workspace.Documents.Single(d => d.CursorPosition.HasValue).CursorPosition.Value; _view.Caret.MoveTo(new SnapshotPoint(_view.TextBuffer.CurrentSnapshot, caretPosition)); _editorOperations = _workspace.GetService <IEditorOperationsFactoryService>().GetEditorOperations(_view); }
private IEnumerable <ITagSpan <BraceHighlightTag> > ProduceTags( TestWorkspace workspace, ITextBuffer buffer, int position) { var producer = new BraceHighlightingTagProducer( workspace.GetService <IBraceMatchingService>()); var document = buffer.CurrentSnapshot.GetRelatedDocumentsWithChanges().FirstOrDefault(); return(producer.ProduceTagsAsync(document, buffer.CurrentSnapshot, position, CancellationToken.None).Result); }
private DiagnosticTaggerWrapper( TestWorkspace workspace, Dictionary <string, DiagnosticAnalyzer[]> analyzerMap, IDiagnosticUpdateSource updateSource, bool createTaggerProvider) { _threadingContext = workspace.GetService <IThreadingContext>(); _listenerProvider = workspace.GetService <IAsynchronousOperationListenerProvider>(); if (analyzerMap != null || updateSource == null) { AnalyzerService = CreateDiagnosticAnalyzerService(analyzerMap, _listenerProvider.GetListener(FeatureAttribute.DiagnosticService)); } if (updateSource == null) { updateSource = AnalyzerService; } _workspace = workspace; _registrationService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>(); _registrationService.Register(workspace); DiagnosticService = new DiagnosticService(_listenerProvider); DiagnosticService.Register(updateSource); if (createTaggerProvider) { var taggerProvider = this.TaggerProvider; } if (AnalyzerService != null) { _incrementalAnalyzers = ImmutableArray.Create(AnalyzerService.CreateIncrementalAnalyzer(workspace)); _solutionCrawlerService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; } }
public DiagnosticTaggerWrapper( TestWorkspace workspace, IReadOnlyDictionary <string, ImmutableArray <DiagnosticAnalyzer> >?analyzerMap = null, IDiagnosticUpdateSource?updateSource = null, bool createTaggerProvider = true) { _threadingContext = workspace.GetService <IThreadingContext>(); _listenerProvider = workspace.GetService <IAsynchronousOperationListenerProvider>(); if (updateSource == null) { updateSource = AnalyzerService = new MyDiagnosticAnalyzerService(_listenerProvider.GetListener(FeatureAttribute.DiagnosticService)); } var analyzerReference = new TestAnalyzerReferenceByLanguage(analyzerMap ?? DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()); workspace.TryApplyChanges(workspace.CurrentSolution.WithAnalyzerReferences(new[] { analyzerReference })); _workspace = workspace; _registrationService = workspace.Services.GetRequiredService <ISolutionCrawlerRegistrationService>(); _registrationService.Register(workspace); DiagnosticService = new DiagnosticService(_listenerProvider, Array.Empty <Lazy <IEventListener, EventListenerMetadata> >()); DiagnosticService.Register(updateSource); if (createTaggerProvider) { _ = TaggerProvider; } if (AnalyzerService != null) { _incrementalAnalyzers = ImmutableArray.Create(AnalyzerService.CreateIncrementalAnalyzer(workspace)); _solutionCrawlerService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; } }
public CallHierarchyTestState(XElement markup, params Type[] additionalTypes) { var exportProvider = CreateExportProvider(additionalTypes); this.Workspace = TestWorkspaceFactory.CreateWorkspace(markup, exportProvider: exportProvider); var testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue); _textView = testDocument.GetTextView(); _subjectBuffer = testDocument.GetTextBuffer(); var provider = Workspace.GetService <CallHierarchyProvider>(); _presenter = new MockCallHierarchyPresenter(); _commandHandler = new CallHierarchyCommandHandler(new[] { _presenter }, provider, TestWaitIndicator.Default); }
public CallHierarchyTestState(string markup, params Type[] additionalTypes) { var exportProvider = CreateExportProvider(additionalTypes); this.Workspace = CSharpWorkspaceFactory.CreateWorkspaceFromFile(markup, exportProvider: exportProvider); var testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue); _textView = testDocument.GetTextView(); _subjectBuffer = testDocument.GetTextBuffer(); var provider = Workspace.GetService<CallHierarchyProvider>(); var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback; var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => NotificationMessage = message); notificationService.NotificationCallback = callback; _presenter = new MockCallHierarchyPresenter(); _commandHandler = new CallHierarchyCommandHandler(new[] { _presenter }, provider, TestWaitIndicator.Default); }
private CallHierarchyTestState(string markup, TestWorkspace workspace) { this.Workspace = workspace; var testDocument = Workspace.Documents.Single(d => d.CursorPosition.HasValue); _textView = testDocument.GetTextView(); _subjectBuffer = testDocument.GetTextBuffer(); var provider = Workspace.GetService <CallHierarchyProvider>(); var notificationService = Workspace.Services.GetService <INotificationService>() as INotificationServiceCallback; var callback = new Action <string, string, NotificationSeverity>((message, title, severity) => NotificationMessage = message); notificationService.NotificationCallback = callback; _presenter = new MockCallHierarchyPresenter(); _commandHandler = new CallHierarchyCommandHandler(new[] { _presenter }, provider, TestWaitIndicator.Default); }
internal static List <ITagSpan <IErrorTag> > GetErrorSpans( TestWorkspace workspace, ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > analyzerMap = null) { var registrationService = workspace.Services.GetService <ISolutionCrawlerRegistrationService>(); registrationService.Register(workspace); var listener = new AsynchronousOperationListener(); var listeners = AsynchronousOperationListener.CreateListeners( ValueTuple.Create(FeatureAttribute.DiagnosticService, listener), ValueTuple.Create(FeatureAttribute.ErrorSquiggles, listener)); var optionsService = workspace.Services.GetService <IOptionService>(); var analyzerService = analyzerMap == null || analyzerMap.Count == 0 ? new TestDiagnosticAnalyzerService(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap()) : new TestDiagnosticAnalyzerService(analyzerMap); var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable <IDiagnosticUpdateSource>(analyzerService), listeners); var document = workspace.Documents.First(); var buffer = document.GetTextBuffer(); var foregroundService = workspace.GetService <IForegroundNotificationService>(); var taggerProvider = new DiagnosticsSquiggleTaggerProvider(optionsService, diagnosticService, foregroundService, listeners); var tagger = taggerProvider.CreateTagger <IErrorTag>(buffer); using (var disposable = tagger as IDisposable) { var service = workspace.Services.GetService <ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService; service.WaitUntilCompletion_ForTestingPurposesOnly(workspace, ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace))); listener.CreateWaitTask().PumpingWait(); var snapshot = buffer.CurrentSnapshot; var spans = tagger.GetTags(new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length))).ToList(); registrationService.Unregister(workspace); return(spans); } }
protected override async Task AssertContentIsAsync( TestWorkspace workspace, Document document, int position, string expectedContent, string expectedDocumentationComment = null) { var provider = CreateProvider(workspace); var state = await provider.GetItemAsync(document, position, cancellationToken : CancellationToken.None); Assert.NotNull(state); var hostingControlFactory = workspace.GetService <DeferredContentFrameworkElementFactory>(); var viewHostingControl = (ViewHostingControl)hostingControlFactory.CreateElement(state.Content); var actualContent = viewHostingControl.GetText_TestOnly(); Assert.Equal(expectedContent, actualContent); }
internal static Holder CreateSession(TestWorkspace workspace, char opening, char closing, OptionsCollection globalOptions = null) { var document = workspace.Documents.First(); var provider = Assert.IsType <BraceCompletionSessionProvider>(workspace.GetService <IBraceCompletionSessionProvider>()); var openingPoint = new SnapshotPoint(document.GetTextBuffer().CurrentSnapshot, document.CursorPosition.Value); var textView = document.GetTextView(); globalOptions?.SetGlobalOptions(workspace.GlobalOptions); workspace.GlobalOptions.SetEditorOptions(textView.Options.GlobalOptions, document.Project.Language); if (provider.TryCreateSession(textView, openingPoint, opening, closing, out var session)) { return(new Holder(workspace, session)); } workspace.Dispose(); return(null); }
internal static async Task <IList <ITagSpan <TTag> > > GetErrorsFromUpdateSource(TestWorkspace workspace, DiagnosticsUpdatedArgs updateArgs) { var globalOptions = workspace.GetService <IGlobalOptionService>(); var source = new TestDiagnosticUpdateSource(globalOptions); using var wrapper = new DiagnosticTaggerWrapper <TProvider, TTag>(workspace, updateSource: source); var tagger = wrapper.TaggerProvider.CreateTagger <TTag>(workspace.Documents.First().GetTextBuffer()); using var disposable = (IDisposable)tagger; source.RaiseDiagnosticsUpdated(updateArgs); await wrapper.WaitForTags(); var snapshot = workspace.Documents.First().GetTextBuffer().CurrentSnapshot; var spans = tagger.GetTags(snapshot.GetSnapshotSpanCollection()).ToImmutableArray(); return(spans); }