formatWithCursor and --cursor-offset seem not work
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- java, javascript
- 领域
- tooling
调研方向
使用 formatWithCursor API 和 --cursor-offset CLI 选项重现 Java 示例,然后将它们的结果与能正确处理光标偏移量的解析器进行比较。跟踪 plugin 从这些入口开始对 cursor-offset 的处理。完成标准是:有效的输入偏移量会产生预期的调整后 cursorOffset,而不是始终返回 0。
由索引模型根据 Issue 内容生成。
描述
Prettier-Java 2.6.0
Detail
I want to get the index change of given cursor when formatting Java code. I noticed that it can be done with formatWithCursor(API) or --cursor-offset(CLI). However, whatever valid offset I try, the result will always be 0. Besides, I have also tried with formatting babel code (builtin in Prettier), which behaved correctly. I wonder how I can fix this. Is this a feature unfinished?
I will show you the example with API (CLI also fails extractly the same)
API Usage with formatWithCursor
import * as prettier from "prettier";
import * as prettierPluginJava from "prettier-plugin-java";
const javaText = `
public class HelloWorldExample{public static void main(String args[]){
System.out.println("Hello World !");
}
}
`;
const formattedText = await prettier.formatWithCursor(javaText, {
cursorOffset: 5,
parser: "java",
plugins: [prettierPluginJava.default],
});
Output:
{
formatted: 'public class HelloWorldExample {\n' +
'\n' +
' public static void main(String args[]) {\n' +
' System.out.println("Hello World !");\n' +
' }\n' +
'}\n',
cursorOffset: 0,
comments: []
}
Expected output:
{
formatted: 'public class HelloWorldExample {\n' +
'\n' +
' public static void main(String args[]) {\n' +
' System.out.println("Hello World !");\n' +
' }\n' +
'}\n',
cursorOffset: 2,
comments: []
}
- 主要语言
- Java
- 星标
- 1.2k
- 派生
- 122
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jhipster/prettier-java 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
jhipster/prettier-java#1113 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
jhipster/prettier-java#1115 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 56/100
jhipster/prettier-java#1114 ·
维护者通常 2 天内回复
-
难度 3/5 1-2 天 新手友好度 66/100
jhipster/prettier-java#1112 ·
维护者通常 2 天内回复
-
Comment "// @formatter:off" was not printed可能已有人在做 @jtkiesel 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
jhipster/prettier-java#1098 ·
维护者通常 2 天内回复
查看 jhipster/prettier-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
QuiltMC/update-quilt-meta#28 ·
-
awaiting triage Documentation P3
难度 1/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
area/build area/maintainability component/camunda-process-test kind/tech-debt
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToList可能已有人在做 @mohamed-elbrik 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
area/kotlin
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复