Beispiel #1
0
        private void InsertText(string code, string text, bool expectDocumentAnalysis, string language = LanguageNames.CSharp)
        {
            using (var workspace = TestWorkspaceFactory.CreateWorkspaceFromLines(
                       SolutionCrawler, language, compilationOptions: null, parseOptions: null, content: new string[] { code }))
            {
                var analyzer   = new Analyzer();
                var lazyWorker = new Lazy <IIncrementalAnalyzerProvider, IncrementalAnalyzerProviderMetadata>(() => new AnalyzerProvider(analyzer), Metadata.Crawler);
                var service    = new SolutionCrawlerRegistrationService(new[] { lazyWorker }, GetListeners(workspace.ExportProvider));

                service.Register(workspace);

                var testDocument = workspace.Documents.First();

                var insertPosition = testDocument.CursorPosition;
                var textBuffer     = testDocument.GetTextBuffer();

                using (var edit = textBuffer.CreateEdit())
                {
                    edit.Insert(insertPosition.Value, text);
                    edit.Apply();
                }

                Wait(service, workspace);

                service.Unregister(workspace);

                Assert.Equal(1, analyzer.SyntaxDocumentIds.Count);
                Assert.Equal(expectDocumentAnalysis ? 1 : 0, analyzer.DocumentIds.Count);
            }
        }
        private static void AssertNavigated(string code, bool next, SourceCodeKind?sourceCodeKind = null)
        {
            var kinds = sourceCodeKind != null
                ? SpecializedCollections.SingletonEnumerable(sourceCodeKind.Value)
                : new[] { SourceCodeKind.Regular, SourceCodeKind.Script };

            foreach (var kind in kinds)
            {
                using (var workspace = TestWorkspaceFactory.CreateWorkspaceFromLines(
                           LanguageNames.CSharp,
                           new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                           CSharpParseOptions.Default.WithKind(kind),
                           code))
                {
                    var hostDocument = workspace.DocumentWithCursor;
                    var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                    Assert.Empty(document.GetSyntaxTreeAsync().Result.GetDiagnostics());
                    var targetPosition = GoToAdjacentMemberCommandHandler.GetTargetPosition(
                        document,
                        hostDocument.CursorPosition.Value,
                        next,
                        CancellationToken.None);

                    Assert.NotNull(targetPosition);
                    Assert.Equal(hostDocument.SelectedSpans.Single().Start, targetPosition.Value);
                }
            }
        }
 private static int?GetTargetPosition(string code, bool next)
 {
     using (var workspace = TestWorkspaceFactory.CreateWorkspaceFromLines(
                LanguageNames.CSharp,
                new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                CSharpParseOptions.Default,
                code))
     {
         var hostDocument = workspace.DocumentWithCursor;
         var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
         Assert.Empty(document.GetSyntaxTreeAsync().Result.GetDiagnostics());
         return(GoToAdjacentMemberCommandHandler.GetTargetPosition(
                    document,
                    hostDocument.CursorPosition.Value,
                    next,
                    CancellationToken.None));
     }
 }