T4Toolbox
T4Toolbox copied to clipboard
T4 Text-Templates with IntelliSense
please work on IntelliSense.
Sure, I'll get right on it! :smile:
IntelliSense for T4 templates is a very large area, it would help if you could elaborate on what would be the most important in your usage of T4. Allow me to provide some background.
When I think of IntelliSense for T4 templates, I tend to separate the following two areas:
- IntelliSense for the T4 syntax
- IntelliSense for code blocks.
IntelliSense for the T4 syntax is implemented in the T4Toolbox itself, which includes a template scanner used for syntax colorization and a template parser used for quick info tooltips, outlining, error underlining in editor, error reporting in error list window and completion lists. While syntax colorization and error reporting for template display work OK, I think it's fair to say that support for template editing needs a lot of improvement. I suspect the template parser is too "strict" which prevents creation of completion lists when you are in the process of typing a line. For instance, when you stop typing <#@
, I'd expect to see a completion list names of the directives, however this list appears only when you have text caret in the middle of <#@ #>
.
IntelliSense for the code blocks was simply never implemented. In Visual Studio 2013, Roslyn was not available and re-implementing C# and VB IntelliSense was not feasible. In Visual Studio 2015, Roslyn is in the box and all options are open. One of the options is projection buffers which are used by the Visual Studio HTML editor for Razor and WebForms code blocks. I think Web Essentials for Visual Studio 2015 takes advantage of this capability to implement IntelliSense for code snippets in markdown, which could be used as an example for code blocks in T4 templates.
One thought which crossed my mind could an all-or-nothing approach. As in, a T4 file is treated as purely T4, unless another known directive is supplied:
<#@ template language="C#" #>
<#@ output extension="cs" #>
This is to say, some T4 files may have a couple of headers and consume methods from imports, operating mostly over a C# template.
Other T4 files may be pure T4 files, all enclosed completely in <#
#>
.
Which is a more common scenario? If a file is mostly C#, would it not be more beneficial simply to enhance the standard C# syntax & highlighting buffer, and offer IntelliSense for <#
#>
blocks inside of the C# buffer? (Let's say, similar to classic VB/ASP inside of HTML, but named .asp)
This would be opposed to gearing for T4, and then trying to implement C# (or VB) syntax interpretation as an afterthought.
That was just one thought which crossed my mind, and I'll be looking into. (Confirm that Web Essentials does use IProjectionBuffer
as a place to look at examples of implementation.)
Interesting, I didn't think about this before... So if we could extend the C# content type instead of defining a distinct text template content type we could let the C# editor extension take care of handling its own IntelliSense features while adding only the T4-specific ones. That would be awesome if it works.
I wonder if the C# editor supports projection buffers. I think that Web Essentials uses the built-in htmlx content type as a base for the markdown content type because the HTML editor has support for projection buffers and provides extensibility API allowing Web Extension to hook in the markdown IntelliSense components.
I don't know about the latter (if the C# editor supports projection buffers), and, I haven't checked, but... one thing which crossed my mind is F#. (Whereas, I believe T4Toolbox is primarily geared for VB/C#, but T4 might also be supporting F#???)
I've never tested T4 + F#, but, the idea is very simple: such that T4 syntax highlighting becomes a natural extension of whatever the declared (supported or mapped) output language. (Which could naturally extend to .json
, .js
, .html
, .whatever
), or otherwise default to pure T4.txt.
at least that's how I think about things
/ End Thought
That would be awesome! If we detect the type of text being generated from the extension
in the output directive and the language
in the template directive, we could use projection buffers to provide built-in syntax colorization and IntelliSense in both text and code blocks of the T4 Templates.
I wonder if @madskristensen could help us understand how this was accomplished for code snippets in the markdown editor of Web Essentials for Visual Studio 2015.
How to access completion list? I cannot access it using Ctrl+Space.