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 = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                           LanguageName,
                           compilationOptions: null,
                           parseOptions: DefaultParseOptions.WithKind(kind),
                           content: code))
                {
                    var hostDocument = workspace.DocumentWithCursor;
                    var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                    Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());
                    var targetPosition = await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                        document,
                        hostDocument.CursorPosition.Value,
                        next,
                        CancellationToken.None);

                    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 async Task <int?> GetTargetPositionAsync(string code, bool next)
 {
     using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                LanguageNames.CSharp,
                new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary),
                CSharpParseOptions.Default,
                code))
     {
         var hostDocument = workspace.DocumentWithCursor;
         var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
         Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());
         return(await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                    document,
                    hostDocument.CursorPosition.Value,
                    next,
                    CancellationToken.None));
     }
 }
        protected async Task <int?> GetTargetPositionAsync(string code, bool next)
        {
            using (var workspace = await TestWorkspaceFactory.CreateWorkspaceFromLinesAsync(
                       LanguageName,
                       compilationOptions: null,
                       parseOptions: DefaultParseOptions,
                       content: code))
            {
                var hostDocument = workspace.DocumentWithCursor;
                var document     = workspace.CurrentSolution.GetDocument(hostDocument.Id);
                Assert.Empty((await document.GetSyntaxTreeAsync()).GetDiagnostics());

                return(await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
                           document,
                           hostDocument.CursorPosition.Value,
                           next,
                           CancellationToken.None));
            }
        }
Beispiel #5
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));
            }
        }