jbangdev / jbang-idea

IntelliJ IDEA plugin for JBang
https://plugins.jetbrains.com/plugin/18257-jbang
MIT License
20 stars 9 forks source link

Sync dependencies between build.gradle and JBang script #3

Open linux-china opened 2 years ago

linux-china commented 2 years ago

In edit mode, some developers add dependencies in build.gradle for code completion etc. Finally they should copy dependencies to JBang script with //DEPS directive. Introduce a shortcut to sync dependencies from Gradle to JBang script with //DEPS filled.

Reverse flow should be considered too. Introduce intention action for //DEPS and add dependency to build.gradle. With Github Copilot, and it's easy to add dependency in script.

maxandersen commented 2 years ago

this is not something that should be done by jbang idea plugin imo - at least not in its final form. users should not be encouraged to edit build.gradle when using jbang - build.gradle is to be treated as purely temporary intermediate format as jbang edit will regenerate build.gradle anyway.

we have prs/issues that suggest to add deps.txt as a more centralized location if that is a problem.

linux-china commented 2 years ago

@maxandersen I have implemented this feature in 0.3.0 version. Sync Dependencies Action: right click script file and sync dependencies between JBang and Gradle. //DEPS to implementation or implementation to //DEPS .

Screen Shot 2021-12-25 at 6 41 07 PM
maxandersen commented 2 years ago

I really don't think this is right. Sure it's a nice feature but we should NOT assume build.gradle even exist.

linux-china commented 2 years ago

If build.gradle not found, and Sync JBang DEPS will not available.

For most developers, two ways to open JBang with IDEA:

I think we should have a good practice to code JBang script with IDEA, and developers can enjoy features supplied by the plugin.

linux-china commented 2 years ago

Sync DEPS as IDEA module's libraries when using idea . to open JBang project without build.gradle

The new logic as following:

maxandersen commented 2 years ago

I'm concerned whatever this sync does it gets out of sync (no pun intended :) with how jbang edit works; especially upcoming jbang edit . (see https://github.com/jbangdev/jbang/pull/1042).

p.s. could we move to use pull-request before pushing to main - would be great to learn a bit more on how idea plugins evolves and pull-requests lets one see that vs raw push to main - even if pushed more or less directly.

linux-china commented 2 years ago

Gradle project models for dependencies sync :

settings.gradle

include 'app'
include 'jbang1'
sourceSets {
  hello {
    java {
      srcDirs = ["src/hello/java"]
    }
  }
maxandersen commented 2 years ago

I really do not think the same action should be used to sync from build.gralde to java file and the java file to idea library. It's not symmetrical actions.

linux-china commented 2 years ago

I agree, too complicated for developers. What's your suggestion? just to keep DEPS to idea module in IDE?

If developers want to generate build.gradle, and it's easy with following command.

jbang edit --open=[editor] helloworld.java

I think build.gradle to DEPS not necessary, and I can remove these code.

maxandersen commented 2 years ago

the feature is interesting (similar could be done for maven) but should be in separate actions. so if interested in tuning that keep it in a separate action "Sync JBang with Gradle" or similar.

Also perfectly fine dropping it for now as we have no tests and there are so many edge cases I fear its going to be a nightmare to maintain.