jhipster / jhipster/prettier-java
formatWithCursor and --cursor-offset seem not work
- 主要言語
- Java
- スター
- 1.2k
- フォーク
- 120
- 平均マージ
- 1日 11時間
- マージ済み PR(30日)
- 31
説明
**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`
```js
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:**
```java
{
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:**
```java
{
formatted: 'public class HelloWorldExample {\n' +
'\n' +
' public static void main(String args[]) {\n' +
' System.out.println("Hello World !");\n' +
' }\n' +
'}\n',
cursorOffset: 2,
comments: []
}
コントリビューションガイド
調査の方向性
formatWithCursor API と --cursor-offset CLI オプションを使って Java の例を再現し、その結果をカーソルオフセットを正しく処理する parser と比較します。これらのエントリポイントから plugin の cursor-offset 処理を追跡します。完了の条件は、有効な入力オフセットによって期待される調整済みの cursorOffset が生成され、常に 0 が返される状態ではないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java, javascript
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100