【问题标题】:"Can't set data buffer before setting document buffer." for IVsTextLines“无法在设置文档缓冲区之前设置数据缓冲区。”对于 IVsTextLines
【发布时间】:2020-08-11 16:16:47
【问题描述】:

在我的 VSIX 项目中,此错误显示在以下行:

(AdapterService as IVsEditorAdaptersFactoryService).SetDataBuffer(textLines, projBuffer as IProjectionBuffer);

textLines 是使用我的包的 CreateInstance 方法创建的

Type textLinesType = typeof(IVsTextLines);
Guid riid = textLinesType.GUID;
Guid clsid = typeof(VsTextBufferClass).GUID;
IVsTextLines textLines = (_package as Package).CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines;

DocumentTextBuffer 属性实际上是什么?如何在新实例化的IVsTextLines 上设置它?
我要做的是创建一个IVsTextLines 将其作为缓冲区传递给IVsCodeWindow

【问题讨论】:

  • 能否请您share a minimal, reproducible example 与我们一起帮助我们解决问题?此外,您可以与我们分享具体错误。
  • @PerryQian-MSFT 我想我已经通过使用IVsEditorAdaptersFactoryService.CreateVsTextBufferAdapter 解决了这个问题,然后调用IVsTextBuffer.InitializeContent。这将初始化 DocumentTextBuffer 和 DataTextBuffer,之后IVsEditorAdaptersFactoryService.SetDataBuffer 不会引发任何错误。我只需要确保它IVsCodeWindow.SetBuffer 可以接受(可能是)。

标签: visual-studio-2019 mef visual-studio-extensions vsix vspackage


【解决方案1】:

我把textLines的初始化改成

textLines = AdapterService.CreateVsTextBufferAdapter(serviceProvider as IOleServiceProvider,
(contentTypeRegistry as IContentTypeRegistryService).GetContentType("csharp")) as IVsTextLines;

然后使用IVsTextBuffer.InitializeContent 方法将文档和数据文本缓冲区初始化为单个空格字符。之后我就可以成功使用SetBuffer 方法了。

我还没有完成我的扩展,所以我不确定 Document Buffer 的内容有多相关。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 2011-07-10
    相关资源
    最近更新 更多