Visual Studio 2010 Extensions

2019-04-13 04:40发布

问题:

I'm writing my own abstract extension for Visual Studio 2010, it makes similary functionality as Ook Language Integration.

I have a question, is it possibly to mix my own AutoCompletion with standart C++ autocompletion of VS? How to do it? Is in need to use libraries of VS and call some methods?

回答1:

This is a very good example about adding features to C# intellisense.

First of all you should capture the completionSession and use it.

Like this snippet, but in C++

    [Export(typeof(IIntellisensePresenterProvider))]
    [ContentType("text")]
    [Order(Before = "Default Completion Presenter")]
    [Name("Object Intellisense Presenter")]
    internal class IntellisensePresenterProvider : IIntellisensePresenterProvider
    {
        [Import(typeof(SVsServiceProvider))]
        IServiceProvider ServiceProvider { get; set; }

        #region Try Create Intellisense Presenter

        #region Documentation
        /// <summary>
        /// Inject the IntelliSense presenter
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        #endregion // Documentation
        public IIntellisensePresenter TryCreateIntellisensePresenter(IIntellisenseSession session)
        {
            #region Validation (is C#)

            const string CSHARP_CONTENT = "CSharp";
            if (session.TextView.TextBuffer.ContentType.TypeName != CSHARP_CONTENT)
            {
                return null;
            }

            #endregion // Validation

            ICompletionSession completionSession = session as ICompletionSession;
            if (completionSession != null)
            {
                var presenter = new IntelliSenseViewModel(ServiceProvider, completionSession);
                return presenter;
            }
            return null;
        }

        #endregion // Try Create Intellisense Presenter
    }

Hope helps!