Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

formatWithCursor and --cursor-offset seem not work

Đang mở
#660 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java, javascript
Lĩnh vực
tooling

Hướng nghiên cứu

Tái tạo ví dụ Java bằng API formatWithCursor và tùy chọn CLI --cursor-offset, sau đó so sánh kết quả của chúng với một parser xử lý chính xác các cursor offset. Theo dõi cách plugin xử lý cursor-offset từ các điểm vào này. Hoàn tất khi một offset đầu vào hợp lệ tạo ra cursorOffset đã điều chỉnh như mong đợi thay vì luôn trả về 0.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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: []
}
Ngôn ngữ chính
Java
Star
1.2k
Fork
123
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
35

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của jhipster/prettier-java

Tất cả issue của jhipster/prettier-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.