未验证 提交 6801607c 编写于 作者: I Ivan Basov 提交者: GitHub

set content type for AbstractDebuggerIntelliSenseContext to the original content type (#30679)

上级 9046f1ed
......@@ -25,6 +25,7 @@ internal abstract class AbstractDebuggerIntelliSenseContext : IDisposable
{
private readonly IWpfTextView _textView;
private readonly IContentType _contentType;
private readonly IContentType _originalContentType;
protected readonly IProjectionBufferFactoryService ProjectionBufferFactoryService;
protected readonly Microsoft.VisualStudio.TextManager.Interop.TextSpan CurrentStatementSpan;
private readonly IVsTextLines _debuggerTextLines;
......@@ -58,6 +59,7 @@ private class ImmediateWindowContext
this.ContextBuffer = contextBuffer;
this.CurrentStatementSpan = currentStatementSpan[0];
_contentType = contentType;
_originalContentType = _textView.TextBuffer.ContentType;
this.ProjectionBufferFactoryService = componentModel.GetService<IProjectionBufferFactoryService>();
_bufferGraphFactoryService = componentModel.GetService<IBufferGraphFactoryService>();
_isImmediateWindow = IsImmediateWindow((IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)), vsTextView);
......@@ -200,6 +202,12 @@ internal bool TryInitialize()
return true;
}
internal void SetContentType(bool install)
{
var contentType = install ? _contentType :_originalContentType;
_textView.TextBuffer.ChangeContentType(contentType, null);
}
private ITrackingSpan CreateImmediateWindowProjectionMapping(Document document, out ImmediateWindowContext immediateWindowContext)
{
var caretLine = _textView.Caret.ContainingTextViewLine.Extent;
......
......@@ -194,6 +194,9 @@ internal void RemoveContext()
_context = null;
}
internal void SetContentType(bool install)
=> _context?.SetContentType(install);
public void Dispose()
{
if (_context != null)
......
......@@ -40,12 +40,7 @@ int IVsImmediateStatementCompletion2.InstallStatementCompletion(int install, IVs
if (install != 0)
{
DebuggerIntelliSenseFilter<TPackage, TLanguageService> filter;
if (this.filters.ContainsKey(textView))
{
// We already have a filter in this textview. Return.
return VSConstants.S_OK;
}
else
if (!this.filters.ContainsKey(textView))
{
filter = new DebuggerIntelliSenseFilter<TPackage, TLanguageService>(this,
this.EditorAdaptersFactoryService.GetWpfTextView(textView),
......@@ -55,10 +50,13 @@ int IVsImmediateStatementCompletion2.InstallStatementCompletion(int install, IVs
Marshal.ThrowExceptionForHR(textView.AddCommandFilter(filter, out var nextFilter));
filter.SetNextFilter(nextFilter);
}
this.filters[textView].SetContentType(install: true);
}
else
{
Marshal.ThrowExceptionForHR(textView.RemoveCommandFilter(this.filters[textView]));
this.filters[textView].SetContentType(install: false);
this.filters[textView].Dispose();
this.filters.Remove(textView);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册