Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project tree shows confusing directory structure #437

Closed
aherrmann opened this issue Nov 7, 2018 · 15 comments
Closed

Project tree shows confusing directory structure #437

aherrmann opened this issue Nov 7, 2018 · 15 comments

Comments

@aherrmann
Copy link

IntelliJ shows a confusing picture of the directory structure in the project tree pane.

  • Example 1
    The following directory tree

    src
    ├── main
    │   ├── resources
    │   └── scala
    └── test
        └── scala
    

    is shown like this:

    one "scala" folder under "src/main", one under "src"

    I.e. the test directory is omitted, and it is not obvious where the lower scala folder belongs to.
    I would expect the project tree to match the actual directory structure.

  • Example 2
    The following directory tree

    src
    ├── main
    │   └── scala
    └── test
        └── scala
    

    is shown like this:

    two "scala" folders under "src"

    I.e. the main and test directories are omitted. It is not obvious where the two "floating" scala folders belong to.
    I would expect the project tree to match the actual directory strucuture.

  • Version information
    IntelliJ:

    IntelliJ IDEA 2018.2.5 (Community Edition)
    Build #IC-182.4892.20, built on October 16, 2018
    
    JRE: 1.8.0_152-release-1248-b6-amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    

    Bazel plugin:

    2018.10.08.0.2
    

A full reproduction of this issue is available here: https://github.com/aherrmann/reproduce-intellij-project-view-issue

@brendandouglas
Copy link
Contributor

I believe this is an upstream bug with IntelliJ. If you import that exact same project as a plain IntelliJ project (without the bazel plugin) does it still occur?

@aherrmann
Copy link
Author

@brendandouglas If I import it as a regular IntelliJ project (without the bazel plugin) then I get the following "Project" tree:
no-bazel-project
And the "Packages" tree looks like this:
no-bazel-packages

@brendandouglas
Copy link
Contributor

I don't mean importing from scratch, but importing the exact project created by the bazel plugin, but with the bazel plugin disabled (you should see a 'Required plugins weren't loaded' error).

When I do that, and check 'compact empty middle packages' (the source of this problem), I see all main/test files and directories disappear, except src/main/resources/dummy.txt

@brendandouglas
Copy link
Contributor

So there's an upstream bug and/or a bug with the project definition written by the bazel plugin.

The project definition looks valid to me, so this appears to be an upstream bug.

@aherrmann
Copy link
Author

@brendandouglas Okay, so, a workaround for this issue is to disable "compact empty middle packages". I can confirm that this produces the expected project tree.

I've tested loading the project with the Bazel plugin disabled, and as you say the main and test folders disappear, except for dummy.txt. It looks like this for me:
disable-bazel-plugin-no-compact

The project definition looks valid to me, so this appears to be an upstream bug.

I'm afraid, I don't know enough about IntelliJ to make that judgement. Could I ask you to file an issue for this upstream? I'm happy to provide additional information if required.
Or, if that's not possible, could you point me to the relevant information that should be included in the upstream ticket?

@brendandouglas
Copy link
Contributor

@aherrmann if you check in the project definition, and point to that in an upstream ticket it should be enough to go on.

@ittaiz
Copy link
Member

ittaiz commented Nov 11, 2018 via email

@gseitz
Copy link

gseitz commented Nov 13, 2018

I don't think it's a bug in IntelliJ. The issue is that the root folder is added as a Source Folder in Intellij. This means IntelliJ interprets every sub-folder as a java-like "package". Removing the root folder from the module setup manually yields the expected results:
image

Notice that this also changed the icons for the folder src and main, as they are now regarded as normal directories rather than java-like packages.

@brendandouglas
Copy link
Contributor

Thanks for tracking it down. That still seems like a bug in IntelliJ. What if this test project actually had nested source directories?

@gseitz
Copy link

gseitz commented Nov 13, 2018

Conceptually, having nested source directories doesn't make much sense for a conventional maven-like project structure. Multiple source directories that don't overlap is fine (e.g. src/test/scala and src/main/scala).
I think the assumption that each directories entry is by default a source directory doesn't hold when it comes to conventional java/scala project structures.
That said, possibly the maven inspired project structure doesn't fit how bazel works to begin with, and trying to square this particular circle is doomed to lead to issues down the line.

@brendandouglas
Copy link
Contributor

I agree it wouldn't be common, and we should stop marking the root directories as source roots by default.

@ittaiz
Copy link
Member

ittaiz commented Nov 13, 2018 via email

@brendandouglas
Copy link
Contributor

Marking the root directory as a source root regardless of its contents was a hack (which happened to make sense internally). We also detected source roots during sync by looking for java-like sources built by bazel targets in the project, and checking their package path using a set of heuristics (up to actually reading the file contents via our aspect).

You shouldn't notice any regression when the release after next lands, or need to manually mark source roots.

@ittaiz
Copy link
Member

ittaiz commented Nov 14, 2018 via email

@aherrmann
Copy link
Author

Sounds great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants