redhat-developer / redhat-developer/vscode-java

java formatter: unable to wrap/break long Strings

未关闭
#3,985 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

code action enhancement
主要语言
TypeScript
星标
2.3k
派生
546
平均合并
20 小时 1 分钟
30 天内合并 PR
11

描述

I come from Intellij idea and I'm used to break long lines with the formatter. I managed to export/import most of the settings, but I can not manage it that vscode breaks long String lines, splitting the Strings with "firstPart" + "secondPart".

These are my related settings in the codeFormatterSettings.json:

<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="180"/>
<setting id="org.eclipse.jdt.core.formatter.formatter_wrap_long_strings" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_strings" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_string_concatenation" value="true"/>

Please ask if I should upload the whole file.

This is an example line of code:

String strSystemPrompt =
                "You are a system that generates a concise and informative answer in less than 100 words for the given question, which is marked with QUESTION. Use the given search results marked with SEARCH RESULT as only knowledge base. Answer questions in the language of the question, i.e. german questions in german and only english questions in english.";

This is the expected output:

String strSystemPrompt =
                "You are a system that generates a concise and informative answer in less than 100 words for the given question, which is marked with QUESTION. Use the given search" + 
                "results marked with SEARCH RESULT as only knowledge base. Answer questions in the language of the question, i.e. german questions in german and only english" + 
                "questions in english.";

Am I missing something, is it not supported, or is it a bug?

VSCode version 1.98.2
Java Language support:
Version
1.40.0
Last Updated
2025-03-06, 08:33:26

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用 codeFormatterSettings.json 中显示的设置和 issue 中的 Java 示例重现 formatter 的行为。检查列出的长字符串和字符串拼接选项是否传递到了 VS Code extension 使用的 Java formatter。只有当长 Java 字符串字面量按预期输出所示拆分为拼接字符串时,才算完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。