redhat-developer / redhat-developer/vscode-java

Updating class references (generated classes from proto files)

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

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

annotation-processing ls-out-of-sync
Ngôn ngữ chính
TypeScript
Star
2.3k
Fork
547
Merge trung bình
20 giờ 1 phút
Pull request đã merge (30 ngày)
11

Mô tả

Hi. I'm using Protocol Buffers in my Java application. I'm using Gradle, and the protobuf-gradle-plugin to generate Java classes from the .proto files. The generated proto Java files are added to my sourceSet in build.gradle.

build.gradle
plugins {
    id 'java'
    id 'application'
    id "com.google.protobuf" version "0.8.12"
}

repositories {
    jcenter()
}

dependencies {
    implementation 'com.google.guava:guava:28.2-jre'
    testImplementation 'junit:junit:4.12'
}

application {
    mainClassName = 'test.gradle.project.proto.App'
}

sourceSets {
  main {
    java {
      srcDirs 'src/main/java'
      srcDirs 'build/generated/source/proto/main/java'
    }
  }
}

compileJava.dependsOn 'generateProto'

Whenever I make a change to the proto files, and re-generate the proto Java classes via ./gradlew generateProto, the language server does not update the references, and I get errors in the editor. AFAIK there's two ways to update the class references:

  1. Restart vscode, or
  2. Run "Update project configuration" from the grade build file

Neither options are ideal, and option 2 can sometimes take a long time to complete on large projects. I would think updating class references should be a quick process. No compilation is necessary, the language server just needs to update it's reference cache (or something along those lines).

Would it be possible to

  1. Provide a new command to update class references?
  2. Watch the build directory/sourceSets and automatically update references when generated files change?

I'm also developing a gradle vscode extension, and from my extension i would potentially be able to provide a list of generated class files to the vscode-java extension via an API call, so that could also be a potential option.

Looking for any ideas/suggestions/changes to make this process more user friendly and fast.

Environment
  • Operating System: MacOS catalina
  • JDK version: openjdk 11.0.2
  • Visual Studio Code version: 1.45.1
  • Java extension version: 0.62.0
Steps To Reproduce
  1. Clone this repo: https://github.com/badsyntax/test-gradle-project-proto
  2. Open test-gradle-project-proto in vscode
  3. Open src/main/java/test/gradle/project/proto/App.java
  4. Note classes for Greeting don't exist
  5. In the vscode terminal, run ./gradlew generateProto
  6. Note references for Greeting still don't exist
  7. Either restart vscode, or run "Update project configuration" from build.gradle
  8. Note references for Greeting now exist and there's no errors in the editor

Keep in mind this is a very small project and you won't see the performance issues I mentioned above, but does demonstrate the extension not updating references when files on disk change.

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

Tái hiện vấn đề với repository test-gradle-project-proto được liên kết, sử dụng build.gradle và src/main/java/test/gradle/project/proto/App.java. Chạy ./gradlew generateProto sau khi mở project và quan sát xem các tham chiếu đến Greeting có được cập nhật mà không cần khởi động lại VS Code hoặc chạy Update project configuration hay không. Hoàn thành khi các tham chiếu đến các class được sinh ra được cập nhật sau khi các file thay đổi mà không yêu cầu cập nhật toàn bộ cấu hình project.

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, vscode
Lĩnh vực
developer-experience, tooling
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/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.