Пример #1
0
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid           = codeWindowType.GUID;
            Guid clsid          = typeof(VsCodeWindowClass).GUID;
            var  compModel      = _package.AsVsServiceProvider().GetComponentModel();
            var  adapterService = compModel.GetService <IVsEditorAdaptersFactoryService>();

            var window = adapterService.CreateVsCodeWindowAdapter(_serviceProvider.TryGetOleServiceProvider());

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                if (_promptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;
            return(window);
        }
Пример #2
0
        public override IScanner GetScanner(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines buffer)
        {
            if (scanner == null)
            {
                scanner = new RefalScanner();
            }

            return(scanner);
        }
            public TextBufferEventListener(IComponentModel componentModel, IVsTextLines textLines)
            {
                this._componentModel = componentModel;
                this._textLines      = textLines;

                var connectionPointContainer = textLines as IConnectionPointContainer;
                var bufferEventsGuid         = typeof(IVsTextBufferDataEvents).GUID;

                connectionPointContainer.FindConnectionPoint(ref bufferEventsGuid, out _connectionPoint);
                _connectionPoint.Advise(this, out _cookie);
            }
            public TextBufferEventListener(IComponentModel compModel, IVsTextLines textLines, IVsTextManager textMgr, IVsCodeWindow window)
            {
                _textLines = textLines;
                _compModel = compModel;
                _textMgr = textMgr;
                _window = window;

                var cpc = textLines as IConnectionPointContainer;
                var bufferEventsGuid = typeof(IVsTextBufferDataEvents).GUID;
                cpc.FindConnectionPoint(ref bufferEventsGuid, out _cp);
                _cp.Advise(this, out _cookie);
            }
            public TextBufferEventListener(IComponentModel componentModel, IVsTextLines textLines, Guid languageServiceId)
            {
                _componentModel    = componentModel;
                _textLines         = textLines;
                _languageServiceId = languageServiceId;

                var connectionPointContainer = textLines as IConnectionPointContainer;
                var bufferEventsGuid         = typeof(IVsTextBufferDataEvents).GUID;

                connectionPointContainer.FindConnectionPoint(ref bufferEventsGuid, out _connectionPoint);
                _connectionPoint.Advise(this, out _cookie);
            }
Пример #6
0
            public TextBufferEventListener(IComponentModel compModel, IVsTextLines textLines, IVsTextManager textMgr, IVsCodeWindow window)
            {
                _textLines = textLines;
                _compModel = compModel;
                _textMgr   = textMgr;
                _window    = window;

                var cpc = textLines as IConnectionPointContainer;
                var bufferEventsGuid = typeof(IVsTextBufferDataEvents).GUID;

                cpc.FindConnectionPoint(ref bufferEventsGuid, out _cp);
                _cp.Advise(this, out _cookie);
            }
        public int GetCurrentBlock(
            IVsTextLines pTextLines,
            int iCurrentLine,
            int iCurrentChar,
            VsTextSpan[] ptsBlockSpan,
            out string pbstrDescription,
            out int pfBlockAvailable
            )
        {
            var snapshot =
                this.EditorAdaptersFactoryService.GetDataBuffer(pTextLines).CurrentSnapshot;
            var position = snapshot?.TryGetPosition(iCurrentLine, iCurrentChar);

            if (position == null)
            {
                pbstrDescription = null;
                pfBlockAvailable = 0;
                return(VSConstants.S_OK);
            }

            (string description, TextSpan span)? foundBlock = null;

            var waitIndicator = this.Package.ComponentModel.GetService <IWaitIndicator>();

            waitIndicator.Wait(
                ServicesVSResources.Current_block,
                ServicesVSResources.Determining_current_block,
                allowCancel: true,
                action: context =>
            {
                foundBlock = VsLanguageBlock.GetCurrentBlock(
                    snapshot,
                    position.Value,
                    context.CancellationToken
                    );
            }
                );

            pfBlockAvailable = foundBlock != null ? 1 : 0;
            pbstrDescription = foundBlock?.description;

            if (foundBlock != null && ptsBlockSpan != null && ptsBlockSpan.Length >= 1)
            {
                ptsBlockSpan[0] = foundBlock.Value.span.ToSnapshotSpan(snapshot).ToVsTextSpan();
            }

            return(VSConstants.S_OK);
        }
        protected override IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            IVsCodeWindow window = base.CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI);

            var compModel = Package.AsVsServiceProvider().GetComponentModel();
            var textMgr = Package.AsVsServiceProvider().GetTextManager();
            var bufferEventListener = new TextBufferEventListener(compModel, textLines, textMgr, window);
            if (!createdDocData)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized.
                bufferEventListener.OnLoadCompleted(0);
            }

            return window;
        }
Пример #9
0
        protected override IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            IVsCodeWindow window = base.CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI);

            var compModel           = Package.AsVsServiceProvider().GetComponentModel();
            var textMgr             = Package.AsVsServiceProvider().GetTextManager();
            var bufferEventListener = new TextBufferEventListener(compModel, textLines, textMgr, window);

            if (!createdDocData)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized.
                bufferEventListener.OnLoadCompleted(0);
            }

            return(window);
        }
Пример #10
0
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid           = codeWindowType.GUID;
            Guid clsid          = typeof(VsCodeWindowClass).GUID;
            var  compModel      = (IComponentModel) new VsServiceProviderWrapper(_package).GetService(typeof(SComponentModel));
            IVsEditorAdaptersFactoryService adapterService = compModel.GetService <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;

            var componentModel      = (IComponentModel) new VsServiceProviderWrapper(Package).GetService(typeof(SComponentModel));
            var bufferEventListener = new TextBufferEventListener(componentModel, textLines, _languageServiceId);

            if (!createdDocData)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized
                bufferEventListener.OnLoadCompleted(0);
            }

            return(window);
        }
Пример #11
0
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid = codeWindowType.GUID;
            Guid clsid = typeof(VsCodeWindowClass).GUID;
            var compModel = _package.AsVsServiceProvider().GetComponentModel();
            var adapterService = compModel.GetService<IVsEditorAdaptersFactoryService>();

            var window = adapterService.CreateVsCodeWindowAdapter(_serviceProvider.TryGetOleServiceProvider());
            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            IVsUserData userData = textLines as IVsUserData;
            if (userData != null)
            {
                if (_promptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;
            return window;
        }
Пример #12
0
        protected virtual object CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI)
        {
            //Init out params
            editorCaption = string.Empty;
            cmdUI         = Guid.Empty;

            if (string.IsNullOrEmpty(physicalView))
            {
                // create code window as default physical view
                return(CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI));
            }

            // We couldn't create the view
            // Return special error code so VS can try another editor factory.
            throw Marshal.GetExceptionForHR(VSConstants.VS_E_UNSUPPORTEDFORMAT);
        }
Пример #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="grfCreateDoc"></param>
        /// <param name="pszMkDocument"></param>
        /// <param name="pszPhysicalView"></param>
        /// <param name="pvHier"></param>
        /// <param name="itemid"></param>
        /// <param name="punkDocDataExisting"></param>
        /// <param name="ppunkDocView"></param>
        /// <param name="ppunkDocData"></param>
        /// <param name="pbstrEditorCaption"></param>
        /// <param name="pguidCmdUI"></param>
        /// <param name="pgrfCDW"></param>
        /// <returns></returns>
        public virtual int CreateEditorInstance(
            uint createEditorFlags,
            string documentMoniker,
            string physicalView,
            IVsHierarchy hierarchy,
            uint itemid,
            IntPtr docDataExisting,
            out IntPtr docView,
            out IntPtr docData,
            out string editorCaption,
            out Guid commandUIGuid,
            out int createDocumentWindowFlags)
        {
            // Initialize output parameters
            docView                   = IntPtr.Zero;
            docData                   = IntPtr.Zero;
            commandUIGuid             = Guid.Empty;
            createDocumentWindowFlags = 0;
            editorCaption             = null;

            // Validate inputs
            if ((createEditorFlags & (uint)(VSConstants.CEF.OpenFile | VSConstants.CEF.Silent)) == 0)
            {
                return(VSConstants.E_INVALIDARG);
            }

            if (docDataExisting != IntPtr.Zero && _promptEncodingOnLoad)
            {
                return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
            }

            // Get a text buffer
            IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker);

            // Assign docData IntPtr to either existing docData or the new text buffer
            if (docDataExisting != IntPtr.Zero)
            {
                docData = docDataExisting;
                Marshal.AddRef(docData);
            }
            else
            {
                docData = Marshal.GetIUnknownForObject(textLines);
            }

            try
            {
                object docViewObject = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid);
                docView = Marshal.GetIUnknownForObject(docViewObject);
            }
            finally
            {
                if (docView == IntPtr.Zero)
                {
                    if (docDataExisting != docData && docData != IntPtr.Zero)
                    {
                        // Cleanup the instance of the docData that we have addref'ed
                        Marshal.Release(docData);
                        docData = IntPtr.Zero;
                    }
                }
            }
            return(VSConstants.S_OK);
        }
Пример #14
0
            public TextBufferEventListener(IComponentModel componentModel, IVsTextLines textLines)
            {
                this._componentModel = componentModel;
                this._textLines = textLines;

                var connectionPointContainer = textLines as IConnectionPointContainer;
                var bufferEventsGuid = typeof(IVsTextBufferDataEvents).GUID;
                connectionPointContainer.FindConnectionPoint(ref bufferEventsGuid, out _connectionPoint);
                _connectionPoint.Advise(this, out _cookie);
            }
Пример #15
0
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid = codeWindowType.GUID;
            Guid clsid = typeof(VsCodeWindowClass).GUID;
            var compModel = (IComponentModel)new VsServiceProviderWrapper(_package).GetService(typeof(SComponentModel));
            var adapterService = compModel.GetService<IVsEditorAdaptersFactoryService>();

            var 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));

            IVsUserData userData = textLines as IVsUserData;
            if (userData != null)
            {
                if (_promptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;

            var componentModel = (IComponentModel)new VsServiceProviderWrapper(Package).GetService(typeof(SComponentModel));
            var bufferEventListener = new TextBufferEventListener(componentModel, textLines);
            if (!createdDocData)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized
                bufferEventListener.OnLoadCompleted(0);
            }

            return window;
        }
Пример #16
0
        protected virtual object CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI)
        {
            //Init out params
            editorCaption = string.Empty;
            cmdUI = Guid.Empty;

            if (string.IsNullOrEmpty(physicalView))
            {
                // create code window as default physical view
                return CreateCodeView(documentMoniker, textLines, createdDocData, ref editorCaption, ref cmdUI);
            }

            // We couldn't create the view
            // Return special error code so VS can try another editor factory.
            throw Marshal.GetExceptionForHR(VSConstants.VS_E_UNSUPPORTEDFORMAT);
        }
Пример #17
0
 int IVsDebugger.GetDataTipValue(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines pTextBuf, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] pTS, string pszExpression, out string pbstrValue)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #18
0
 public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer)
 {
     ppColorizer = null;
     return(VSConstants.E_FAIL);
 }
Пример #19
0
 public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer)
 {
     ppColorizer = null;
     return VSConstants.E_FAIL;
 }