I'm a software engineer from Belgium with a focus on .NET technologies.
tim-maes / t4editor Goto Github PK
View Code? Open in Web Editor NEWEnhance your T4 experience in Visual Studio.
License: MIT License
Enhance your T4 experience in Visual Studio.
License: MIT License
I'm a software engineer from Belgium with a focus on .NET technologies.
No way to adjust text colors no (Extensions -> T4Editor -> Colors) menu. Color of the text template is white on white.
Since installing the extension I find that code-editor scrolling performance in VS2019 suffers badly when scrolling a T4 file with even a moderate amount of T4 code-blocks.
When dragging the scrollbar down it starts behaving erratically (e.g. the scrollbar thumb just jumps around, top to bottom) and the document view sometimes goes blank for a half-second.
I can make a screen recording and share the T4 files I'm working with if you like.
I received some anonymous feedback through my blog regarding custom file extensions. Some users like to suffix their .T4 template with an extra character to exclude them from being handled during build events etc.
It would be nice if the user could specify custom extensions (eg. .T4i, .T4x, .tt1) in some way.
Default colorization settings are based on a dark IDE theme. When a user installs the extension on a light IDE, the default text colors are too light/bright on a white background.
A nice to have would be default settings for both themes, some sort of detection on install or ask the user on first install what defaults are preferred.
Ideal: you can right click in the editor on a T4 file and there should be an option 'Format T4 template'.
This command should put control block and class feature block tags on new lines and indent the code with 1 tab in between tags.
Optional: attach the command to the format command in Visual Studio (eg; CTRL+K+D)
(This doesn't seem to be the same issue as #16)
I had a T4 file open and just held-down the spacebar in the editor and experienced performance issues (high CPU, slow VS editor updates, etc) so I started a profiler session and I see that the regular-expressions in T4Classifier.GetClassificationSpans
were being evaluated via the regex interpreter instead of being compiled in-memory.
I'm confident that converting the regexs in T4Classifier.cs
to be precompiled should provide an immediate perf. boost here, though I'm not currently able to test this hypothesis.
To do this, hide the const String
patterns as private
(so other code can't accidentally call non-compiled versions) and use RegexOptions.Compiled
(though there are some gotchas too: https://stackoverflow.com/questions/40953573/why-does-the-c-sharp-regexoptions-compiled-makes-the-match-slower )
Also, as the regex patterns are const String
values, you can improve your dev UX by adding /* language=regex */
right before the literal. The literals look like they could be converted to verbatim literals which makes them more readable as it eliminates the escaped backslashes, like so:
internal const string ControlBlockRegex = /* language=regex */ @"(?<openingtag>(?<!\")<#((?!\"|=|@|\+)))(?<code>((?!(?!)<#(?!\+|=)|#>)[\s|\w|\d|\n|().,<>\-:;@#$%^&=*\[\]\"'+\/\®°⁰!?{}|`~\\u2000-\\u206F\\u2E00-\\u2E7F])*)(?<closingtag>(?=\s?|\w?|\n?)(?<!\")#>(?!\"))";
Currently T4Editor is leaning heavily on the use of RegEx patterns to filter out codeblocks from the textView and colorize them.
A better approach would be to create something that parses the textView on a token based implemenation. We only catch the T4 open/close tags and this leaves room to try and introduce C# language features inside these blocks.
This piece of code was not processed properly:
<#+
static string CreateSummaryText(string s)
{
return s.Length < 51 ? s : "…";
}
#>
The ellipsis is the culprit here.
I'm trying to uninstall the extension in VS 2022, but it persists after a restart.
Can you assist?
I noticed when I type a ¦
character into the plaintext/output part of a T4 script (i.e. not in a <#
block) it causes the extension to lose syntax coloring of that run of text. This also happens when reloading a T4 file with those chars in it.
In the screenshot below, observe that I have Output set to ForestGreen, which is used for most of the output text runs on the right-hand editor pane - but notice that whenever an output run has ¦
in it the editor will render the text as black-on-white and not ForestGreen-on-white.
(I use the ¦
char to denote an alignment point which is used by a tool I wrote).
There is a problem when a standard control block open tag <#
or close tag #>
is in touch with the double-quote character "
on any side of any of the tags. The result is the color is not set for this code block it is colored as the result (white by default on my dark theme).
The problem seems to affect only the standard control blocks <# ... #>
or as you call it on the config window "Statements blocks".
I not tested on other themes than the dark.
To demonstrate the problem I attach a T4 Text Template and its output.
You need to open this file on the Visual Studio with the T4Editor extension installed.
You will see the color inconsistency related to the double-quote symbol.
If you don't want to open it in VS, I added the comments for each case. "WRONG" means it is colored as result (white by default on my dark theme) instead of as code.
I also included the execution result to demonstrate that the template will execute as expected and will not ignore the tags in touch with double-quote characters as the color information suggests.
TextTemplate.tt
//Tests with no quotes
//<# #> <- Displays ok
//Tests with double quotes:
//"<# #>" <- Displays WRONG!
//" <# #> " <- Displays ok
//"<# #> <- Displays WRONG!
//" <# #> <- Displays ok
//<# #>" <- Displays WRONG!
//<# #> " <- Displays ok
//Tests with other quotes/tildes:
//'<# #>' <- Displays ok
//´<# #>´ <- Displays ok
//`<# #>` <- Displays ok
//¨<# #>¨ <- Displays ok
Result:
//Tests with no quotes
// <- Displays ok
//Tests with double quotes:
//"" <- Displays WRONG!
//" " <- Displays ok
//" <- Displays WRONG!
//" <- Displays ok
//" <- Displays WRONG!
// " <- Displays ok
//Tests with other quotes/tildes:
//'' <- Displays ok
//´´ <- Displays ok
//`` <- Displays ok
//¨¨ <- Displays ok
After Visual Studio 2022 version update from 17.0.2 to 17.0.4 Colors reset to default values.
Reproduced with Visual Studio 2019 update 16.11.7->16.11.8
Either one solution will be better than now: different default colors for light scheme, load/save colors to file, or just don't reset values after update.
Currently I ask the user on first install if the IDE is set to dark or light theme and apply color scheme based on the input. This should be an automatic process without user interaction.
When you write one code with debugging lines, you don't want to appear these lines in the final release.
It is not possible the use "#if DEBUG ... #endif" just the T4 is a compiler.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.