Esempio n. 1
0
        public void TestMultipleBackgroundAction()
        {
            // Test that background actions don't run at the same time.
            var listener  = new AggregateAsynchronousOperationListener(Enumerable.Empty <Lazy <IAsynchronousOperationListener, FeatureMetadata> >(), "Test");
            var worker    = new AsynchronousSerialWorkQueue(listener);
            var doneEvent = new AutoResetEvent(false);

            var action1Ran = false;
            var action2Ran = false;

            worker.EnqueueBackgroundWork(() =>
            {
                Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current);
                action1Ran = true;

                // Simulate work to ensure that if tasks overlap that we will
                // see it.
                Thread.Sleep(1000);
                Assert.False(action2Ran);
            }, "Test", CancellationToken.None);

            worker.EnqueueBackgroundWork(() =>
            {
                Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current);
                action2Ran = true;
                doneEvent.Set();
            }, "Test", CancellationToken.None);

            doneEvent.WaitOne();
            Assert.True(action1Ran);
            Assert.True(action2Ran);
        }
 public NavigationBarControllerFactoryService(
     IWaitIndicator waitIndicator,
     [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners)
 {
     _waitIndicator = waitIndicator;
     _asyncListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.NavigationBar);
 }
Esempio n. 3
0
        private void InitializeWorkspace(TestWorkspace workspace)
        {
            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider   = new NavigateToItemProvider(workspace, aggregateListener);
            _aggregator = new NavigateToTestAggregator(_provider);
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.SyntacticColorizer))
            {
                return(null);
            }

            if (!_tagComputers.TryGetValue(buffer, out var tagComputer))
            {
                var asyncListener = new AggregateAsynchronousOperationListener(_asyncListeners, FeatureAttribute.Classification);
                tagComputer = new TagComputer(buffer, _notificationService, asyncListener, _typeMap, this);
                _tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger      = new Tagger(tagComputer);
            var typedTagger = tagger as ITagger <T>;

            if (typedTagger == null)
            {
                // Oops, we can't actually return this tagger, so just clean up
                tagger.Dispose();
                return(null);
            }
            else
            {
                return(typedTagger);
            }
        }
Esempio n. 5
0
            public AdornmentManagerTester()
            {
                _subjectBuffer = EditorFactory.CreateBuffer(TestExportProvider.ExportProviderWithCSharpAndVisualBasic, "Hi There");

                _textView = new Mock <IWpfTextView>();
                var aggregatorService = new Mock <IViewTagAggregatorFactoryService>();

                _adornmentLayer = new Mock <IAdornmentLayer>();
                _aggregator     = new Mock <ITagAggregator <Tag> >();

                var layerName = "LayerName";

                _textView.Setup(tv => tv.GetAdornmentLayer(layerName)).Returns(_adornmentLayer.Object);
                _textView.SetupGet(tv => tv.VisualElement).Returns(new FrameworkElement());

                aggregatorService.Setup(a => a.CreateTagAggregator <Tag>(_textView.Object)).Returns(_aggregator.Object);

                var textViewModel = new Mock <ITextViewModel>();

                textViewModel.Setup(tvm => tvm.VisualBuffer).Returns(_subjectBuffer);
                _textView.Setup(tv => tv.TextViewModel).Returns(textViewModel.Object);

                var workspace = new TestWorkspace();

                var listener = new AggregateAsynchronousOperationListener(
                    Enumerable.Empty <Lazy <IAsynchronousOperationListener, FeatureMetadata> >(),
                    FeatureAttribute.LineSeparators);

                Manager = AdornmentManager <Tag> .Create(_textView.Object,
                                                         aggregatorService.Object,
                                                         listener,
                                                         adornmentLayerName : layerName);
            }
 public AbstractEncapsulateFieldCommandHandler(
     IWaitIndicator waitIndicator,
     ITextBufferUndoManagerProvider undoManager,
     IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners)
 {
     _waitIndicator = waitIndicator;
     _undoManager   = undoManager;
     _listener      = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.EncapsulateField);
 }
Esempio n. 7
0
 internal void BeginSession(
     EventHookupCommandHandler eventHookupCommandHandler,
     ITextView textView,
     ITextBuffer subjectBuffer,
     AggregateAsynchronousOperationListener asyncListener,
     Mutex testSessionHookupMutex)
 {
     CurrentSession = new EventHookupSession(this, eventHookupCommandHandler, textView, subjectBuffer, asyncListener, testSessionHookupMutex);
 }
Esempio n. 8
0
        public void TestBackgroundCancelMultipleActions()
        {
            // Ensure that multiple background actions are cancelled if they
            // use the same cancellation token.
            var listener = new AggregateAsynchronousOperationListener(Enumerable.Empty <Lazy <IAsynchronousOperationListener, FeatureMetadata> >(), "Test");
            var worker   = new AsynchronousSerialWorkQueue(listener);

            var taskRunningEvent = new AutoResetEvent(false);
            var cancelEvent      = new AutoResetEvent(false);
            var doneEvent        = new AutoResetEvent(false);

            var source            = new CancellationTokenSource();
            var cancellationToken = source.Token;

            var action1Ran = false;
            var action2Ran = false;

            worker.EnqueueBackgroundWork(() =>
            {
                action1Ran = true;

                Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current);
                Assert.False(cancellationToken.IsCancellationRequested);

                taskRunningEvent.Set();
                cancelEvent.WaitOne();

                cancellationToken.ThrowIfCancellationRequested();
                Assert.True(false);
            }, "Test", source.Token);

            // We should not run this action.
            worker.EnqueueBackgroundWork(() =>
            {
                action2Ran = true;
                Assert.False(true);
            }, "Test", source.Token);

            taskRunningEvent.WaitOne();

            source.Cancel();
            cancelEvent.Set();

            try
            {
                worker.WaitUntilCompletion_ForTestingPurposesOnly();
                Assert.True(false);
            }
            catch (AggregateException ae)
            {
                Assert.IsAssignableFrom <OperationCanceledException>(ae.InnerException);
            }

            Assert.True(action1Ran);
            Assert.False(action2Ran);
        }
Esempio n. 9
0
            public ImplicitCacheMonitor(ProjectCacheService owner, int backOffTimeSpanInMS) :
                base(AggregateAsynchronousOperationListener.CreateEmptyListener(),
                     backOffTimeSpanInMS,
                     CancellationToken.None)
            {
                _owner = owner;
                _gate  = new SemaphoreSlim(0);

                Start();
            }
 // protected for testing purposes.
 protected DiagnosticAnalyzerService(
     HostAnalyzerManager hostAnalyzerManager,
     AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource,
     IDiagnosticUpdateSourceRegistrationService registrationService,
     IAsynchronousOperationListener listener = null) : this(registrationService)
 {
     _hostAnalyzerManager        = hostAnalyzerManager;
     _hostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
     _listener = listener ?? AggregateAsynchronousOperationListener.CreateEmptyListener();
 }
Esempio n. 11
0
        public async Task TestTagsChangedForEntireFile()
        {
            var code =
                @"class Program2
{
    string x = @""/// <summary>$$
/// </summary>"";
}";

            using (var workspace = TestWorkspace.CreateCSharp(code))
            {
                var document      = workspace.Documents.First();
                var subjectBuffer = document.TextBuffer;
                var checkpoint    = new Checkpoint();
                var tagComputer   = new SyntacticClassificationTaggerProvider.TagComputer(
                    subjectBuffer,
                    workspace.GetService <IForegroundNotificationService>(),
                    AggregateAsynchronousOperationListener.CreateEmptyListener(),
                    null,
                    new SyntacticClassificationTaggerProvider(null, null, null));

                // Capture the expected value before the await, in case it changes.
                var           expectedLength      = subjectBuffer.CurrentSnapshot.Length;
                int?          actualVersionNumber = null;
                int?          actualLength        = null;
                List <string> callstacks          = new List <string>();
                tagComputer.TagsChanged += (s, e) =>
                {
                    actualVersionNumber = e.Span.Snapshot.Version.VersionNumber;
                    actualLength        = e.Span.Length;
                    callstacks.Add(new StackTrace().ToString());
                    checkpoint.Release();
                };

                await checkpoint.Task;
                Assert.Equal(1, actualVersionNumber);
                Assert.Equal(expectedLength, actualLength);
                Assert.Equal(1, callstacks.Count);

                checkpoint = new Checkpoint();

                // Now apply an edit that require us to reclassify more that just the current line
                var snapshot = subjectBuffer.Insert(document.CursorPosition.Value, "\"");
                expectedLength = snapshot.Length;

                // NOTE: TagsChanged is raised on the UI thread, so there is no race between
                // assigning expected here and verifying in the event handler, because the
                // event handler can't run until we await.
                await checkpoint.Task;
                Assert.Equal(2, actualVersionNumber);
                Assert.Equal(expectedLength, actualLength);
                Assert.Equal(2, callstacks.Count);
            }
        }
Esempio n. 12
0
        private void InitializeWorkspace(TestWorkspace workspace)
        {
            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider = new NavigateToItemProvider(
                workspace,
                _glyphServiceMock.Object,
                aggregateListener,
                workspace.ExportProvider.GetExportedValues <Lazy <INavigateToOptionsService, VisualStudioVersionMetadata> >());
            _aggregator = new NavigateToTestAggregator(_provider);
        }
Esempio n. 13
0
        protected AbstractGraphProvider(
            IGlyphService glyphService,
            SVsServiceProvider serviceProvider,
            Workspace workspace,
            IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners)
        {
            _glyphService    = glyphService;
            _serviceProvider = serviceProvider;
            var asyncListener = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.GraphProvider);

            _graphQueryManager = new GraphQueryManager(workspace, asyncListener);
        }
        public void Test_HeavyMultipleCall()
        {
            var asyncToken = AggregateAsynchronousOperationListener.CreateEmptyListener().BeginAsyncOperation("EnqueueTest");
            var count      = 0;

            var loopCount = 100000;
            var done      = false;

            for (var i = 0; i < loopCount; i++)
            {
                var index = i;
                var retry = false;

                _service.RegisterNotification(() =>
                {
                    if (retry)
                    {
                        return(false);
                    }

                    var source = new CancellationTokenSource();

                    _service.RegisterNotification(() =>
                    {
                        for (int j = 0; j < 100; j++)
                        {
                            count++;
                        }
                    }, asyncToken, source.Token);

                    if ((index % 10) == 0)
                    {
                        source.Cancel();

                        retry = true;
                        return(retry);
                    }

                    if (index == loopCount - 1)
                    {
                        _service.RegisterNotification(() => { done = true; }, asyncToken, CancellationToken.None);
                    }

                    return(false);
                }, asyncToken, CancellationToken.None);
            }

            PumpWait(ref done);

            Assert.True(done);
            Assert.Equal(count, 9000000);
            Assert.True(Empty(_service));
        }
Esempio n. 15
0
 public InlineRenameService(
     IWaitIndicator waitIndicator,
     ITextBufferAssociatedViewService textBufferAssociatedViewService,
     ITextBufferFactoryService textBufferFactoryService,
     [ImportMany] IEnumerable <IRefactorNotifyService> refactorNotifyServices,
     [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > listeners)
 {
     _waitIndicator = waitIndicator;
     _textBufferAssociatedViewService = textBufferAssociatedViewService;
     _textBufferFactoryService        = textBufferFactoryService;
     _refactorNotifyServices          = refactorNotifyServices;
     _aggregateListener = new AggregateAsynchronousOperationListener(listeners, FeatureAttribute.Rename);
 }
Esempio n. 16
0
        private TestWorkspace SetupWorkspace(params string[] lines)
        {
            var workspace         = CSharpWorkspaceFactory.CreateWorkspaceFromLines(lines);
            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider = new NavigateToItemProvider(
                workspace,
                _glyphServiceMock.Object,
                aggregateListener);
            _aggregator = new NavigateToTestAggregator(_provider);

            return(workspace);
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!buffer.GetOption(InternalFeatureOnOffOptions.SyntacticColorizer))
            {
                return(null);
            }

            TagComputer tagComputer;

            if (!_tagComputers.TryGetValue(buffer, out tagComputer))
            {
                var asyncListener = new AggregateAsynchronousOperationListener(_asyncListeners, FeatureAttribute.Classification);

                var languageName = _contentTypesToLanguageNames.FirstOrDefault(x => buffer.ContentType.MatchesAny(x.Metadata.DefaultContentType))?.Metadata.Language;
                var editorClassificationService = _editorClassificationLanguageServices.FirstOrDefault(x => x.Metadata.Language == languageName).Value as IEditorClassificationService;

                if (editorClassificationService == null)
                {
                    return(null);
                }

                tagComputer = new TagComputer(
                    buffer,
                    _notificationService,
                    asyncListener,
                    _typeMap,
                    this,
                    _viewSupportsClassificationServiceOpt,
                    _associatedViewService,
                    editorClassificationService,
                    languageName);

                _tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger      = new Tagger(tagComputer);
            var typedTagger = tagger as ITagger <T>;

            if (typedTagger == null)
            {
                // Oops, we can't actually return this tagger, so just clean up
                tagger.Dispose();
                return(null);
            }
            else
            {
                return(typedTagger);
            }
        }
Esempio n. 18
0
        public async Task TestTagsChangedForEntireFile()
        {
            var code =
                @"class Program2
{
    string x = @""/// <summary>$$
/// </summary>"";
}";

            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromFile(code))
            {
                var document      = workspace.Documents.First();
                var subjectBuffer = document.TextBuffer;
                var checkpoint    = new Checkpoint();
                var tagComputer   = new SyntacticClassificationTaggerProvider.TagComputer(
                    subjectBuffer,
                    workspace.GetService <IForegroundNotificationService>(),
                    AggregateAsynchronousOperationListener.CreateEmptyListener(),
                    typeMap: null,
                    taggerProvider: new SyntacticClassificationTaggerProvider(
                        notificationService: null,
                        typeMap: null,
                        viewSupportsClassificationServiceOpt: null,
                        associatedViewService: null,
                        allLanguageServices: ImmutableArray <Lazy <ILanguageService, LanguageServiceMetadata> > .Empty,
                        contentTypes: ImmutableArray <Lazy <ILanguageService, ContentTypeLanguageMetadata> > .Empty,
                        asyncListeners: ImmutableArray <Lazy <IAsynchronousOperationListener, FeatureMetadata> > .Empty),
                    viewSupportsClassificationServiceOpt: null,
                    associatedViewService: null,
                    editorClassificationService: null,
                    languageName: null);

                SnapshotSpan span = default(SnapshotSpan);
                tagComputer.TagsChanged += (s, e) =>
                {
                    span = e.Span;
                    checkpoint.Release();
                };

                await checkpoint.Task.ConfigureAwait(true);

                checkpoint = new Checkpoint();

                // Now apply an edit that require us to reclassify more that just the current line
                subjectBuffer.Insert(document.CursorPosition.Value, "\"");

                await checkpoint.Task.ConfigureAwait(true);

                Assert.Equal(subjectBuffer.CurrentSnapshot.Length, span.Length);
            }
        }
Esempio n. 19
0
        private async Task <TestWorkspace> SetupWorkspaceAsync(params string[] files)
        {
            var workspace = await CSharpWorkspaceFactory.CreateWorkspaceFromFilesAsync(files, parseOptions : Options.Script);

            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider = new NavigateToItemProvider(
                workspace,
                _glyphServiceMock.Object,
                aggregateListener);
            _aggregator = new NavigateToTestAggregator(_provider);

            return(workspace);
        }
        public EventHookupCommandHandler(
            IInlineRenameService inlineRenameService,
            Microsoft.CodeAnalysis.Editor.Host.IWaitIndicator waitIndicator,
            IQuickInfoBroker quickInfoBroker,
            [Import(AllowDefault = true)] IHACK_EventHookupDismissalOnBufferChangePreventerService prematureDismissalPreventer,
            [ImportMany] IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners)
        {
            _inlineRenameService         = inlineRenameService;
            _waitIndicator               = waitIndicator;
            _prematureDismissalPreventer = prematureDismissalPreventer;
            _asyncListener               = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.EventHookup);

            this.EventHookupSessionManager = new EventHookupSessionManager(prematureDismissalPreventer, quickInfoBroker);
        }
Esempio n. 21
0
        private async Task <TestWorkspace> SetupWorkspaceAsync(string content)
        {
            var workspace = await TestWorkspace.CreateCSharpAsync(content);

            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider = new NavigateToItemProvider(
                workspace,
                _glyphServiceMock.Object,
                aggregateListener);
            _aggregator = new NavigateToTestAggregator(_provider);

            return(workspace);
        }
        public void Test_Enqueue()
        {
            var asyncToken = AggregateAsynchronousOperationListener.CreateEmptyListener().BeginAsyncOperation("EnqueueTest");
            var done       = false;
            var ran        = false;

            _service.RegisterNotification(() => { Thread.Sleep(100); }, asyncToken, CancellationToken.None);
            _service.RegisterNotification(() => { /* do nothing */ }, asyncToken, CancellationToken.None);
            _service.RegisterNotification(() => { ran = true; done = true; }, asyncToken, CancellationToken.None);

            PumpWait(ref done);

            Assert.True(ran);
            Assert.True(Empty(_service));
        }
Esempio n. 23
0
        private async Task <TestWorkspace> SetupWorkspaceAsync(string content)
        {
            var workspace = await TestWorkspace.CreateCSharpAsync(content, exportProvider : s_exportProvider);

            var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

            _provider = new NavigateToItemProvider(
                workspace,
                _glyphServiceMock.Object,
                aggregateListener,
                workspace.ExportProvider.GetExportedValues <Lazy <INavigateToOptionsService, VisualStudioVersionMetadata> >());
            _aggregator = new NavigateToTestAggregator(_provider);

            return(workspace);
        }
Esempio n. 24
0
        public async Task NavigateToGeneratedFiles()
        {
            using (var workspace = TestWorkspace.Create(@"
<Workspace>
    <Project Language=""C#"" CommonReferences=""true"">
        <Document FilePath=""File1.cs"">
            namespace N
            {
                public partial class C
                {
                    public void VisibleMethod() { }
                }
            }
        </Document>
        <Document FilePath=""File1.g.cs"">
            namespace N
            {
                public partial class C
                {
                    public void VisibleMethod_Generated() { }
                }
            }
        </Document>
    </Project>
</Workspace>
", exportProvider: s_exportProvider))
            {
                var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

                _provider = new NavigateToItemProvider(
                    workspace, _glyphServiceMock.Object, aggregateListener,
                    workspace.ExportProvider.GetExportedValues <Lazy <INavigateToHostVersionService, VisualStudioVersionMetadata> >());
                _aggregator = new NavigateToTestAggregator(_provider);

                var items = await _aggregator.GetItemsAsync("VisibleMethod");

                var expectedItems = new List <NavigateToItem>()
                {
                    new NavigateToItem("VisibleMethod", NavigateToItemKind.Method, "csharp", null, null, MatchKind.Exact, true, null),
                    new NavigateToItem("VisibleMethod_Generated", NavigateToItemKind.Method, "csharp", null, null, MatchKind.Prefix, true, null)
                };

                // The pattern matcher should match 'VisibleMethod' to both 'VisibleMethod' and 'VisibleMethod_Not', except that
                // the _Not method is declared in a generated file.
                VerifyNavigateToResultItems(expectedItems, items);
            }
        }
Esempio n. 25
0
            public SolutionChecksumUpdater(RemoteHostClientService service, CancellationToken shutdownToken) :
                base(AggregateAsynchronousOperationListener.CreateEmptyListener(),
                     service.Workspace.Services.GetService <IGlobalOperationNotificationService>(),
                     service.Workspace.Options.GetOption(RemoteHostOptions.SolutionChecksumMonitorBackOffTimeSpanInMS), shutdownToken)
            {
                _service = service;

                _event = new SemaphoreSlim(initialCount: 0);

                // start listening workspace change event
                _service.Workspace.WorkspaceChanged += OnWorkspaceChanged;

                // create its own cancellation token source
                _globalOperationCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(shutdownToken);

                Start();
            }
Esempio n. 26
0
        public AbstractSnippetInfoService(
            Shell.SVsServiceProvider serviceProvider,
            Guid languageGuidForSnippets,
            IEnumerable <Lazy <IAsynchronousOperationListener, FeatureMetadata> > asyncListeners)
        {
            AssertIsForeground();

            if (serviceProvider != null)
            {
                var textManager = (IVsTextManager2)serviceProvider.GetService(typeof(SVsTextManager));
                if (textManager.GetExpansionManager(out _expansionManager) == VSConstants.S_OK)
                {
                    ComEventSink.Advise <IVsExpansionEvents>(_expansionManager, this);
                    _waiter = new AggregateAsynchronousOperationListener(asyncListeners, FeatureAttribute.Snippets);
                    _languageGuidForSnippets = languageGuidForSnippets;
                    PopulateSnippetCaches();
                }
            }
        }
        public void Test_Delay()
        {
            var asyncToken = AggregateAsynchronousOperationListener.CreateEmptyListener().BeginAsyncOperation("EnqueueTest");

            bool     done = false;
            DateTime now  = DateTime.UtcNow;
            DateTime set  = DateTime.UtcNow;

            _service.RegisterNotification(() =>
            {
                set  = DateTime.UtcNow;
                done = true;
            }, 50, asyncToken, CancellationToken.None);

            PumpWait(ref done);

            Assert.True(set.Subtract(now).TotalMilliseconds > 50);
            Assert.True(Empty(_service));
        }
Esempio n. 28
0
        public void NoNavigationToGeneratedFiles()
        {
            using (var workspace = TestWorkspaceFactory.CreateWorkspace(@"
<Workspace>
    <Project Language=""C#"" CommonReferences=""true"">
        <Document FilePath=""File1.cs"">
            namespace N
            {
                public partial class C
                {
                    public void VisibleMethod() { }
                }
            }
        </Document>
        <Document FilePath=""File1.g.cs"">
            namespace N
            {
                public partial class C
                {
                    public void VisibleMethod_Not() { }
                }
            }
        </Document>
    </Project>
</Workspace>
"))
            {
                var aggregateListener = AggregateAsynchronousOperationListener.CreateEmptyListener();

                _provider   = new NavigateToItemProvider(workspace, _glyphServiceMock.Object, aggregateListener);
                _aggregator = new NavigateToTestAggregator(_provider);

                var items         = _aggregator.GetItems("VisibleMethod");
                var expectedItems = new List <NavigateToItem>()
                {
                    new NavigateToItem("VisibleMethod", NavigateToItemKind.Method, "csharp", null, null, MatchKind.Exact, true, null)
                };

                // The pattern matcher should match 'VisibleMethod' to both 'VisibleMethod' and 'VisibleMethod_Not', except that
                // the _Not method is declared in a generated file.
                VerifyNavigateToResultItems(expectedItems, items);
            }
        }
Esempio n. 29
0
        public void TestBackgroundAction()
        {
            var listener  = new AggregateAsynchronousOperationListener(Enumerable.Empty <Lazy <IAsynchronousOperationListener, FeatureMetadata> >(), "Test");
            var worker    = new AsynchronousSerialWorkQueue(listener);
            var doneEvent = new AutoResetEvent(initialState: false);

            var actionRan = false;

            worker.EnqueueBackgroundWork(() =>
            {
                // Assert.NotNull(SynchronizationContext.Current);
                Assert.NotSame(_foregroundSyncContext, SynchronizationContext.Current);
                actionRan = true;
                doneEvent.Set();
            }, GetType().Name + ".TestBackgroundAction", CancellationToken.None);

            doneEvent.WaitOne();
            Assert.True(actionRan);
        }
Esempio n. 30
0
        public async Task TestTagsChangedForEntireFile()
        {
            var code =
                @"class Program2
{
    string x = @""/// <summary>$$
/// </summary>"";
}";

            using (var workspace = CSharpWorkspaceFactory.CreateWorkspaceFromFile(code))
            {
                var document      = workspace.Documents.First();
                var subjectBuffer = document.TextBuffer;
                var checkpoint    = new Checkpoint();
                var tagComputer   = new SyntacticClassificationTaggerProvider.TagComputer(
                    subjectBuffer,
                    workspace.GetService <IForegroundNotificationService>(),
                    AggregateAsynchronousOperationListener.CreateEmptyListener(),
                    null,
                    new SyntacticClassificationTaggerProvider(null, null, null));

                SnapshotSpan span = default(SnapshotSpan);
                tagComputer.TagsChanged += (s, e) =>
                {
                    span = e.Span;
                    checkpoint.Release();
                };

                await checkpoint.Task.ConfigureAwait(true);

                checkpoint = new Checkpoint();

                // Now apply an edit that require us to reclassify more that just the current line
                subjectBuffer.Insert(document.CursorPosition.Value, "\"");

                await checkpoint.Task.ConfigureAwait(true);

                Assert.Equal(subjectBuffer.CurrentSnapshot.Length, span.Length);
            }
        }