{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/43169229","id":43169229,"diff_hunk":"@@ -0,0 +1,185 @@\n+﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.\n+\n+using System;\n+using System.ComponentModel.Composition;\n+using System.Diagnostics;\n+using System.Threading;\n+using Microsoft.CodeAnalysis.Editor.Commands;\n+using Microsoft.CodeAnalysis.Editor.Host;\n+using Microsoft.CodeAnalysis.Editor.Shared.Extensions;\n+using Microsoft.CodeAnalysis.Editor.Shared.SuggestionSupport;\n+using Microsoft.CodeAnalysis.LanguageServices;\n+using Microsoft.CodeAnalysis.Shared.Extensions;\n+using Microsoft.CodeAnalysis.Text;\n+using Microsoft.VisualStudio.Text;\n+using Microsoft.VisualStudio.Text.Editor;\n+using Microsoft.VisualStudio.Text.Outlining;\n+using Roslyn.Utilities;\n+\n+namespace Microsoft.CodeAnalysis.Editor.CommandHandlers\n+{\n+    [ExportCommandHandler(PredefinedCommandHandlerNames.GoToNextAndPreviousMethod, ContentTypeNames.RoslynContentType)]\n+    internal class GoToNextAndPreviousMethodCommandHandler : ICommandHandler<GoToNextMethodCommandArgs>, ICommandHandler<GoToPreviousMethodCommandArgs>\n+    {\n+        private readonly IWaitIndicator _waitIndicator;\n+        private readonly IOutliningManagerService _outliningManagerService;\n+\n+        [ImportingConstructor]\n+        public GoToNextAndPreviousMethodCommandHandler(IWaitIndicator waitIndicator, IOutliningManagerService outliningManagerService)\n+        {\n+            _waitIndicator = waitIndicator;\n+            _outliningManagerService = outliningManagerService;\n+        }\n+\n+        public CommandState GetCommandState(GoToNextMethodCommandArgs args, Func<CommandState> nextHandler)\n+            => GetCommandState(args.SubjectBuffer, args.TextView, nextHandler);\n+\n+        public void ExecuteCommand(GoToNextMethodCommandArgs args, Action nextHandler)\n+            => ExecuteCommand(nextHandler, args.SubjectBuffer, args.TextView, next: true);\n+\n+        public CommandState GetCommandState(GoToPreviousMethodCommandArgs args, Func<CommandState> nextHandler)\n+            => GetCommandState(args.SubjectBuffer, args.TextView, nextHandler);\n+\n+        public void ExecuteCommand(GoToPreviousMethodCommandArgs args, Action nextHandler)\n+            => ExecuteCommand(nextHandler, args.SubjectBuffer, args.TextView, next: false);\n+\n+        private static CommandState GetCommandState(ITextBuffer subjectBuffer, ITextView textView, Func<CommandState> nextHandler)\n+        {\n+            var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();\n+            var caretPoint = textView.GetCaretPoint(subjectBuffer);\n+            return IsAvailable(document, caretPoint) ? CommandState.Available : nextHandler();\n+        }\n+\n+        private static bool IsAvailable(Document document, SnapshotPoint? caretPoint)\n+        {\n+            var documentSupportsSuggestionService = document.Project.Solution.Workspace.Services.GetService<IDocumentSupportsSuggestionService>();\n+            if (document == null || !document.SupportsSyntaxTree || !documentSupportsSuggestionService.SupportsNavigationToAnyPosition(document))\n+            {\n+                return false;\n+            }\n+\n+            if (!caretPoint.HasValue)\n+            {\n+                return false;\n+            }\n+\n+            return true;\n+        }\n+\n+        private void ExecuteCommand(Action nextHandler, ITextBuffer subjectBuffer, ITextView textView, bool next)\n+        {\n+            var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();\n+            var caretPoint = textView.GetCaretPoint(subjectBuffer);\n+            if (!IsAvailable(document, caretPoint))\n+            {\n+                nextHandler();\n+                return;\n+            }\n+\n+            int? targetPosition = null;\n+            var waitResult = _waitIndicator.Wait(EditorFeaturesResources.Navigating, allowCancel: true, action: waitContext =>\n+            {\n+                targetPosition = GetTargetPosition(document, caretPoint.Value.Position, next, waitContext.CancellationToken);\n+            });\n+\n+            if (waitResult == WaitIndicatorResult.Canceled || targetPosition == null)\n+            {\n+                return;\n+            }\n+\n+            textView.TryMoveCaretToAndEnsureVisible(new SnapshotPoint(subjectBuffer.CurrentSnapshot, targetPosition.Value), _outliningManagerService);\n+        }\n+\n+        /// <summary>\n+        /// Internal for testing purposes.\n+        /// </summary>\n+        internal static int? GetTargetPosition(Document document, int caretPosition, bool next, CancellationToken cancellationToken)\n+        {\n+            var syntaxFactsService = document.GetLanguageService<ISyntaxFactsService>();\n+            if (syntaxFactsService == null)\n+            {\n+                return null;\n+            }\n+\n+            var root = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);\n+            var members = syntaxFactsService.GetMethodLevelMembers(root);\n+\n+            if (members.Count == 0)\n+            {\n+                return null;\n+            }\n+\n+            var currentMember = GetMember(syntaxFactsService, caretPosition, root);\n+            int indexOfCurrentMember;\n+            if (currentMember == null)\n+            {\n+                // We're not contained in any member currently.  Find the first member to start after our\n+                // position and use that.\n+                for (indexOfCurrentMember = 0; indexOfCurrentMember < members.Count; indexOfCurrentMember++)","path":"src/EditorFeatures/Core/CommandHandlers/GoToNextAndPreviousMethodCommandHandler.cs","position":118,"original_position":118,"commit_id":"c104073c6c662502de3a90ae5006b885586ec22d","original_commit_id":"c104073c6c662502de3a90ae5006b885586ec22d","user":{"login":"CyrusNajmabadi","id":4564579,"avatar_url":"https://avatars.githubusercontent.com/u/4564579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"body":"Seems like this code could be inside GetMember.  And GetMember would just be some sort of binary search.","created_at":"2015-10-27T18:54:15Z","updated_at":"2015-10-27T18:54:15Z","html_url":"https://github.com/dotnet/roslyn/pull/6299#discussion_r43169229","pull_request_url":"https://api.github.com/repos/dotnet/roslyn/pulls/6299","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/43169229"},"html":{"href":"https://github.com/dotnet/roslyn/pull/6299#discussion_r43169229"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/6299"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/6299","id":48667220,"html_url":"https://github.com/dotnet/roslyn/pull/6299","diff_url":"https://github.com/dotnet/roslyn/pull/6299.diff","patch_url":"https://github.com/dotnet/roslyn/pull/6299.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/6299","number":6299,"state":"open","locked":false,"title":"Support \"Go to next/previous method\" commands","user":{"login":"Pilchie","id":312835,"avatar_url":"https://avatars.githubusercontent.com/u/312835?v=3","gravatar_id":"","url":"https://api.github.com/users/Pilchie","html_url":"https://github.com/Pilchie","followers_url":"https://api.github.com/users/Pilchie/followers","following_url":"https://api.github.com/users/Pilchie/following{/other_user}","gists_url":"https://api.github.com/users/Pilchie/gists{/gist_id}","starred_url":"https://api.github.com/users/Pilchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pilchie/subscriptions","organizations_url":"https://api.github.com/users/Pilchie/orgs","repos_url":"https://api.github.com/users/Pilchie/repos","events_url":"https://api.github.com/users/Pilchie/events{/privacy}","received_events_url":"https://api.github.com/users/Pilchie/received_events","type":"User","site_admin":false},"body":"Fixes #4311","created_at":"2015-10-24T22:49:51Z","updated_at":"2015-10-27T18:54:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"53ab19f788023443b0c6d19c3071b1ca08b650ad","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn/pulls/6299/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn/pulls/6299/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/6299/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/c104073c6c662502de3a90ae5006b885586ec22d","head":{"label":"Pilchie:Fix4311-NextAndPreviousMethodCommands","ref":"Fix4311-NextAndPreviousMethodCommands","sha":"c104073c6c662502de3a90ae5006b885586ec22d","user":{"login":"Pilchie","id":312835,"avatar_url":"https://avatars.githubusercontent.com/u/312835?v=3","gravatar_id":"","url":"https://api.github.com/users/Pilchie","html_url":"https://github.com/Pilchie","followers_url":"https://api.github.com/users/Pilchie/followers","following_url":"https://api.github.com/users/Pilchie/following{/other_user}","gists_url":"https://api.github.com/users/Pilchie/gists{/gist_id}","starred_url":"https://api.github.com/users/Pilchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pilchie/subscriptions","organizations_url":"https://api.github.com/users/Pilchie/orgs","repos_url":"https://api.github.com/users/Pilchie/repos","events_url":"https://api.github.com/users/Pilchie/events{/privacy}","received_events_url":"https://api.github.com/users/Pilchie/received_events","type":"User","site_admin":false},"repo":{"id":29272236,"name":"roslyn","full_name":"Pilchie/roslyn","owner":{"login":"Pilchie","id":312835,"avatar_url":"https://avatars.githubusercontent.com/u/312835?v=3","gravatar_id":"","url":"https://api.github.com/users/Pilchie","html_url":"https://github.com/Pilchie","followers_url":"https://api.github.com/users/Pilchie/followers","following_url":"https://api.github.com/users/Pilchie/following{/other_user}","gists_url":"https://api.github.com/users/Pilchie/gists{/gist_id}","starred_url":"https://api.github.com/users/Pilchie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pilchie/subscriptions","organizations_url":"https://api.github.com/users/Pilchie/orgs","repos_url":"https://api.github.com/users/Pilchie/repos","events_url":"https://api.github.com/users/Pilchie/events{/privacy}","received_events_url":"https://api.github.com/users/Pilchie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Pilchie/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":true,"url":"https://api.github.com/repos/Pilchie/roslyn","forks_url":"https://api.github.com/repos/Pilchie/roslyn/forks","keys_url":"https://api.github.com/repos/Pilchie/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Pilchie/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Pilchie/roslyn/teams","hooks_url":"https://api.github.com/repos/Pilchie/roslyn/hooks","issue_events_url":"https://api.github.com/repos/Pilchie/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/Pilchie/roslyn/events","assignees_url":"https://api.github.com/repos/Pilchie/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/Pilchie/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/Pilchie/roslyn/tags","blobs_url":"https://api.github.com/repos/Pilchie/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Pilchie/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Pilchie/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/Pilchie/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Pilchie/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/Pilchie/roslyn/languages","stargazers_url":"https://api.github.com/repos/Pilchie/roslyn/stargazers","contributors_url":"https://api.github.com/repos/Pilchie/roslyn/contributors","subscribers_url":"https://api.github.com/repos/Pilchie/roslyn/subscribers","subscription_url":"https://api.github.com/repos/Pilchie/roslyn/subscription","commits_url":"https://api.github.com/repos/Pilchie/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/Pilchie/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/Pilchie/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/Pilchie/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/Pilchie/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/Pilchie/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Pilchie/roslyn/merges","archive_url":"https://api.github.com/repos/Pilchie/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Pilchie/roslyn/downloads","issues_url":"https://api.github.com/repos/Pilchie/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/Pilchie/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/Pilchie/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/Pilchie/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Pilchie/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/Pilchie/roslyn/releases{/id}","created_at":"2015-01-15T00:05:23Z","updated_at":"2015-01-15T00:06:02Z","pushed_at":"2015-10-27T18:26:08Z","git_url":"git://github.com/Pilchie/roslyn.git","ssh_url":"git@github.com:Pilchie/roslyn.git","clone_url":"https://github.com/Pilchie/roslyn.git","svn_url":"https://github.com/Pilchie/roslyn","homepage":"","size":104016,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dotnet:stabilization","ref":"stabilization","sha":"5bda2d59c57598ec74dea89de2c523c4430809b6","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":29078997,"name":"roslyn","full_name":"dotnet/roslyn","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn","forks_url":"https://api.github.com/repos/dotnet/roslyn/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn/releases{/id}","created_at":"2015-01-11T02:39:03Z","updated_at":"2015-10-27T17:15:05Z","pushed_at":"2015-10-27T18:43:51Z","git_url":"git://github.com/dotnet/roslyn.git","ssh_url":"git@github.com:dotnet/roslyn.git","clone_url":"https://github.com/dotnet/roslyn.git","svn_url":"https://github.com/dotnet/roslyn","homepage":"","size":216585,"stargazers_count":3594,"watchers_count":3594,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":844,"mirror_url":null,"open_issues_count":1538,"forks":844,"open_issues":1538,"watchers":3594,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/6299"},"html":{"href":"https://github.com/dotnet/roslyn/pull/6299"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/6299"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/6299/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/6299/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/6299/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn/statuses/c104073c6c662502de3a90ae5006b885586ec22d"}}}}