Eclipse code formatting supports a setting that wraps lines after the string concatenation operator (+), along with column formatting that aligns text with one element per line:
public enum SqlQuery {
createChatSchema( "CREATE SCHEMA IF NOT EXISTS chat;" +
"ALTER SCHEMA chat" +
" OWNER TO postgres;" +
"CREATE TABLE IF NOT EXISTS chat.messages_as_json" +
" (id BIGSERIAL PRIMARY KEY, message JSON NOT NULL);" ),
// leaving out constructor, etc.
}
Version: 1.34.0 (user setup)
Commit: a622c65b2c713c890fcf4fbf07cf34049d5fe758
Date: 2019-05-15T21:59:37.030Z
Electron: 3.1.8
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.18898
Java extension version: 0.7.1
public enum SqlQuery {
createChatSchema("CREATE SCHEMA IF NOT EXISTS chat;" + "ALTER SCHEMA chat" + " OWNER TO postgres;"
+ "CREATE TABLE IF NOT EXISTS chat.messages_as_json"
+ " (id BIGSERIAL PRIMARY KEY, message JSON NOT NULL);"),
public enum SqlQuery {
createChatSchema( "CREATE SCHEMA IF NOT EXISTS chat;" +
"ALTER SCHEMA chat" +
" OWNER TO postgres;" +
"CREATE TABLE IF NOT EXISTS chat.messages_as_json" +
" (id BIGSERIAL PRIMARY KEY, message JSON NOT NULL);" ),
// leaving out constructor, etc.
}
@snjeza Is this another case of the formatter changes being seemingly ignored? (see #957)
@rdcoe Could you try to use the following file - https://raw.githubusercontent.com/snjeza/vscode-test/master/eclipse-formatter.xml ?
No difference.
This:
createChatSchema( "CREATE SCHEMA IF NOT EXISTS chat;" +
"ALTER SCHEMA chat" +
" OWNER TO postgres;" +
"CREATE TABLE IF NOT EXISTS chat.messages_as_json" +
" (id BIGSERIAL PRIMARY KEY, message JSON NOT NULL);" ),
newMessageAsJSON( "INSERT INTO chat.messages_as_json (message) VALUES ($1) " +
"RETURNING id, message" ),
viewChatsAsJSON( "SELECT message FROM chat.messages_as_json" ),
viewUserChatAsJSON( "SELECT" +
" message ->> 'message' as message" +
"FROM" +
" chat.messages_as_json" +
"WHERE" +
" message ->> 'uuid' = '$1'" );
Became this:
createChatSchema("CREATE SCHEMA IF NOT EXISTS chat;" + "ALTER SCHEMA chat" + " OWNER TO postgres;"
+ "CREATE TABLE IF NOT EXISTS chat.messages_as_json"
+ " (id BIGSERIAL PRIMARY KEY, message JSON NOT NULL);"),
newMessageAsJSON("INSERT INTO chat.messages_as_json (message) VALUES ($1) " + "RETURNING id, message"),
viewChatsAsJSON("SELECT message FROM chat.messages_as_json"),
viewUserChatAsJSON("SELECT" + " message ->> 'message' as message" + "FROM" + " chat.messages_as_json" + "WHERE"
+ " message ->> 'uuid' = '$1'");
From: Snjeza notifications@github.com
Sent: Tuesday, July 2, 2019 10:22:37 AM
To: redhat-developer/vscode-java
Cc: Robin Coe; Mention
Subject: Re: [redhat-developer/vscode-java] Code formatter does not support additive operator preferences (#931)
@rdcoehttps://github.com/rdcoe Could you try to use the following file - https://raw.githubusercontent.com/snjeza/vscode-test/master/eclipse-formatter.xml
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/redhat-developer/vscode-java/issues/931?email_source=notifications&email_token=ACZS3FLN3ZNBOQWV236YHLDP5NQC3A5CNFSM4HOGLTJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZBOELY#issuecomment-507699759, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACZS3FN52WJYPHAYHAUKN53P5NQC3ANCNFSM4HOGLTJQ.
I can't reproduce the issue.
Could you set the following:
"java.format.settings.url": "https://raw.githubusercontent.com/snjeza/vscode-test/master/eclipse-formatter.xml"
to your workspace settings.json.
Tried both user settings and workspace settings. As soon as the Java Language Server starts, the formatter changes the code from the desired layout to the undesired default layout. To be clear, I changed the setting, experimented with the formatter. Saw undesired formatting. Restarted code, waited for the JLS to start, formatted the file. Always the same, no matter what I put in the formatter field, including an invalid value, like “x”.
From: Snjezanotifications@github.com
Sent: July 3, 2019 10:52 PM
To: redhat-developer/vscode-javavscode-java@noreply.github.com
Cc: Robin Coercoe.javadev@gmail.com; Mentionmention@noreply.github.com
Subject: Re: [redhat-developer/vscode-java] Code formatter does not support additive operator preferences (#931)
I can't reproduce the issue.
Could you set the following:
"java.format.settings.url": "https://raw.githubusercontent.com/snjeza/vscode-test/master/eclipse-formatter.xml"
to your workspace settings.json.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/redhat-developer/vscode-java/issues/931?email_source=notifications&email_token=ACZS3FKNP5ZMI53WK5QLA2DP5VQVTA5CNFSM4HOGLTJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZGFIHQ#issuecomment-508318750, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACZS3FMWRIEGSQI64NQ5KDDP5VQVTANCNFSM4HOGLTJQ.
Did more experimentation. I stopped using the GUI settings to set the value and instead edited the json directly. When I opened the settings, I saw a key for maven that Code didn’t recognize, so I deleted it. Then I moved the formatter setting to my user settings, removing it from my workspace settings. I had to remove the key in the file that had a value of “”, which was an artifact left behind when I removed the URI value from the text box. I believe this is a bug – deleting the value should delete the entry from the settings.
After I did this, the formatter started behaving correctly. So, was the problem that code had an invalid key or that there may have been an empty value in one settings file overriding the value in the other?
From: Robin Coe rcoe.javadev@gmail.com
Sent: Thursday, July 4, 2019 9:48:17 PM
To: redhat-developer/vscode-java; redhat-developer/vscode-java
Cc: Mention
Subject: RE: [redhat-developer/vscode-java] Code formatter does not support additive operator preferences (#931)
Tried both user settings and workspace settings. As soon as the Java Language Server starts, the formatter changes the code from the desired layout to the undesired default layout. To be clear, I changed the setting, experimented with the formatter. Saw undesired formatting. Restarted code, waited for the JLS to start, formatted the file. Always the same, no matter what I put in the formatter field, including an invalid value, like “x”.
From: Snjezanotifications@github.com
Sent: July 3, 2019 10:52 PM
To: redhat-developer/vscode-javavscode-java@noreply.github.com
Cc: Robin Coercoe.javadev@gmail.com; Mentionmention@noreply.github.com
Subject: Re: [redhat-developer/vscode-java] Code formatter does not support additive operator preferences (#931)
I can't reproduce the issue.
Could you set the following:
"java.format.settings.url": "https://raw.githubusercontent.com/snjeza/vscode-test/master/eclipse-formatter.xml"
to your workspace settings.json.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/redhat-developer/vscode-java/issues/931?email_source=notifications&email_token=ACZS3FKNP5ZMI53WK5QLA2DP5VQVTA5CNFSM4HOGLTJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZGFIHQ#issuecomment-508318750, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACZS3FMWRIEGSQI64NQ5KDDP5VQVTANCNFSM4HOGLTJQ.
Experimented with a different computer running the same versions of vscode and plugins. Had the same problem with formatting, until I removed this user setting:
"maven.executable.path": "d:/cygwin64/home/rcoe/apache-maven-3.5.2/bin/mvn"
According to this, https://github.com/Microsoft/vscode-maven/issues/79, the maven path is supposed to be supported. If it is, then it breaks the formatter. If it isn’t, that report should not be closed. Either way, surprising that a single key in the settings can break the formatter.
@snjeza Thanks. :)