intellij icon indicating copy to clipboard operation
intellij copied to clipboard

" File->Open" does not detect that a project is a bazel project

Open shs96c opened this issue 6 years ago • 34 comments

To help people get started quickly, it's not uncommon for people to check in .ijwb/.bazelproject files. However, once this is done, there's no way to actually use this:

  • "Bazel import project" will complain that the file already exists
  • "File->Open..." doesn't detect that this is a bazel project, so the plugin isn't enabled
  • "File->Import Project" doesn't list "Bazel" as an external model.

It seems clunky to check in the project config to a different location and then tell people to point to that.

shs96c avatar Sep 11 '19 10:09 shs96c

The option to overwrite the existing config would help get us over this hump.

shs96c avatar Sep 11 '19 10:09 shs96c

It seems clunky to check in the project config to a different location and then tell people to point to that.

That's exactly what we do. The copy we keep in the .ijwb/.bazelproject directory is the local config and is meant to be used for local edits.

You could also check in the other files in the .ijwb/.idea directory so File -> Open works.

chaoren avatar Sep 11 '19 15:09 chaoren

See this for what files in .ijwb/.idea should be checked in.

chaoren avatar Sep 11 '19 15:09 chaoren

It's not clear that the .ijwb/.bazelproject is user-specific, or that the .idea files need to be checked in (presumably the libraries directory isn't necessary?) It would be very helpful to have the "right thing to do" documented somewhere.

shs96c avatar Sep 11 '19 15:09 shs96c

It's documented in the link in https://github.com/bazelbuild/intellij/issues/1159#issuecomment-530442324. Checking in a project is a general IntelliJ thing.

chaoren avatar Sep 11 '19 16:09 chaoren

Though for bazel projects I would recommend keeping a .bazelproject file elsewhere and importing that.

chaoren avatar Sep 11 '19 16:09 chaoren

Though for bazel projects I would recommend keeping a .bazelproject file elsewhere and importing that.

Also see https://github.com/bazelbuild/intellij/blob/master/ijwb/ijwb.bazelproject and https://github.com/bazelbuild/bazel/blob/master/scripts/ij.bazelproject for examples.

jin avatar Sep 11 '19 16:09 jin

I'm trying to work out myself how to best share project settings etc with other users. I've read this thread a number of times, and I'm bewildered. I'm used to "knowing" (with IDE support) which files in .idea should be checked in. But of the other files, I have no idea:

  • There are files in .idea at the root. Presumably I should ignore the usual suspects in here?
  • There are files in .clwb/.idea and .ijwb/.idea too. Ditto?
  • What about .clwb/.bazelproject and .ijwb/.bazelproject ?
  • Ditto .clwb/.blaze, .ijwb/.blaze ? The latter are market orange in the IDE, but the CLion ones aren't.

Any insights welcomed: thanks!

mattgodbolt avatar Sep 24 '19 14:09 mattgodbolt

@mattgodbolt I'm working on a blogpost to demystify some of these: https://github.com/bazelbuild/bazel-blog/pull/200

We'll probably surface this in documentation soon as well.

jin avatar Sep 24 '19 14:09 jin

@shs96c (hi mate!)

It seems clunky to check in the project config to a different location and then tell people to point to that.

What does this even mean? You'd have a separate git repo with just that one file in it? And then how does it relate to the real repository? Would you mind explaining this: I can't seem to find any way to load an existing repository short of rm -rf-ing all the .iw* files and re-importing each time. Which is tiresome :)

mattgodbolt avatar Sep 24 '19 14:09 mattgodbolt

Thanks @jin!

mattgodbolt avatar Sep 24 '19 14:09 mattgodbolt

What does this even mean? You'd have a separate git repo with just that one file in it? And then how does it relate to the real repository?

It's in the same repository as the code. Look at this project for example: https://github.com/bazelbuild/intellij/blob/master/ijwb/ijwb.bazelproject

You just import that file and you can edit the project.

I can't seem to find any way to load an existing repository short of rm -rf-ing all the .iw* files and re-importing each time.

If you don't check in the .ijwb directory, but keep a separate .bazelproject file in your source directory, then you don't need to rm -rf them on a fresh checkout, you just import once and it's done. If you do check in the .ijwb directory, then make sure you check in everything necessary to open the project, including everything under .idea that you would normally check in.. This is only a problem if you check in part of the directory (in this case he only checked in the local .bazelproject file).

chaoren avatar Sep 24 '19 15:09 chaoren

Thanks @chaoren . We like to share project configuration information, debug configurations etc, so ideally we'd like to check in .ijwb and .clwb. It seems the trick is to not check in the .bazelproject file, but then check in the normal files in .jiwb/.idea etc?

If so, how does one open the project the first time? When I tried, CLion tried to open the directory as a new project, creating a top-level .idea directory (which confused me). Thanks again

mattgodbolt avatar Sep 26 '19 14:09 mattgodbolt

It seems the trick is to not check in the .bazelproject file, but then check in the normal files in .jiwb/.idea etc?

No you do need the .bazelproject file. You also need all of .ijwb/.blaze. BlazeImportSettings from .ijwb/.idea/workspace.xml is required for the project to be identified as a bazel project, but unfortunately workspace.xml is one of the files you usually don't want to share because it contains user specific stuff.

If all you need to share is debug configurations, we have a way of sharing that via the .bazelproject file.

chaoren avatar Sep 26 '19 16:09 chaoren

I think the trick is the exact opposite: check in the .bazelproject as an example, and have people load that. That way, you don't need any of the .ijwb or similar files. You can also keep the .idea directory to a minimum too.

shs96c avatar Sep 26 '19 16:09 shs96c

Yeah, sorry for the confusion. See the two options given in https://github.com/bazelbuild/intellij/issues/1159#issuecomment-534623904

I was responding to this:

ideally we'd like to check in .ijwb and .clwb. It seems the trick is to not check in the .bazelproject file

If he wants to check in .ijwb then he needs to keep the .bazelproject file under it.

We do recommend not checking in .ijwb at all though. All project configuration should be shareable via a separate .bazelproject file checked in elsewhere in your source, and you just import that when you open the project.

chaoren avatar Sep 26 '19 17:09 chaoren

Two thoughts:

  1. I think (and have advocated for it in a different issue) that import bazel project should check to see if a ijwb/ijwb.bazelproject exists and if so then it shoudl default to the radio button of "Import project view file" with this value. This is to ease and promote this pattern of working together. The default filename can of course be different but it needs to be one and documented.
  2. Additionally I think the original problem the OP describes is still a big issue when you want to open an project you've opened before (and so you have .ijwb folder for it) but it's no longer in your recently opened (because you work with many workspaces). Because you can't use "File->Open" then you have to rm -rf .ijwb and then import from scratch. This is a problem.

ittaiz avatar Jan 01 '20 14:01 ittaiz

Nowhere here or in the corresponding blog post mentioned (https://blog.bazel.build/2019/09/29/intellij-bazel-sync.html) do I see @mattgodbolt's question answered.

If we wish to share .idea/codeStyles what is the recommended way of doing so? From what I've gathered it is impossible to share them in .ijwb/.idea because then opening a Bazel project for the first time will not be recognized as a Bazel project.

So then the solution is putting a top level .idea directory under version control and having other developers manually import these into their .ijwb directory?

CarsonBradshaw avatar Apr 06 '20 23:04 CarsonBradshaw

I've struggled with putting IDE configuration for Bazel projects under version control as well. I'll get into my workarounds, although I don't think they're great.

The Exploring the IntelliJ Bazel Plugin's Sync Process blog post mentioned above has this to say:

The .ijwb directory is not completely portable. Files like .bazelproject and codeStyleConfig.xml can be shared project-wide, but workspace.xml and .workspace.iml should be user-specific.

In general, extract .bazelproject file out of .ijwb/ to version control it, and follow JetBrains' recommendations on checking in specific files in the .idea directory.

For the .bazelproject file, it's somewhat reasonable to put that somewhere else such as ijwb/ijwb.bazelproject, similar to this repo.

For the IntelliJ configuration files, though, I don't believe anything under .idea/ is going to be used, only directories such as .ijwb/.idea/. I have two approaches, neither of which I think is ideal:

1. Keep IDEA config in .ijwb/.idea/ and check that into version control
You have to instruct people setting themselves up on a repo the first time to

  1. Run rm -rf .ijwb/ (!!!)
  2. Open IDEA and go through Bazel project import using the existing project view file ijwb/ijwb.bazelproject
  3. Close IDEA
  4. Run git checkout .ijwb/ to restore the deleted config files you've kept under version control
  5. Reopen IDEA

The upshot is that once they're set up their IDE configuration will stay consistent with upstream.

2. Put IDEA config somewhere else like .idea/
Again you need to provide some user instructions:

  1. Open IDEA and go through Bazel project import like in the first approach
  2. Close IDEA
  3. Run git ls-files .idea | while read -r file; do mkdir -p .ijwb/$(dirname $file) && cp $file .ijwb/$file; done (or put that in a script and have them run it)
  4. Reopen IDEA

While at least you aren't telling users to delete a directory, the downside of this approach is that the configuration under .ijwb/.idea/ won't stay in sync with upstream, so configuration can drift.

All in all, I think approach 1 is the most workable, but it's obviously not ideal.

brymck avatar Apr 09 '21 13:04 brymck

@jin it looks like you wrote the blogpost. Are @brymck's workarounds the best recommended ways to achieve this?

If they are, then it looks like the blog post is wrong / misleading - it implies checking in files inside .idea should "just work". Would a PR to update the blog be reviewed/accepted?

dhalperi avatar Mar 10 '22 21:03 dhalperi

The blogpost was written years ago, and I've lost the context (and no longer work on the IDE plugin) to make recommendations on this.

@alice-ks Are there documentation for current best practices to sync config directories?

jin avatar Mar 14 '22 08:03 jin

I am so confused as to how to "just open" a project with an existing view file and .ijwb path. Is this documented?

aryeh-looker avatar Feb 26 '23 00:02 aryeh-looker

Contextual help could be improved too -- i.e. using the error dialog in the last screenshot to help the user understand how to properly import an existing project.

image image image image

aryeh-looker avatar Feb 26 '23 00:02 aryeh-looker

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

github-actions[bot] avatar Jan 05 '24 01:01 github-actions[bot]

Should be listed as awaiting maintainer

On Thu, Jan 4, 2024 at 17:55 github-actions[bot] @.***> wrote:

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team @.***/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

— Reply to this email directly, view it on GitHub https://github.com/bazelbuild/intellij/issues/1159#issuecomment-1878004208, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEAQT4D4WBOB74BSVHPPO3YM5MPTAVCNFSM4IVR6NOKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBXHAYDANBSGA4A . You are receiving this because you commented.Message ID: @.***>

dhalperi avatar Jan 05 '24 14:01 dhalperi

@bazelbuild/triage can you take the needed action if any?

dhalperi avatar Jan 06 '24 01:01 dhalperi

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

github-actions[bot] avatar Jul 07 '24 02:07 github-actions[bot]

What evidence do you have that it’s been resolved? I don’t see any PRs tagged against this issue? These bots are big eff yous to your users.

On Sat, Jul 6, 2024 at 19:06 github-actions[bot] @.***> wrote:

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

— Reply to this email directly, view it on GitHub https://github.com/bazelbuild/intellij/issues/1159#issuecomment-2212267623, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEAQTZ2V444TEVBIYGOTXDZLCPCPAVCNFSM4IVR6NOKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRRGIZDMNZWGIZQ . You are receiving this because you commented.Message ID: @.***>

dhalperi avatar Jul 07 '24 23:07 dhalperi

When this happened 6 months ago, I noted that this issue is labeled incorrectly and should be tagged awaiting-maintainer so that it won't get auto-closed. I tried @bazelbuild/triage last time, maybe @mai93 can do it/

dhalperi avatar Jul 08 '24 15:07 dhalperi

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

github-actions[bot] avatar Jan 08 '25 02:01 github-actions[bot]