jhipster / jhipster/prettier-java
formatWithCursor and --cursor-offset seem not work
- Lenguaje dominante
- Java
- Estrellas
- 1.2k
- Forks
- 120
- Merge medio
- 1 d 11 h
- PR fusionados (30 d)
- 31
Descripción
**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: []
}
Guía de contribución
Línea de trabajo
Reproduce el ejemplo de Java usando la API formatWithCursor y la opción de CLI --cursor-offset, y después compara sus resultados con un parser que gestione correctamente los offsets del cursor. Rastrea el manejo de cursor-offset del plugin desde estos puntos de entrada. Se considera completado cuando un offset de entrada válido produce el cursorOffset ajustado esperado en lugar de devolver siempre 0.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java, javascript
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100