9

Last year I wrote a Language Service for Visual Studio which added syntax highlighting for NHaml files: http://github.com/snappycode/hamleditor.

To clarify, NHaml is a html template language that can mix in code elements like an aspx file can. This plugin adds support to the IDE for editing NHaml files, but basically only adds syntax highlighting.

I was wondering if anyone knows how to add inline c# intellisense to the service like you get now in an aspx file. I'm hoping that would be possible without doing the whole c# grammar myself specific for the plugin.

Has anyone written a language service that mixes languages?

UPDATE: It looks like the spark view engine guys have made some inroads here, I am investigating their implementation

whatupdave
  • 3,124
  • 5
  • 28
  • 32
  • Did you find anything useful when looking at the spark view engine code? – Jake Apr 20 '09 at 19:56
  • Yep, looks like they dropped down to C++ http://whereslou.com/2008/12/03/ivsintellisenseless I'm going to see if I can get this going in c#, but there are some crazy undocumented interfaces to support – whatupdave Apr 27 '09 at 07:16
  • Yeah, downshifting to ATL COM was helpful for getting a handle on the situation because you could trace QueryInterface calls on your objects to gather hints about what expectations VS was having. There's also another nice trick where you take an object reference and call QI for every IID in the registry to discover as many of it's exposed interfaces as you can. I'm not aware of a way to do that type of COM-level exploration in c#. – loudej May 10 '09 at 09:10
  • Will this become any easier in VS2010? From what I read (don't remember source) they put effort in making it easier to create plugins. – Boris Callens Nov 23 '09 at 16:10

4 Answers4

2

I checked the Spark View Engine, and they seem to have made a generic ATL stuff (called SparkLanguagePackageLib), that in fact seems to be not containiag anything Spark specific. It seems to be just a generic C# intellisense library that needs the following:

  • The original code
  • The C# source that gets generated from the original code
  • The position mappings between the two (for example the code on line 2 pos 5 gets mapped in the output to line 4 pos 10, etc.)
  • Some other things, like Paintings(?)

And after that you can call:

events.OnGenerated(
    primaryText, // original source code
    entry.SourceCode, // generated sourcecode
    cMappings, // mappings between the two
    ref mappings[0], // ?
    cPaints, // ?
    ref paints[0]); // ?

I've tried to find Spark-specific stuff in that C++ library, but I couldn't find anything: everythig spark-related is split to a separate C# code file. I think this is good, because:

  • You don't need to edit the C++ files
  • If the spark view engine's intellisense support is installed it can be used by other view engines too
  • You only need to create a class, that maps between the original nhaml file and it's generated C# counterpart.

Btw. Are you still working on this NHaml Intellisense library? If not I'll try to patch their implementation in hope it can be converted to NHaml easily.

SztupY
  • 10,291
  • 8
  • 64
  • 87
  • Any updates on this? has anyone successfully ported the spark class to nhaml ? – Martijn Laarman Jul 09 '09 at 20:33
  • cMapping is the size argument for the mappings array, the ref [0] is address-of-array to interop. Same with cPaints and paints. Mapping is exactly right - it's an array of substring offset pairs for each little window where code in the template show through as code in the generated file. Paint is an array of substring offsets and color types in the original source. That information is used to colorize the rest of the non-code text. To be honest the biggest pain was reworking the parse/gen code to carry forward and capture all of the input/output text offsets. – loudej Jul 10 '09 at 06:13
  • @loudej: Thanks for the clarification! @Martijn: I already managed to rewrite the stuff to NHaml, but unfortunately NHaml is using an alternative parsing/code generation method than Spark, so I have to learn how it works. I don't want to bloat it with too much stuff. – SztupY Jul 10 '09 at 09:49
1

I finally managed to modify the code to support NHaml. It wasn't that hard at all. Unfortunately the original NHaml library doesn't support everything that was needed, so I had to create a new parser for NHaml. It doesn't support all of the constructs, but it supports most of them (enough to make NHaml programming easier)

Download: http://github.com/sztupy/nhamlsense

Screencast: http://www.youtube.com/watch?v=8jTZ2zC9eYc

SztupY
  • 10,291
  • 8
  • 64
  • 87
1

this looks like it might help

http://www.codeproject.com/KB/recipes/VSLanguageService.aspx

Simon
  • 33,714
  • 21
  • 133
  • 202
0

You can easily add keywords by creating or modifying a usertype.dat file. Check here for some directions on attaching to specific file extentions. That might get you at least part of the way, without redoing the complete c# syntax.

(In fact, I'm not sure what you mean exactly by 'syntax highlighting' in this context. I'm sure, for instance, you get brace-match highlighting for free in the editor).

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101
  • The context is he has developed a plugin for Visual Studio that provides syntax highlighting (pretty colours), to provide brace-matching you have to parse the code, and tell visually studio where the brace pair/tupples are. – Simeon Pilgrim Apr 15 '09 at 04:08