提交 13a68a82 编写于 作者: S Sam Harwell

IsCompletionActive returns false when no text view is active

上级 d61a6352
......@@ -52,31 +52,47 @@ private Editor_InProc()
public static Editor_InProc Create()
=> new Editor_InProc();
protected override bool HasActiveTextView()
=> ErrorHandler.Succeeded(TryGetActiveTextViewHost().hr);
protected override IWpfTextView GetActiveTextView()
=> GetActiveTextViewHost().TextView;
private static IVsTextView GetActiveVsTextView()
{
var vsTextManager = GetGlobalService<SVsTextManager, IVsTextManager>();
var (textView, hr) = TryGetActiveVsTextView();
Marshal.ThrowExceptionForHR(hr);
return textView;
}
private static (IVsTextView textView, int hr) TryGetActiveVsTextView()
{
var vsTextManager = GetGlobalService<SVsTextManager, IVsTextManager>();
var hresult = vsTextManager.GetActiveView(fMustHaveFocus: 1, pBuffer: null, ppView: out var vsTextView);
Marshal.ThrowExceptionForHR(hresult);
return vsTextView;
return (vsTextView, hresult);
}
private static IWpfTextViewHost GetActiveTextViewHost()
{
var (textViewHost, hr) = TryGetActiveTextViewHost();
Marshal.ThrowExceptionForHR(hr);
return textViewHost;
}
private static (IWpfTextViewHost textViewHost, int hr) TryGetActiveTextViewHost()
{
// The active text view might not have finished composing yet, waiting for the application to 'idle'
// means that it is done pumping messages (including WM_PAINT) and the window should return the correct text view
WaitForApplicationIdle(Helper.HangMitigatingTimeout);
var activeVsTextView = (IVsUserData)GetActiveVsTextView();
var hresult = activeVsTextView.GetData(IWpfTextViewId, out var wpfTextViewHost);
Marshal.ThrowExceptionForHR(hresult);
var (activeVsTextView, hr) = TryGetActiveVsTextView();
if (!ErrorHandler.Succeeded(hr))
{
return (null, hr);
}
return (IWpfTextViewHost)wpfTextViewHost;
var hresult = ((IVsUserData)activeVsTextView).GetData(IWpfTextViewId, out var wpfTextViewHost);
return ((IWpfTextViewHost)wpfTextViewHost, hresult);
}
public bool IsUseSuggestionModeOn()
......
......@@ -61,6 +61,9 @@ public bool IsInitializing
public string GetReplText()
=> _interactiveWindow.TextView.TextBuffer.CurrentSnapshot.GetText();
protected override bool HasActiveTextView()
=> _interactiveWindow.TextView is object;
protected override IWpfTextView GetActiveTextView()
=> _interactiveWindow.TextView;
......
......@@ -94,11 +94,18 @@ public void WaitForLightBulbSession()
/// querying the editor
/// </remarks>
public bool IsCompletionActive()
=> ExecuteOnActiveView(view =>
{
if (!HasActiveTextView())
{
return false;
}
return ExecuteOnActiveView(view =>
{
var broker = GetComponentModelService<ICompletionBroker>();
return broker.IsCompletionActive(view);
});
}
protected abstract ITextBuffer GetBufferContainingCaret(IWpfTextView view);
......@@ -478,6 +485,8 @@ public void DismissLightBulbSession()
broker.DismissSession(view);
});
protected abstract bool HasActiveTextView();
protected abstract IWpfTextView GetActiveTextView();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册