Change Code of New Query Template

I believe the code for new queries (template) is embedded (IIRC) in LINQPad 8. I'm wondering, in case I am wrong, how I can modify the default template. First off, I hate having 3 blank lines at the end (I turned the comment at the end off in preferences). Additionally, there are other lines we would like to have (by default) for all new queries. I have had to workaround this by creating a snippet that, when a new tab/query is opened, I would have to delete it's contents and then execute the snippet.

Comments

  • This is not something that's been requested so far. It would be somewhat complicated in that this template would need to be different depending on whether the script was of type C# Program or C# Statements (or C# Expression). And when you switch between those three modes, LINQPad would need to know how to convert between them.

  • Well, I guess the reason for this request was just so I could remove unnecessary the blank lines at the end of the default code templates when you have Preferences > Advanced > Editor > Include user-code placeholder comment in 'C# Program' mode set to False.

    I know, not a huge deal, but to me, I manually remove them every new query and it's just extra stuff I would like to be removed. Personal preference only. :) You've been awesome at applying my requests before, so I thought, what the hell, it doesn't hurt to ask. Keep up the great work!

  • Thanks for the clarification. I don't understand you'd want to remove the blank lines - it makes it easier to add extra code. If it weren't for this, you'd have to hit enter three times before typing in the new code.

  • I would like to be able to change the default from "void Main()" to "async Task Main()" because that's something I have to manually change almost every time I open a new script. Is this possible today?

  • Yes: this is a pain point. I'm not keen on creating an option to changing the default to async Task Main(), though, because (a) most people won't discover the feature and (b) even though wrapping sync code with async Task Main() should be harmless, any edge-case issues could end up being counterintuitive.

    Instead, what I can do is modify the Make method async code fix such that it preserves the Main method name rather than renaming it to MainAsync. Then you just have to press Alt+Enter and Enter again to change the signature.

    Additionally, I could make that code fix run automatically. When the compiler detects CS4033 in your Main method, it could change the Main method signature without asking. What do you think?

  • Additionally, I could make that code fix run automatically. When the compiler detects CS4033 in your Main method, it could change the Main method signature without asking. What do you think?

    Personally, I would rather things don't get changed automatically in code. As long as it's opt-in.

  • There will definitely be an option to enable/disable, although I'm leaning towards opt-out rather than opt-in, like the option that switches automatically between Expression and Statements modes.

    Also considering importing the System.Threading.Tasks namespace automatically when required (also opt-out). This is a pain-point because normal console projects include this by default, and LINQPad doesn't (mostly because doing so could break existing scripts - and compatibility with LINQPad 5).

  • Would you ever consider a LINQPad template file (.tlinq) for this?

    A .tlinq file would be a .linq file but include the xml header and you could add them at any point in the Scripts hierarchy. I'm imagining one or more at the root level and then others as required within your folder structure. A right click on any folder could then display one or more root templates + the first ones it hit going back up the folder structure.

    So for the async / non async you'd just have two root level ones, one of which you'd define as the default.

    I've got a number of folders where this would work nicely for specific script types.

    I'm not quite sure what behaviour you'd want on the "+" new tab - maybe just the default root one?