locked
Using Custom editor for Custom Language when not backed by files RRS feed

  • Question

  • I'm keen to leverage the power of VSX even further now. I have a DSL editor which is hosted in an isolated shell.For elements of that DSL I have text that is a custom programming language. Ideally I'd like to provide syntax highlighting etc. Currently, that text is just string properties on domain elements. I can get the hook to start a custom editor for that property. But rather than provide my own control and maybe use something like Scintilla or ActiPro for the highlighting and brace matching, it seems sensible to use a Visual Studio editor :)

    It seems straightforward enough to create a custom editor (thanks for the new project type). But what I want is to be able to create an editor when someone edits the property. At the moment it looks like the 'simplest' way is going to be save the content of that property to a temp file with the right extension and then ask visual studio to open it. But that seems just a little convoluted. I did find mention in a forum from 2005 about a sample in the sdk for an editor service that provides a new logical view and uses a textbuffer of an existing document for the docdata, which is similar to what I'm after. Is there a 2010 sample for such a docdata. Or maybe even a better way in the new MEF world.

    In summary: parts of my doc are string properties. These strings are  a custom language. I'd like to use the visual studio editor to provide highlighting and brace matching when editing these strings. Can I do this without saving things to temporary files, presumably by writing a language service with a scanner and lexer.

     

    Thanks.

     

    Wednesday, January 5, 2011 2:48 PM

Answers

  • Hi Joeul,

    If your using VS 2010, I'd recommend reviewing the RegEx Editor sample (you can download the code on the "Source Code" page).

    This sample should provide you with some guidance. The interesting part (for me) was how they associated the text buffer with the regex content type (see RegexEditorService.ShowEditor for the details). The CreateTextBuffer call allows you to associated a content type with the buffer, which appears to be the key to providing colorization/intellisense for the editor that is ultimately displayed in the RegExEditorDialog.

    Sincerely,


    Ed Dore
    Tuesday, January 11, 2011 5:35 PM