提交 c8c8e4d9 编写于 作者: W Wonseok Chae

Razor/aspx files need updatable during debugging

Move AllowsReadOnly to VsReadOnlyDocumentTracker from VsENCRebuildableProjectImpl, so we can avoid pass a delegate.
上级 a47cdf60
......@@ -24,7 +24,6 @@
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.Venus;
using Microsoft.VisualStudio.LanguageServices.Utilities;
using Roslyn.Utilities;
using Microsoft.VisualStudio.SymReaderInterop;
......@@ -225,7 +224,7 @@ public int StartDebuggingPE()
_encService.StartDebuggingSession(_vsProject.VisualStudioWorkspace.CurrentSolution);
s_encDebuggingSessionInfo = new EncDebuggingSessionInfo();
s_readOnlyDocumentTracker = new VsReadOnlyDocumentTracker(_encService, _editorAdaptersFactoryService, AllowsReadOnly);
s_readOnlyDocumentTracker = new VsReadOnlyDocumentTracker(_encService, _editorAdaptersFactoryService, _vsProject);
}
string outputPath = _vsProject.TryGetObjOutputPath();
......@@ -288,17 +287,6 @@ public int StartDebuggingPE()
}
}
private bool AllowsReadOnly(DocumentId documentId)
{
// All documents of regular running projects are read-only until the debugger breaks the app.
// However, ASP.NET doesnt want its views (aspx, cshtml, or vbhtml) to be read-only, so they can be editable
// while the code is running and get refreshed next time the web page is hit.
// Note that Razor-like views are modelled as a ContainedDocument but normal code including code-behind are modelled as a StandradTextDocument.
var containedDocument = _vsProject.VisualStudioWorkspace.GetHostDocument(documentId) as ContainedDocument;
return containedDocument == null;
}
public int StopDebuggingPE()
{
try
......
......@@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.Venus;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.TextManager.Interop;
......@@ -17,11 +18,11 @@ internal sealed class VsReadOnlyDocumentTracker : ForegroundThreadAffinitizedObj
private readonly IEditAndContinueWorkspaceService _encService;
private readonly IVsEditorAdaptersFactoryService _adapters;
private readonly Workspace _workspace;
private readonly AbstractProject _vsProject;
private bool _isDisposed;
private Func<DocumentId, bool> _allowsReadOnly;
private bool _isDisposed;
public VsReadOnlyDocumentTracker(IEditAndContinueWorkspaceService encService, IVsEditorAdaptersFactoryService adapters, Func<DocumentId, bool> allowsReadOnly)
public VsReadOnlyDocumentTracker(IEditAndContinueWorkspaceService encService, IVsEditorAdaptersFactoryService adapters, AbstractProject vsProject)
: base(assertIsForeground: true)
{
Debug.Assert(encService.DebuggingSession != null);
......@@ -29,7 +30,7 @@ public VsReadOnlyDocumentTracker(IEditAndContinueWorkspaceService encService, IV
_encService = encService;
_adapters = adapters;
_workspace = encService.DebuggingSession.InitialSolution.Workspace;
_allowsReadOnly = allowsReadOnly;
_vsProject = vsProject;
_workspace.DocumentOpened += OnDocumentOpened;
UpdateWorkspaceDocuments();
......@@ -89,10 +90,21 @@ private void SetReadOnly(Document document)
{
SessionReadOnlyReason sessionReason;
ProjectReadOnlyReason projectReason;
SetReadOnly(document.Id, _encService.IsProjectReadOnly(document.Project.Id, out sessionReason, out projectReason));
SetReadOnly(document.Id, _encService.IsProjectReadOnly(document.Project.Id, out sessionReason, out projectReason) && AllowsReadOnly(document.Id));
}
}
private bool AllowsReadOnly(DocumentId documentId)
{
// All documents of regular running projects are read-only until the debugger breaks the app.
// However, ASP.NET doesnt want its views (aspx, cshtml, or vbhtml) to be read-only, so they can be editable
// while the code is running and get refreshed next time the web page is hit.
// Note that Razor-like views are modelled as a ContainedDocument but normal code including code-behind are modelled as a StandradTextDocument.
var containedDocument = _vsProject.VisualStudioWorkspace.GetHostDocument(documentId) as ContainedDocument;
return containedDocument == null;
}
internal void SetReadOnly(DocumentId documentId, bool value)
{
AssertIsForeground();
......@@ -101,7 +113,7 @@ internal void SetReadOnly(DocumentId documentId, bool value)
var textBuffer = GetTextBuffer(_workspace, documentId);
if (textBuffer != null)
{
SetReadOnlyFlag(textBuffer, value && _allowsReadOnly(documentId));
SetReadOnlyFlag(textBuffer, value);
}
}
......
......@@ -6,11 +6,14 @@ Imports Microsoft.CodeAnalysis.Diagnostics
Imports Microsoft.CodeAnalysis.EditAndContinue
Imports Microsoft.CodeAnalysis.Editor.Implementation.EditAndContinue
Imports Microsoft.VisualStudio.Editor
Imports Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
Imports Microsoft.VisualStudio.OLE.Interop
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Editor
Imports Microsoft.VisualStudio.TextManager.Interop
Imports Microsoft.VisualStudio.Utilities
Imports Moq
Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
......@@ -32,11 +35,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
Dim sessionReason As SessionReadOnlyReason
Dim projectReason As ProjectReadOnlyReason
Dim isReadOnly As Boolean
Dim allowsReadOnly As Boolean = True 'It is a StandardTextDocument
' start debugging
encService.StartDebuggingSession(workspace.CurrentSolution)
readOnlyDocumentTracker = New VsReadOnlyDocumentTracker(encService, mockEditorAdaptersFactoryService, allowsReadOnly:=Function(documentId) True)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
readOnlyDocumentTracker = New VsReadOnlyDocumentTracker(encService, mockEditorAdaptersFactoryService, Nothing)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(1, mockVsBuffer._oldFlags) ' Read-Only
......@@ -45,23 +49,24 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
Dim projectStates = ImmutableArray.Create(Of KeyValuePair(Of ProjectId, ProjectReadOnlyReason))(New KeyValuePair(Of ProjectId, ProjectReadOnlyReason)(project.Id, ProjectReadOnlyReason.None))
encService.StartEditSession(currentSolution, activeStatement, projectStates.ToImmutableDictionary(), stoppedAtException:=False)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
' end edit session
encService.EndEditSession()
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(1, mockVsBuffer._oldFlags) ' Read-Only
' break mode and stop at exception
encService.StartEditSession(currentSolution, activeStatement, projectStates.ToImmutableDictionary(), stoppedAtException:=True)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(1, mockVsBuffer._oldFlags) ' Read-Only
End Sub
<WorkItem(1089964, "DevDiv")>
<Fact>
Public Sub ContainedDocumentTest()
Dim diagnosticService As IDiagnosticAnalyzerService = New EditAndContinueTestHelper.TestDiagnosticAnalyzerService()
......@@ -79,11 +84,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
Dim sessionReason As SessionReadOnlyReason
Dim projectReason As ProjectReadOnlyReason
Dim isReadOnly As Boolean
Dim allowsReadOnly As Boolean = False 'It is a ContainedDocument
' start debugging
encService.StartDebuggingSession(workspace.CurrentSolution)
readOnlyDocumentTracker = New VsReadOnlyDocumentTracker(encService, mockEditorAdaptersFactoryService, allowsReadOnly:=Function(documentId) False)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
readOnlyDocumentTracker = New VsReadOnlyDocumentTracker(encService, mockEditorAdaptersFactoryService, Nothing)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
......@@ -92,19 +98,19 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.EditAndContinue
Dim projectStates = ImmutableArray.Create(Of KeyValuePair(Of ProjectId, ProjectReadOnlyReason))(New KeyValuePair(Of ProjectId, ProjectReadOnlyReason)(project.Id, ProjectReadOnlyReason.None))
encService.StartEditSession(currentSolution, activeStatement, projectStates.ToImmutableDictionary(), stoppedAtException:=False)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
' end edit session
encService.EndEditSession()
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
' break mode and stop at exception
encService.StartEditSession(currentSolution, activeStatement, projectStates.ToImmutableDictionary(), stoppedAtException:=True)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason)
isReadOnly = encService.IsProjectReadOnly(project.Id, sessionReason, projectReason) AndAlso allowsReadOnly
readOnlyDocumentTracker.SetReadOnly(project.DocumentIds.First(), isReadOnly)
Assert.Equal(Of UInteger)(0, mockVsBuffer._oldFlags) ' Editable
End Sub
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册