harsimranb / monodevelop

MonoDevelop is a cross platform IDE mostly aimed at Mono/.NET developers

Home Page:http://www.monodevelop.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inline JavaScript

harsimranb opened this issue · comments

We need to also support JavaScript inside an inline < script / > block.

Michael, any pointers on how I should go about this? We probably want to ad code completion, code folding, errors, code snippets, document highlighting?, and code formatting inside html and cshtml files.

This one is definitely not easy as we don't have a standard system for handling languages embedded inside documents written in other languages.

Syntax highlighting is the easy one, you've seen how the HTML addin does that already.

Beyond that, I think the JS addin would need to provide an API for handling sections of JS inside a larger document, and you'd have to alter the handling of the languages that embed JS (HTML, Razor, ASPX) to use this API to handle JS.

e.g.

public static class EmbeddedJavaScriptHandler
{
    // HTML parser uses this to parse body of <script> tags
    public static JavaScriptFragment Parse (TextReader reader, int start, int length);
    // HTML ParsedDocument uses this to generate foldings within <script> tags
    public static IEnumerable<FoldingRegion> GenerateFoldings (JavaScriptFragment fragment);
    // HTML TextEditorExtension uses this to generate outline children for <script> tags
    public static void GenerateOutline (JavaScriptFragment fragment, Gtk.TreeStore store, Gtk.TreeIter parent);
    // HTML TextEditorExtension uses this to generate completions within <script> tags
    public static CompletionDataList HandleCompletion (IEnumerable<JavaScriptImports> imports, IEnumerable<JavaScriptFragment> documentFragments, TextEditorData editor, int offset);
    // etc ...
}

Obviously you could do this incrementally, e.g. start with a proof of concept that just adds folding support, then work your way down the other features.

TBH I would put this on hold until you have all the basics working well for JS files.

I agree. I also like the POC.
I'll move this to Polishing Release for now.

@mhutch my idea for the embedded scanning was to do something similar to R#, not sure if its achievable though.

Basically, the inline </script> tag would provide auto-completion members based on the files referenced in <script src=''/>. I'm assuming something like this would require changes to the original add-ins. I guess once we get to this stage, we'll experiment on the simple HTML files first.

Yeah, the idea with HandleCompletion is that the IEnumerable<JavaScriptImports> would be the URLs from <script src=.../> tags and the IEnumerable<JavaScriptFragment> would be the parsed JS regions from the current file, so the completion engine could complete symbols from them.

Nice. That will make things very easy.