1

In my VSIX project this error is shown on the line:

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

where textLines is created using CreateInstance method of my package

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;

What actually is DocumentTextBuffer property and how do I set it on a newly instantiated IVsTextLines?
What I am trying to do is create a IVsTextLines to pass it as a buffer to IVsCodeWindow.

Savo Pejović
  • 133
  • 1
  • 9
  • Could you please [share a minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with us to help us troubleshoot the issue? Besides, you can share the specific error with us. – Mr Qian Aug 12 '20 at 09:22
  • @PerryQian-MSFT I think I've solved this by using `IVsEditorAdaptersFactoryService.CreateVsTextBufferAdapter`, and then calling `IVsTextBuffer.InitializeContent`. This initializes both the DocumentTextBuffer and DataTextBuffer, after which `IVsEditorAdaptersFactoryService.SetDataBuffer` throws no errors. I just need to make sure it `IVsCodeWindow.SetBuffer` is ok with it (probably is). – Savo Pejović Aug 12 '20 at 09:46

1 Answers1

2

I changed the initialization of textLines to

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

and then have used the IVsTextBuffer.InitializeContent method to initialize the Document and Data text buffer to a single space character. After that I was able to successfully use the SetBuffer method.

I am still haven't finalized my extension, so I am not sure how relevant Document Buffer's content is.

Savo Pejović
  • 133
  • 1
  • 9