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

Indentation configuration #287

Closed
affanshahid opened this issue Aug 24, 2017 · 7 comments
Closed

Indentation configuration #287

affanshahid opened this issue Aug 24, 2017 · 7 comments

Comments

@affanshahid
Copy link

Is there any way to customize the indentation/format rules? The following screenshots should describe what I want to happen

Pre Format

screen shot 2017-08-24 at 10 43 08 pm

Post Format

screen shot 2017-08-24 at 10 43 47 pm

I want it to not mess up my custom formatting and simply fix indentation errors. Is this possible?
IntelliJ is able to format code into my pre-format form as well.

@fbricon
Copy link
Collaborator

fbricon commented Aug 24, 2017

vscode-java doesn't expose formatting options of the underlying Eclipse JDT formatter yet.

You currently have 2 options:

  • disable java formatting, by setting java.format.enabled to false in VS Code's preferences
  • define the formatting preferences in your project's .settings/org.eclipse.jdt.core.prefs.

The 2nd solution is rather tedious, so the best way to do it is to open your project in eclipse and set the formatting preferences for your project there. In Eclipse, right-click on your project, open Properties > Java Code Style > Formatter and create a new formatting profile :
screen shot 2017-08-24 at 2 41 36 pm

Once you save it, .settings/org.eclipse.jdt.core.prefs will be updated. This file will need to be copied to all your other projects in the same workspace.

No it's not an ideal solution, but it should be done only once, unless you regularly change your formatter settings.

@affanshahid
Copy link
Author

Thanks for the work around! Any plans on integrating this type of customization?

@fbricon
Copy link
Collaborator

fbricon commented Aug 29, 2017

It's in our backlog: #2

@fbricon
Copy link
Collaborator

fbricon commented Aug 29, 2017

Will keep the discussion open in #2. Closing this one as duplicate (kinda)

@fbricon fbricon closed this as completed Aug 29, 2017
@ocavue
Copy link

ocavue commented Oct 29, 2017

@fbricon The 2nd solution does not works for me.

Below is my code. I can't get 4 blank line before methods. Now I have only 1 blank line, as same as the default setting.

screen shot 2017-10-29 at 6 19 40 pm

I don't know if I did something wrong or this is just a bug.

OS: macOS 10.13
VSCode: 1.17.2
Language Support for Java(TM) by Red Hat: 0.12.0

@fbricon
Copy link
Collaborator

fbricon commented Oct 30, 2017

@ocavue the solution works for actual projects. What you have is a folder with a java project and a .classpath file. So what defines what an actual project is? At the root of your folder you need to have either:

  • a Maven pom.xml,
  • or a Gradle build.gradle,
  • or both Eclipse's .project and .classpath files.

I strongly suggest you go with making either a Maven or a Gradle project. But if you find that too daunting, a simpler alternative is to use Eclipse to create a new Java project.

Then add your java class to your project source folder.

Once you have your project structure created, you can close your IDE to open the folder in VS Code. Changing org.eclipse.jdt.core.formatter.blank_lines_before_method=4 in .settings/org.eclipse.jdt.core.prefs should now work.

oct-30-2017 09-57-44

@ocavue
Copy link

ocavue commented Oct 31, 2017

@fbricon Sorry for posting a stupid question. I know little about java and your detailed answer is really helpful. Thanks.

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