How can I modify the template for generating setters in CLion? - clion

In CLion, we can generate setters from fields by: Code -> Generate... -> Setter. But how can I modify the template for the code generation to change, for example, the generated setter parameter name?

As far as I know you can not fully customize it, but you can change some attributes of it under Editor > Code Style > C/C++ Like if prefixes should be added.

Unfortunately, I've got it confirmed from JetBrains that this is currently not possible in CLion.

Related

Go text template syntax highlighting in GoLand

GoLand has syntax support on Go html files with the file extension of .gohtml
So what about Go text files? Does GoLand support that as well? .tmpl is supported by vim-go but not GoLand.
As mkopriva has already hinted and you have described as well in the comments, you can go to Preferences/Editor/File Types and add your custom ending as Registered pattern to the Go Template. But imo the real game changer is that you can also set Go as Template data language there. This way even the Go syntax gets validated, not just the template syntax. It's still wonky, but definitly better than nothing.
Still, autoformatting does not work properly and can screw up your code. Therefore, you might also want to make sure the Reformat code in the commit dialog is unchecked. Same with Optimize Imports ... better keep it unchecked.
there are two parts to this answer to get both html highlighting and go template highlighting
go template highlighting:
settings > editor > file types > select Go template files from the list > update pattern to the file ending you use for your go templates. I used *.go.html
html highlighting
settings > template data languages > project language (dropdown at the top) > set to html
now you have both html highlighting and go template completion

Visual Studio DSL interaction with my classes

I'm getting start with DSL, I have build my DSL and I have a T4 template for generate code from a design.
I can create a new element in my project of my DSL type, I can create my design and then I have to run my T4 to generate code.
But, I can see how to work the default Visual Studio Class Diagram, it don't need to run any T4. For example when you drop a class in the diagram it shows a dialog to choose the class name and file.
When I change a class (adding properties for example) by edit the file the diagram update itself the new information (properties, methods, ...). When you add a property in a class using the diagram its update the file adding the correct property ...
How to do it? I'm newbie and I would like to find documentation about it.

visual studio 2010 inserts using directives inside namespace

I have exactly opposite problem to one described here. In my case Visual Studio inserts using directives inside namespace and I want to prevent this. I did try to uncheck Resharper option:
Languages -> C# -> Formatting Style -> Namespace Imports -> Add using directive to the deepest scope
And it didn't help. Also I tried to temporary disable the Resharper. Still same issue.
Btw, I have StyleCop and StyleCop+ installed as well. Maybe it is causing the issue.
So right now when I go and Add New Item -> Class - it will create new code file with using directives inside namespace. How to change this?
Have you replace your class template file with one that has one or more using directives inside the namespace declaration? If so, you're probably seeing the result of an interesting bit of C# plugin behavior: a newly added using directive is placed after the last recognized using directly already in the file, regardless of where that is.

Adding usings inside the namespace

Is there a way to configure ReSharper to add using references to a file within the appropriate namespace?
Currently it adds them to the top of the file, which is fine, until you want multiple namespaces in the same file.
For example, I would like it to be like the following:
namespace A
{
using System;
// other classes
}
Options > Code Editing > C# > Namespace Imports:
Insert using directives when necessary > Add using directive to the deepest scope.
Just to bring an up to date answer here as I was wanting to do this but not having R# (ReSharper) installed...
Its now available from Visual Studio 2019 directly since the 16.1 Release.
I found this on developercommunity.visualstudio.com
The code style to include using directives inside or outside a namespace was added in Visual Studio 2019 update 16.1. You can now set your preference in Tools > Options > Text Editor > C# > Code Style or in an EditorConfig file and the IDE can apply it through messages, warnings, or errors depending on the severity you specify in the code style rule

Finding T4 text template class code

T4 text templates can be used to generate not only code but also any kind of text with visual studio.
I've read blogs and tutorials about T4 and as far as I can understand, visual studio dynamically builds a class in the background, compiles and runs the code in that class to build the text output.
Is it possible to see the source code of that class?
Yes, the easiest way is to change the Custom Tool in the properties window when the template file is selected in Solution Explorer.
By default, it will be 'TextTemplatingFileGenerator'.
If you change the custom tool to 'TextTemplatingFilePreprocessor' you'll get the underlying template class instead of the template output generated into your project.
To be precise, this code won't be exactly the same as that which is run under the covers, but it will be very close.
If you need the absolute exact code, you should leave the custom tool alone, but set the debug="true" flag on your <## template #> directive. This will then leave the generated code sitting around in a random named '.cs' or 'vb' file in your %TEMP% directory. Just sort the directory by time and it should be up at the top.

Resources