This project is read-only.

Hosting interface and multiple-file source

Nov 11, 2009 at 6:58 AM

Hi, I have a situation that I have my source in multiple files (such as include files). These files are preprocessed into a single script file. In order to inject debug info, I need to pass some mapping between my source code and the merged code to my compiler. I use ScriptEngine.CreateScriptSource method to pass my source code to the hosting interface. I could subclass the TextContentProvider to pass my mapping information. On the other end, I subclass LanguageContext and override the CompileSourceCode method. As far as I can see, the SourceUnit does carry the TextContentProvider. However, SourceUnit is a sealed class and only exposes the Reader of TextContentProvider through the GetReader() method. As a result, I am not able to retrieve whatever mapping information that I added to the TextContentProvider subclass. Is there a way around this problem? Thanks.

Nov 11, 2009 at 6:28 PM

We have some basic line mapping on ScriptSource but it's missing support for multiple file debug info (it only stores a line to line mapping). Also the languages currently ignore this mapping. We should, however, fix this in future versions.

Do you implement your own language? If so a workround would be to add some public method taking the mapping on your LanguageContext implementation. The host can then bypass the default source unit compilation code path - retrieve the context from a ScriptEngine by calling HostingHelpers.GetLanguageContext and call the method directly. If you want more clean design that also works with remoting you can implement a service (see ScriptEngine.GetService<T>).