Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make namespace line position configurable #99

Open
bard83 opened this issue May 12, 2022 · 5 comments
Open

Make namespace line position configurable #99

bard83 opened this issue May 12, 2022 · 5 comments

Comments

@bard83
Copy link
Collaborator

bard83 commented May 12, 2022

Current behavior
namespace in class/interface/struct etc... always appears after using block.

using System.Text.Json;
// more using statements

namespace My.Wonderful.Name.Space;

public class MyClass
{
     // some code
}

Expected behavior
The name space position should be configurable to be either after the using block for default or when the configuration flag is ticked on top of the class:
e.g.

Default position:

using System.Text.Json;
// more using statements

namespace My.Wonderful.Name.Space;

public class MyClass
{
     // some code
}

When option is enabled:

namespace My.Wonderful.Name.Space;

using System.Text.Json;
// more using statements

public class MyClass
{
     // some code
}

Reformat feature should take care about the new configuration property.

@bard83 bard83 added bug Something isn't working feature request and removed bug Something isn't working labels May 12, 2022
@tilkinsc
Copy link

I, too, would like this feature.

@KreativJos
Copy link
Owner

How would a reformat take care of this? Is there an option for this in omnisharp or .editorconfig?
Also, do both of you know what ramifications this choice has? - https://stackoverflow.com/questions/125319/should-using-directives-be-inside-or-outside-the-namespace

@tilkinsc
Copy link

Reformat would probably work. For people who don't configure a formatter to abide by their standards, it would butcher their code to be weirdly modifyable. Omnisharp settings are like walking into linux for the first time without prior knowledge. Very complex. I don't even know if they have a reformatter. I dont use them.

I do understand the ramifications. I keep it very java-like. Fully qualified usings and namespace.

@bard83
Copy link
Collaborator Author

bard83 commented Jul 27, 2022

How would a reformat take care of this?

TBH I didn't remember about that point. Well, I must admit that it seems pretty hard task to do and honestly not a responsibility of the formatter. Drop that.

Is there an option for this in omnisharp or .editorconfig?

Haven't found anything in both of them. Currently even though .editorconfig would have specified a configuration for it, the current templates generation won't either consider it. It will generate class/enum/interface based on the static templates, doesn't it?

Side note: .editorconfig bothers me, even if it'd define the possibility I wouldn't use it. Why should I define .editorconfig file and then carry it over all my solo projects? I would, rather, rely on my IDE for such configuration.

Also, do both of you know what ramifications this choice has?

The request here is not about to create a configuration enabled for default, which I can image will start to create inconsistency over all the extension users. But rather opt-in the configuration for those users which have the needs to do like so. My team decided to have namespace on top of the file, means that in the next months I'll spend time to move the namespace on top of any created files first and then start to write my code...

@KreativJos
Copy link
Owner

Reformat would probably work. For people who don't configure a formatter to abide by their standards, it would butcher their code to be weirdly modifyable. Omnisharp settings are like walking into linux for the first time without prior knowledge. Very complex. I don't even know if they have a reformatter. I dont use them.

Omnisharp does provide a formatter. I do not see any option for the namespace position though: https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options
I have implemented a reformat after create in branch feature/formatTemplateAfterCreate. If .editorconfig does have an option for the namespace, it could be tested with that branch. Either one of you can try if this is enough to fix your issue / feature request.

Otherwise, this could be implemented by having 2 replacement variables in the templates, or by simply placing the namespace at the beginning of the file. I'd rather have this functionality by using an existing tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants