“无法在设置文档缓冲区之前设置数据缓冲区”用于IVsTextLines

问题描述

在我的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

解决方法

我将textLines的初始化更改为

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

,然后使用IVsTextBuffer.InitializeContent方法将“文档和数据”文本缓冲区初始化为单个空格字符。之后,我能够成功使用SetBuffer方法。

我还没有完成扩展名的确定,因此我不确定文档缓冲区的内容有多相关。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...