locked
Embed VS 2010 Code editor in a tool window RRS feed

  • Question

  • Hi,

    I have been trying to follow some example found online to embed a VS 2010 code editor to a tool window.

    http://dotneteers.net/blogs/divedeeper/archive/2010/07/28/LearnVSXNow_2D00_Part45.aspx

    The sample opens the tool editor, however I am trying to see how I can restrict the content type to C# and also provided syntax & formatting, so the texts are colored and code is formatted.

    So, i updated the code to something like :

    var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
    _OleServiceProvider = (IOleServiceProvider)GetService(typeof(IOleServiceProvider));
    _BufferFactory = componentModel.GetService<ITextBufferFactoryService>();
    _RegistryService = componentModel.GetService<IContentTypeRegistryService>();
    var vType = _RegistryService.GetContentType("CSharp");
    _EditorAdapterFactory = componentModel.GetService<IVsEditorAdaptersFactoryService>();
    //_BufferAdapter = _EditorAdapterFactory.CreateVsTextBufferAdapter(_OleServiceProvider, _BufferFactory.TextContentType);
    _BufferAdapter = _EditorAdapterFactory.CreateVsTextBufferAdapter(_OleServiceProvider, vType);
    _BufferAdapter.InitializeContent(message, message.Length);
    // Guid csharpLanguageServiceGuid = new Guid("{694DD9B6-B865-4C5B-AD85-86356E9C88DC}");
    //_BufferAdapter.SetLanguageServiceID(ref csharpLanguageServiceGuid);
    _ViewAdapter = _EditorAdapterFactory.CreateVsTextViewAdapter(_OleServiceProvider);
       (IVsWindowPane)_ViewAdapter).SetSite(_OleServiceProvider);

    The above piece of code doesn't seem to work, unless I uncomment the line where I set the Language service ID, then i do see the coloring. But, I don't see any intellisense support.

    I was hoping to embed a code editor to a tool window with full syntax support along with Intellisense. Is this possible? Can someone point me to some example or samples?

    Thanks

    Tuesday, October 23, 2012 9:40 PM

Answers

  • Well it needs to know the language service in order to provide things like colorization. I don't believe you will be able to get Intellisense unless the editor is associated with a file that is associated with an open project. Basically Intellisense needs a reference set of dlls to extract type information from. Without such a set of dlls it wouldn't have anything to 'suggest'.

    If you are fine only opening files that are in the project I have an example of a toolwindow hosted editor that gets full intellisense here:

     https://github.com/ryanmolden/ToolWindowHostedEditorExample

    Ryan


    Thursday, October 25, 2012 1:27 AM