Example #1
0
        protected async Task AssertNavigatedAsync(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 = TestWorkspace.Create(
                           LanguageName,
                           compilationOptions: null,
                           parseOptions: DefaultParseOptions.WithKind(kind),
                           content: code))
                {
                    var hostDocument   = workspace.DocumentWithCursor;
                    var document       = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                    var parsedDocument = await ParsedDocument.CreateAsync(document, CancellationToken.None);

                    Assert.Empty(parsedDocument.SyntaxTree.GetDiagnostics());
                    var service = document.GetRequiredLanguageService <ISyntaxFactsService>();

                    var targetPosition = GoToAdjacentMemberCommandHandler.GetTargetPosition(
                        service,
                        parsedDocument.Root,
                        hostDocument.CursorPosition.Value,
                        next);

                    Assert.NotNull(targetPosition);
                    Assert.Equal(hostDocument.SelectedSpans.Single().Start, targetPosition.Value);
                }
            }
        }
        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));
     }
 }
Example #4
0
        protected async Task <int?> GetTargetPositionAsync(string code, bool next)
        {
            using (var workspace = TestWorkspace.Create(
                       LanguageName,
                       compilationOptions: null,
                       parseOptions: DefaultParseOptions,
                       content: code))
            {
                var hostDocument   = workspace.DocumentWithCursor;
                var document       = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                var parsedDocument = await ParsedDocument.CreateAsync(document, CancellationToken.None);

                Assert.Empty(parsedDocument.SyntaxTree.GetDiagnostics());

                return(GoToAdjacentMemberCommandHandler.GetTargetPosition(
                           document.GetRequiredLanguageService <ISyntaxFactsService>(),
                           parsedDocument.Root,
                           hostDocument.CursorPosition.Value,
                           next));
            }
        }