Visual Studio 代码:格式化 Java 方法链接
Visual Studio Code: Formatting Java method chaining
我正在尝试更改 VSCode 设置,这将允许我使用方法链执行类似的操作:
Flux
.just("test", "string", "flux")
.log()
.map(String::toUpperCase);
问题是每当应用格式化程序时,它都会将其改回只有一行:
Flux.just("test", "string", "flux").log().map(String::toUpperCase);
我安装了 Java 扩展包,其中包括 'Language Support for Java by Red Hat'。该扩展程序添加了一些格式选项,我一直在尝试使用它们,但运气不好。
以下是我更改的格式选项:
"editor.formatOnSave": true,
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"java.format.enabled": true,
"java.format.settings.profile": "GoogleStyle"
有人知道我如何让格式化程序单独保留多行方法链接吗?
来自Redhat Developer VSCode-Java plugin wiki:
You can also define the formatting preferences in your project's .settings/org.eclipse.jdt.core.prefs. It will override global formatting settings.
Since this is rather tedious, the best way to edit those preferences is to open your project in Eclipse and set the formatting preferences for your project there.
您要查找的选项是:
换行 > 换行设置 > 函数调用 > 合格调用
设置为换行所有元素,每个元素换行,如下图所示:
我无需下载 Eclipse 即可导出所需设置,也获得了相同的结果。我阅读了来自 vscode-java-formatter.md
的精彩指南
我已经在 vscode 中设置了这个 JSON:
"java.format.settings.url": "dir/to/eclipse-java-google-style.xml"
在本地 eclipse-java-google-style.xml
中,将以下值从 true
更改为 false
。
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
保存并重新启动 vscode。现在链接的方法不会被挤成一行。
我正在尝试更改 VSCode 设置,这将允许我使用方法链执行类似的操作:
Flux
.just("test", "string", "flux")
.log()
.map(String::toUpperCase);
问题是每当应用格式化程序时,它都会将其改回只有一行:
Flux.just("test", "string", "flux").log().map(String::toUpperCase);
我安装了 Java 扩展包,其中包括 'Language Support for Java by Red Hat'。该扩展程序添加了一些格式选项,我一直在尝试使用它们,但运气不好。
以下是我更改的格式选项:
"editor.formatOnSave": true,
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"java.format.enabled": true,
"java.format.settings.profile": "GoogleStyle"
有人知道我如何让格式化程序单独保留多行方法链接吗?
来自Redhat Developer VSCode-Java plugin wiki:
You can also define the formatting preferences in your project's .settings/org.eclipse.jdt.core.prefs. It will override global formatting settings. Since this is rather tedious, the best way to edit those preferences is to open your project in Eclipse and set the formatting preferences for your project there.
您要查找的选项是:
换行 > 换行设置 > 函数调用 > 合格调用
设置为换行所有元素,每个元素换行,如下图所示:
我无需下载 Eclipse 即可导出所需设置,也获得了相同的结果。我阅读了来自 vscode-java-formatter.md
的精彩指南我已经在 vscode 中设置了这个 JSON:
"java.format.settings.url": "dir/to/eclipse-java-google-style.xml"
在本地 eclipse-java-google-style.xml
中,将以下值从 true
更改为 false
。
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
保存并重新启动 vscode。现在链接的方法不会被挤成一行。