{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/comments/94199319","pull_request_review_id":14730383,"id":94199319,"diff_hunk":"@@ -0,0 +1,182 @@\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.IO;\n+using System.Text.RegularExpressions;\n+using System.Threading;\n+using System.Threading.Tasks;\n+using Microsoft.VisualStudio.Editor;\n+using Microsoft.VisualStudio.IO;\n+using Microsoft.VisualStudio.ProjectSystem.VS.Build;\n+using Microsoft.VisualStudio.ProjectSystem.VS.Utilities;\n+using Microsoft.VisualStudio.Shell;\n+using Microsoft.VisualStudio.Shell.Interop;\n+using Microsoft.VisualStudio.Text;\n+using Microsoft.VisualStudio.TextManager.Interop;\n+using Task = System.Threading.Tasks.Task;\n+\n+namespace Microsoft.VisualStudio.ProjectSystem.VS.Editor\n+{\n+    [Export(typeof(ITextBufferManager))]\n+    internal class TempFileTextBufferManager : OnceInitializedOnceDisposedAsync, ITextBufferManager\n+    {\n+        private readonly Regex _whitespaceRegex = new Regex(@\"\\s\");\n+\n+        private readonly UnconfiguredProject _unconfiguredProject;\n+        private readonly IMsBuildAccessor _msbuildAccessor;\n+        private readonly IVsEditorAdaptersFactoryService _editorAdaptersService;\n+        private readonly ITextDocumentFactoryService _textDocumentService;\n+        private readonly IVsShellUtilitiesHelper _shellUtilities;\n+        private readonly IFileSystem _fileSystem;\n+        private readonly IProjectThreadingService _threadingService;\n+        private readonly IServiceProvider _serviceProvider;\n+\n+        private IVsTextBuffer _textBuffer;\n+        private ITextDocument _textDocument;\n+        private IVsPersistDocData _docData;\n+\n+        [ImportingConstructor]\n+        public TempFileTextBufferManager(UnconfiguredProject unconfiguredProject,\n+            IMsBuildAccessor msbuildAccessor,\n+            IVsEditorAdaptersFactoryService editorAdaptersService,\n+            ITextDocumentFactoryService textDocumentService,\n+            IVsShellUtilitiesHelper shellUtilities,\n+            IFileSystem fileSystem,\n+            IProjectThreadingService threadingService,\n+            [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider) :\n+#pragma warning disable IDE0030 // Use null propagation https://github.com/dotnet/roslyn/issues/161\n+            base(threadingService != null ? threadingService.JoinableTaskContext : throw new ArgumentNullException(nameof(threadingService)))\n+#pragma warning restore IDE0030 // Use null propagation\n+        {\n+            Requires.NotNull(unconfiguredProject, nameof(unconfiguredProject));\n+            Requires.NotNull(msbuildAccessor, nameof(msbuildAccessor));\n+            Requires.NotNull(editorAdaptersService, nameof(editorAdaptersService));\n+            Requires.NotNull(textDocumentService, nameof(textDocumentService));\n+            Requires.NotNull(shellUtilities, nameof(shellUtilities));\n+            Requires.NotNull(fileSystem, nameof(fileSystem));\n+            Requires.NotNull(serviceProvider, nameof(serviceProvider));\n+\n+            _unconfiguredProject = unconfiguredProject;\n+            _msbuildAccessor = msbuildAccessor;\n+            _editorAdaptersService = editorAdaptersService;\n+            _textDocumentService = textDocumentService;\n+            _shellUtilities = shellUtilities;\n+            _fileSystem = fileSystem;\n+            _threadingService = threadingService;\n+            _serviceProvider = serviceProvider;\n+        }\n+\n+        public string FilePath { get; set; }\n+\n+        public Task InitializeBufferAsync() => InitializeAsync();\n+\n+        protected override async Task InitializeCoreAsync(CancellationToken cancellationToken)\n+        {\n+            FilePath = GetTempFileName(Path.GetFileName(_unconfiguredProject.FullPath));\n+\n+            var projectXml = await _msbuildAccessor.GetProjectXmlAsync().ConfigureAwait(false);\n+            _fileSystem.WriteAllText(FilePath, projectXml, await _unconfiguredProject.GetFileEncodingAsync().ConfigureAwait(false));\n+        }\n+\n+        protected override Task DisposeCoreAsync(bool initialized)\n+        {\n+            _fileSystem.RemoveDirectory(Path.GetDirectoryName(FilePath), true);\n+            return Task.CompletedTask;\n+        }\n+\n+        public async Task ResetBufferAsync()\n+        {\n+            var projectXml = await _msbuildAccessor.GetProjectXmlAsync().ConfigureAwait(false);\n+\n+            await _threadingService.SwitchToUIThread();\n+\n+            // We compare the text we want to write with the text currently in the buffer, ignoring whitespace. If they're\n+            // the same, then we don't write anything.\n+            var normalizedExistingText = _whitespaceRegex.Replace(await ReadBufferXmlAsync().ConfigureAwait(true), \"\");","path":"src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Editor/TempFileTextBufferManager.cs","position":96,"original_position":96,"commit_id":"97b7dc865a59d48bde63ee250478a8523cc8a8fe","original_commit_id":"97b7dc865a59d48bde63ee250478a8523cc8a8fe","user":{"login":"davkean","id":1103906,"avatar_url":"https://avatars.githubusercontent.com/u/1103906?v=3","gravatar_id":"","url":"https://api.github.com/users/davkean","html_url":"https://github.com/davkean","followers_url":"https://api.github.com/users/davkean/followers","following_url":"https://api.github.com/users/davkean/following{/other_user}","gists_url":"https://api.github.com/users/davkean/gists{/gist_id}","starred_url":"https://api.github.com/users/davkean/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davkean/subscriptions","organizations_url":"https://api.github.com/users/davkean/orgs","repos_url":"https://api.github.com/users/davkean/repos","events_url":"https://api.github.com/users/davkean/events{/privacy}","received_events_url":"https://api.github.com/users/davkean/received_events","type":"User","site_admin":false},"body":"Why do we do all this normalization on the UI thread? This cannot be cheap on large projects.","created_at":"2016-12-30T02:58:36Z","updated_at":"2016-12-30T02:58:36Z","html_url":"https://github.com/dotnet/roslyn-project-system/pull/1027#discussion_r94199319","pull_request_url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/comments/94199319"},"html":{"href":"https://github.com/dotnet/roslyn-project-system/pull/1027#discussion_r94199319"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027","id":99036704,"html_url":"https://github.com/dotnet/roslyn-project-system/pull/1027","diff_url":"https://github.com/dotnet/roslyn-project-system/pull/1027.diff","patch_url":"https://github.com/dotnet/roslyn-project-system/pull/1027.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/1027","number":1027,"state":"open","locked":false,"title":"Editor state machine","user":{"login":"333fred","id":2371880,"avatar_url":"https://avatars.githubusercontent.com/u/2371880?v=3","gravatar_id":"","url":"https://api.github.com/users/333fred","html_url":"https://github.com/333fred","followers_url":"https://api.github.com/users/333fred/followers","following_url":"https://api.github.com/users/333fred/following{/other_user}","gists_url":"https://api.github.com/users/333fred/gists{/gist_id}","starred_url":"https://api.github.com/users/333fred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/333fred/subscriptions","organizations_url":"https://api.github.com/users/333fred/orgs","repos_url":"https://api.github.com/users/333fred/repos","events_url":"https://api.github.com/users/333fred/events{/privacy}","received_events_url":"https://api.github.com/users/333fred/received_events","type":"User","site_admin":false},"body":"This moves the edit project file feature to a proper state machine, and switches us from using the MsBuild ProjectCollection to UnconfiguredProjectAdvanced.ProjectFileChanging to listen to project file updates. I also listen to when the project is being unloaded, and close the editor before the project closes to ensure we can't get into a bad state if the project is reopened in the same session.\r\n\r\nThis fixes a number of bugs: #738, #836, #883, #1015. This also significantly reduces the number of conflict dialogs that appear, especially after saving the editor. The conflict dialog should now only appear when there actually is a conflict. This reduction is a side effect of fixing #738.\r\n\r\nTagging @dotnet/project-system @davkean for review. The functional code is in now, I'll update and add tests tomorrow.","created_at":"2016-12-22T01:58:48Z","updated_at":"2016-12-30T02:58:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5ce720ce829a87d609c4bf172eb61192a10de013","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/1027/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn-project-system/statuses/97b7dc865a59d48bde63ee250478a8523cc8a8fe","head":{"label":"333fred:editor-state-machine","ref":"editor-state-machine","sha":"97b7dc865a59d48bde63ee250478a8523cc8a8fe","user":{"login":"333fred","id":2371880,"avatar_url":"https://avatars.githubusercontent.com/u/2371880?v=3","gravatar_id":"","url":"https://api.github.com/users/333fred","html_url":"https://github.com/333fred","followers_url":"https://api.github.com/users/333fred/followers","following_url":"https://api.github.com/users/333fred/following{/other_user}","gists_url":"https://api.github.com/users/333fred/gists{/gist_id}","starred_url":"https://api.github.com/users/333fred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/333fred/subscriptions","organizations_url":"https://api.github.com/users/333fred/orgs","repos_url":"https://api.github.com/users/333fred/repos","events_url":"https://api.github.com/users/333fred/events{/privacy}","received_events_url":"https://api.github.com/users/333fred/received_events","type":"User","site_admin":false},"repo":{"id":62111220,"name":"roslyn-project-system","full_name":"333fred/roslyn-project-system","owner":{"login":"333fred","id":2371880,"avatar_url":"https://avatars.githubusercontent.com/u/2371880?v=3","gravatar_id":"","url":"https://api.github.com/users/333fred","html_url":"https://github.com/333fred","followers_url":"https://api.github.com/users/333fred/followers","following_url":"https://api.github.com/users/333fred/following{/other_user}","gists_url":"https://api.github.com/users/333fred/gists{/gist_id}","starred_url":"https://api.github.com/users/333fred/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/333fred/subscriptions","organizations_url":"https://api.github.com/users/333fred/orgs","repos_url":"https://api.github.com/users/333fred/repos","events_url":"https://api.github.com/users/333fred/events{/privacy}","received_events_url":"https://api.github.com/users/333fred/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/333fred/roslyn-project-system","description":"The C# and Visual Basic project system for Visual Studio \"15\"","fork":true,"url":"https://api.github.com/repos/333fred/roslyn-project-system","forks_url":"https://api.github.com/repos/333fred/roslyn-project-system/forks","keys_url":"https://api.github.com/repos/333fred/roslyn-project-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/333fred/roslyn-project-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/333fred/roslyn-project-system/teams","hooks_url":"https://api.github.com/repos/333fred/roslyn-project-system/hooks","issue_events_url":"https://api.github.com/repos/333fred/roslyn-project-system/issues/events{/number}","events_url":"https://api.github.com/repos/333fred/roslyn-project-system/events","assignees_url":"https://api.github.com/repos/333fred/roslyn-project-system/assignees{/user}","branches_url":"https://api.github.com/repos/333fred/roslyn-project-system/branches{/branch}","tags_url":"https://api.github.com/repos/333fred/roslyn-project-system/tags","blobs_url":"https://api.github.com/repos/333fred/roslyn-project-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/333fred/roslyn-project-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/333fred/roslyn-project-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/333fred/roslyn-project-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/333fred/roslyn-project-system/statuses/{sha}","languages_url":"https://api.github.com/repos/333fred/roslyn-project-system/languages","stargazers_url":"https://api.github.com/repos/333fred/roslyn-project-system/stargazers","contributors_url":"https://api.github.com/repos/333fred/roslyn-project-system/contributors","subscribers_url":"https://api.github.com/repos/333fred/roslyn-project-system/subscribers","subscription_url":"https://api.github.com/repos/333fred/roslyn-project-system/subscription","commits_url":"https://api.github.com/repos/333fred/roslyn-project-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/333fred/roslyn-project-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/333fred/roslyn-project-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/333fred/roslyn-project-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/333fred/roslyn-project-system/contents/{+path}","compare_url":"https://api.github.com/repos/333fred/roslyn-project-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/333fred/roslyn-project-system/merges","archive_url":"https://api.github.com/repos/333fred/roslyn-project-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/333fred/roslyn-project-system/downloads","issues_url":"https://api.github.com/repos/333fred/roslyn-project-system/issues{/number}","pulls_url":"https://api.github.com/repos/333fred/roslyn-project-system/pulls{/number}","milestones_url":"https://api.github.com/repos/333fred/roslyn-project-system/milestones{/number}","notifications_url":"https://api.github.com/repos/333fred/roslyn-project-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/333fred/roslyn-project-system/labels{/name}","releases_url":"https://api.github.com/repos/333fred/roslyn-project-system/releases{/id}","deployments_url":"https://api.github.com/repos/333fred/roslyn-project-system/deployments","created_at":"2016-06-28T04:56:42Z","updated_at":"2016-10-24T21:57:49Z","pushed_at":"2016-12-29T21:16:08Z","git_url":"git://github.com/333fred/roslyn-project-system.git","ssh_url":"git@github.com:333fred/roslyn-project-system.git","clone_url":"https://github.com/333fred/roslyn-project-system.git","svn_url":"https://github.com/333fred/roslyn-project-system","homepage":null,"size":10239,"stargazers_count":1,"watchers_count":1,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"b04cd8828717638e34f89ad121a26db5b1a4b388","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":56740275,"name":"roslyn-project-system","full_name":"dotnet/roslyn-project-system","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-project-system","description":"The C# and Visual Basic project system for Visual Studio \"15\"","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn-project-system","forks_url":"https://api.github.com/repos/dotnet/roslyn-project-system/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn-project-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn-project-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn-project-system/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn-project-system/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn-project-system/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn-project-system/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn-project-system/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn-project-system/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn-project-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn-project-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn-project-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn-project-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn-project-system/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn-project-system/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn-project-system/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn-project-system/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn-project-system/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn-project-system/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn-project-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn-project-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn-project-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn-project-system/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn-project-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn-project-system/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn-project-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn-project-system/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn-project-system/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn-project-system/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn-project-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn-project-system/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn-project-system/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/roslyn-project-system/deployments","created_at":"2016-04-21T03:40:18Z","updated_at":"2016-12-24T17:17:10Z","pushed_at":"2016-12-30T01:47:35Z","git_url":"git://github.com/dotnet/roslyn-project-system.git","ssh_url":"git@github.com:dotnet/roslyn-project-system.git","clone_url":"https://github.com/dotnet/roslyn-project-system.git","svn_url":"https://github.com/dotnet/roslyn-project-system","homepage":null,"size":10727,"stargazers_count":188,"watchers_count":188,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":336,"forks":52,"open_issues":336,"watchers":188,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027"},"html":{"href":"https://github.com/dotnet/roslyn-project-system/pull/1027"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/1027"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/issues/1027/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/pulls/1027/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn-project-system/statuses/97b7dc865a59d48bde63ee250478a8523cc8a8fe"}}}}
{"actor":{"display_login":"davkean"}}