/// <summary> /// Creates the code view. /// </summary> protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines?textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI) { ThreadHelper.ThrowIfNotOnUIThread(); if (_serviceProvider == null) { throw new Exception("ServiceProvider can't be null"); } IVsEditorAdaptersFactoryService adapterService = VS.GetMefService <IVsEditorAdaptersFactoryService>(); IVsCodeWindow window = adapterService.CreateVsCodeWindowAdapter((IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider))); ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines)); ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null)); ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption)); if (textLines is IVsUserData userData) { if (PromptEncodingOnLoad) { Guid guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid; userData.SetData(ref guid, (uint)1); } } cmdUI = VSConstants.GUID_TextEditorFactory; if (!createdDocData && textLines != null) { // we have a pre-created buffer, go ahead and initialize now as the buffer already // exists and is initialized TextBufferEventListener?bufferEventListener = new(textLines, _languageServiceId); bufferEventListener.OnLoadCompleted(0); } return(window); }