提交 fed49cfd 编写于 作者: T Tomas Matousek

Make immediate window buffer writable before applying completion edit

上级 11e5b433
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.VisualStudio.Language.Intellisense; using Microsoft.VisualStudio.Language.Intellisense;
namespace Microsoft.CodeAnalysis.Editor namespace Microsoft.CodeAnalysis.Editor
...@@ -9,5 +10,8 @@ internal interface IDebuggerTextView ...@@ -9,5 +10,8 @@ internal interface IDebuggerTextView
bool IsImmediateWindow { get; } bool IsImmediateWindow { get; }
void HACK_StartCompletionSession(IIntellisenseSession editorSessionOpt); void HACK_StartCompletionSession(IIntellisenseSession editorSessionOpt);
uint StartBufferUpdate();
void EndBufferUpdate(uint cookie);
} }
} }
...@@ -114,6 +114,16 @@ private CompletionProvider GetCompletionProvider(CompletionItem item) ...@@ -114,6 +114,16 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
var adjustedNewText = AdjustForVirtualSpace(textChange); var adjustedNewText = AdjustForVirtualSpace(textChange);
var editOptions = GetEditOptions(mappedSpan, adjustedNewText); var editOptions = GetEditOptions(mappedSpan, adjustedNewText);
// The immediate window is always marked read-only and the language service is
// responsible for asking the buffer to make itself writable. We'll have to do that for
// commit, so we need to drag the IVsTextLines around, too.
// We have to ask the buffer to make itself writable, if it isn't already
uint immediateWindowBufferUpdateCookie = 0;
if (_isImmediateWindow)
{
immediateWindowBufferUpdateCookie = ((IDebuggerTextView)TextView).StartBufferUpdate();
}
// Now actually make the text change to the document. // Now actually make the text change to the document.
using (var textEdit = this.SubjectBuffer.CreateEdit(editOptions, reiteratedVersionNumber: null, editTag: null)) using (var textEdit = this.SubjectBuffer.CreateEdit(editOptions, reiteratedVersionNumber: null, editTag: null))
{ {
...@@ -121,6 +131,11 @@ private CompletionProvider GetCompletionProvider(CompletionItem item) ...@@ -121,6 +131,11 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
textEdit.ApplyAndLogExceptions(); textEdit.ApplyAndLogExceptions();
} }
if (_isImmediateWindow)
{
((IDebuggerTextView)TextView).EndBufferUpdate(immediateWindowBufferUpdateCookie);
}
// If the completion change requested a new position for the caret to go, // If the completion change requested a new position for the caret to go,
// then set the caret to go directly to that point. // then set the caret to go directly to that point.
if (completionChange.NewPosition.HasValue) if (completionChange.NewPosition.HasValue)
......
...@@ -195,7 +195,7 @@ internal bool TryInitialize() ...@@ -195,7 +195,7 @@ internal bool TryInitialize()
var bufferGraph = _bufferGraphFactoryService.CreateBufferGraph(_projectionBuffer); var bufferGraph = _bufferGraphFactoryService.CreateBufferGraph(_projectionBuffer);
_debuggerTextView = new DebuggerTextView(_textView, bufferGraph, this.InImmediateWindow); _debuggerTextView = new DebuggerTextView(_textView, bufferGraph, _debuggerTextLines, InImmediateWindow);
return true; return true;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
using Microsoft.VisualStudio.Text.Formatting; using Microsoft.VisualStudio.Text.Formatting;
using Microsoft.VisualStudio.Text.Outlining; using Microsoft.VisualStudio.Text.Outlining;
using Microsoft.VisualStudio.Text.Projection; using Microsoft.VisualStudio.Text.Projection;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities; using Microsoft.VisualStudio.Utilities;
using Roslyn.Utilities; using Roslyn.Utilities;
...@@ -23,15 +24,18 @@ internal partial class DebuggerTextView : IWpfTextView, IDebuggerTextView ...@@ -23,15 +24,18 @@ internal partial class DebuggerTextView : IWpfTextView, IDebuggerTextView
/// The actual debugger view of the watch or immediate window that we're wrapping /// The actual debugger view of the watch or immediate window that we're wrapping
/// </summary> /// </summary>
private readonly IWpfTextView _innerTextView; private readonly IWpfTextView _innerTextView;
private readonly IVsTextLines _debuggerTextLines;
public DebuggerTextView( public DebuggerTextView(
IWpfTextView innerTextView, IWpfTextView innerTextView,
IBufferGraph bufferGraph, IBufferGraph bufferGraph,
IVsTextLines debuggerTextLines,
bool isImmediateWindow) bool isImmediateWindow)
{ {
_innerTextView = innerTextView; _innerTextView = innerTextView;
this.BufferGraph = bufferGraph; _debuggerTextLines = debuggerTextLines;
this.IsImmediateWindow = isImmediateWindow; BufferGraph = bufferGraph;
IsImmediateWindow = isImmediateWindow;
} }
/// <summary> /// <summary>
...@@ -60,6 +64,19 @@ public bool IsImmediateWindow ...@@ -60,6 +64,19 @@ public bool IsImmediateWindow
get; get;
} }
public uint StartBufferUpdate()
{
_debuggerTextLines.GetStateFlags(out var bufferFlags);
_debuggerTextLines.SetStateFlags((uint)((BUFFERSTATEFLAGS)bufferFlags & ~BUFFERSTATEFLAGS.BSF_USER_READONLY));
return bufferFlags;
}
public void EndBufferUpdate(uint cookie)
{
_debuggerTextLines.SetStateFlags(cookie);
}
public ITextCaret Caret public ITextCaret Caret
{ {
get { return _innerTextView.Caret; } get { return _innerTextView.Caret; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册