redhat-developer / redhat-developer/vscode-java

Java code formatter improperly formats one-liner conditions and loops, and after method signatures

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

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

typing
Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
546
Merge trung bình
20 giờ 1 phút
Pull request đã merge (30 ngày)
11

Mô tả

The Java code formatter is working improperly after single-line conditions, loops, and specifically after multiline method signatures. For example, consider the following code segment:

public static List<List<Integer>> combinationSum(
        int[] candidates, int target) {

    return new ArrayList<>();
}

Now, if you hit Enter after the opening curly brace, the cursor will be jumped right to the next line with unexpected indentation:

Unexpected indentation

Environment
  • Operating System: Windows 10 22H2
  • JDK version: javac 17.0.10
  • Visual Studio Code version: 1.86.2
  • Java extension version: 1.28.1
Steps To Reproduce

The brief information above represents just one example. Here is more with single-line conditions and loops:

Consider this code segment:

public static List<List<Integer>> combinationSum(
        int[] candidates, int target) {
    int x = 5;

    if (x > 5)
        System.out.println("ok");
    else
        System.out.println("Not ok");

        

    return new ArrayList<>();
}

Have a look after the end of the else statement. It should not be indented in such cases.
Here is the screenshot:

Indentation problem in conditional statements

The same goes with one-liner loops:

Indentation problem in loop statements

A sample file saved unformatted:
Main.zip

Log file generated by RedHat formatting server:
redhat_server_log.txt

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện các vấn đề về thụt lề bằng các ví dụ mã hoặc Main.zip đính kèm, và kiểm tra redhat_server_log.txt để xem ngữ cảnh của formatter. Công việc được xem là hoàn tất khi các điều kiện và vòng lặp trên một dòng, cùng với các dòng mới sau chữ ký phương thức nhiều dòng, nhận được mức thụt lề mong đợi mà không ảnh hưởng đến định dạng nào khác.

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

Đánh giá

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

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.