-
Notifications
You must be signed in to change notification settings - Fork 339
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
Bazel Support #5138
Comments
While we can generate `.bsp/bazelbsp.json` by `cs launch org.jetbrains.bsp;bazel-bsp:2.6.1 -M org.jetbrains.bsp.bazel.instal.Install` https://github.com/JetBrains/bazel-bsp#easy-way-coursier Metals couldn't connect to the bazel-bsp because it wan't autoConnectable. This change enable Metals to see bazel-bsp as autoConnectable, and Metals will spawn and connct to bazel bsp if there's `.bsp/bazelbsp.json`. As @kpodsiad did in scalameta#3233 we should - reindex if the build configuration changed - I'm wondering we should check all *.bzl files and WORKSPACE and BUILD / BUILD.bazel files. And maybe we should honor the project view settings. - Auto install bazel-bsp when we see `WORKSPACE` file. scalameta#5138 partially fix for scalameta#5064
Nevermind, I misunderstood how to use projectview 😅 https://youtrack.jetbrains.com/issue/BAZEL-377 JetBrains/bazel-bsp#383 We can use Metals in Bazel project without project view feature, but I believe it is practically essential for a pretty large project. |
While we can generate `.bsp/bazelbsp.json` by `cs launch org.jetbrains.bsp;bazel-bsp:2.6.1 -M org.jetbrains.bsp.bazel.instal.Install` https://github.com/JetBrains/bazel-bsp#easy-way-coursier Metals couldn't connect to the bazel-bsp because it wan't autoConnectable. This change enable Metals to see bazel-bsp as autoConnectable, and Metals will spawn and connct to bazel bsp if there's `.bsp/bazelbsp.json`. As @kpodsiad did in #3233 we should - reindex if the build configuration changed - I'm wondering we should check all *.bzl files and WORKSPACE and BUILD / BUILD.bazel files. And maybe we should honor the project view settings. - Auto install bazel-bsp when we see `WORKSPACE` file. #5138 partially fix for #5064
Regarding automatically install
https://discord.com/channels/632642981228314653/1098559553571917944/1099008392841924618 |
Coming back to this. I think for project view we should pick it up automatically if it's present at root and maybe at a setting otherwise? What do you think? How often would users have the projectview file in another place? |
As a personal experience, I have a few projects in a large monorepository, and each has its own projectview. I store those in each project's directories outside VCS, although I could probably move them to the workspace root. I frequently switch between projects, and sometimes I have to work on multiple projects simultaneously, so having to manually change a setting every time would not be great. Ideally, I'd like Metals to detect projectview files automatically. E.g. if I open a file |
I think this is doable, maybe not as a first step, but as a follow up. @tanishiking what do you think, can we move with #3233 ? |
Yes, we can indeed move forward with #3233.
Tthis may not be feasible option. The common scenario, as far as I understand, involves creating multiple Therefore, it would be beneficial if Metals could provide a method for switching projectview file locations. Once the location is changed, the BSP server should restart with the newly specified projectview file. |
@tanishiking do you want to finish #3233 or do you want someone to take over? |
Could Metals handle multiple simultaneous BSP servers? From what I understand, they might end up communicating to the same Bazel process under wraps, correct? As a user, I don't really mind if a BSP server gets started behind the scenes whenever I open a file belonging to a component - as long as that doesn't involve something unnecessarily heavy, like recompiling all the relevant targets from scratch. I could also live with a separate Metals process for each component (spawned by Emacs as needed, with projectview selection also handled by Emacs), as long as those don't step on each other's toes (one Metals/BSP server process regenerating semanticdb or recompiling a common target shouldn't break the others). Not sure whether any of this is even remotely feasible. |
It may take some time, but can I finish up that? (if no one is interested in) 😃 |
We already do a similar thing for sbt meta builds, we have several BSP connection for each level of the build definition. Some work would be neccessary, but hopefully not too much. It's probably soemthing we should look at at some point |
bazel-bsp 2.7.1 introduces the fix for cleaning up previous diagnostics 🎉 I will finish up #3233 to automatically install bazel-bsp 2.7.1 soon. |
I spent some time to tweak #3233 so Metals automatically install bazel-bsp 2.7.1 and reindex the workspace when the configuration has changed. |
@tanishiking one thing I'm curious about, is how are you handling indexing the semanticdb files across Jars. One of the assumptions currently in BSP is that they all exist under a single output directory, which really isn't how Bazel works (i.e. instead it produces zillions of separate output directories for separate targets). |
Side note @tanishiking : I also started a separate Bazel BSP server project here, that I was aiming to be more made for Metals integration from the ground up. https://github.com/bazeltools/bsp4bazel. It's fully functional as BSP server, but I got busy on other stuff this year, so haven't had time to get back to it :( So quite a bit of work to finish integrating it into Metals fully. But let me know if useful for your efforts. |
As I understand it, SemanticDB support just got merged into rules_scala in bazelbuild/rules_scala#1508 which supersedes bazelbuild/rules_scala#1467 mentioned in this issue's description. |
I am so, so excited for this. Keep up the great work! |
I have created a BSP implementation for Bazel and it works well in the repositories I have tested with (type information, goto, maven dependencies, streamed diagnostics and so on), but is very new. |
Thanks for sharing! How does it compare to https://github.com/JetBrains/bazel-bsp ? |
I'll start off by saying I work in a project where we build Scala with Bazel, so I built the tool because I need it. Some things that come to mind are:
|
Thanks for the larger picture! We will most likely finish the current Bazel PR, but we will make sure that it's also easy to use other tools and it's as easy as setting up I would prefer to keep Jetbrain's PR as a default for now since it's done by an organization and much more likely to keep being maintained. If it turns up to be not enough for users, we might be able to add some more work into Mezel. Especially if there is a company willing to sponsor as we are a bit tight in terms of a number of maintained projects and the number of developers we can keep on open source. |
scalameta/metals-feature-requests#39
This issue aims to track the progress of enhancing Bazel support in the Metals. There are several tasks that need to be completed in order to achieve better integration with Bazel. The list of pending tasks is as follows:
build/publishDiagnostics
are always sent with PublishDiagnosticsParams.reset = false : BAZEL-375workspace/buildTargets
returns only a subset of build targets, and Metals will index only a subset of symbols.The text was updated successfully, but these errors were encountered: