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
Auto import builds option #6064
Conversation
// Don't spam the user with requests during rapid build changes. | ||
notification.dismiss(2, TimeUnit.MINUTES) | ||
Future.successful(WorkspaceLoadedStatus.Rejected) | ||
if (userConfig().automaticImportBuild) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we only import automatically at first or also later on?
If we want to always import automatically after changes to build files I would suggest starting it after the focused document changes, as otherwise it will be imported on each saved change, maybe missing some of the changes while the import is underway,.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow, you're suggesting we don't wait for the document (presumably a build.sbt
) to be saved, but instead just be edited? Or are you saying we should only run when the doc is saved and has also received an update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is if someone has auto save on or saves maniacally like me 😅 In that case the import will be started at first save and later changes will be ignored until the first import finishes. This might not be an issue if someone controls it well, but would be good to avoid surprises here anyway. So instead we could do only import if the build file is not currently focused, which would indicate the user stopped editing the build definition.
An easier solution would be to do automatic import only at the very first import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I follow you now. I feel like only doing things on unfocus is probably also liable to be surprising. I think just scoping this to the initial import as you suggest is probably the most straightforward solution. I guess in practice that means reverting the changes to Indexer
whilst retaining these ones to BloopInstall
if I've understood correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked and I think you are right, otherwise it might be really hard to get right.
Hey @keirlawson, thank you for a great contribution, this will not only be a nice option for all the users, but it should make experience of using Metals with Helix one step better! 👍 Do you think it would make sense to make it so that this option not only performs the initial, very first build import on a fresh project, but also re-imports on each Metals start if it detects that there were any changes? It should be much simpler and safer than the already discussed on-the-fly import, but I think it would make the feature even more useful (and improve the Helix integration even more). 🙂 Asking @tgodzik too of course. 😉 |
Yea I'm a Helix user as well and this was part of my motivation. Given the workflow concerns of @tgodzik though I wonder if its best to have two settings, one just for the initial import per this PR, and another for switching on auto-import in general? |
I would rather avoid having two settings, we could have an enum instead if needed. Or ideally we would figure out the UX so that we can just have it on and off |
Ok, have switched to an enum to control the behavior, manually tested against Helix and seems to work well |
Ok cool! I will merge this next week after the release if it's not a problem. |
Whatever's easiest :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @keirlawson for adding the extended configuration (always import), this will be really helpful! 👍
metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala
Outdated
Show resolved
Hide resolved
tables.dismissedNotifications.ImportChanges | ||
.dismiss(2, TimeUnit.MINUTES) | ||
Future.successful(BuildChange.None) | ||
if (clientConfig.autoImportBuilds == AutoImportBuildKind.All) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the problem that @tgodzik has mentioned previously (potentially missed import in case of multiple build changes in quick succession), maybe a future improvement would be to always save the last "intent" to import (like a checksum?) and check if it has been changed in the meantime after the currently ongoing import is finished (poor man's event queue)? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I was thinking of something like that, would be interested to look at what rust-analyzer does here. That said keen to keep this PR simple, this could be a future iteration
@@ -79,6 +80,7 @@ final case class InitializationOptions( | |||
disableColorOutput: Option[Boolean], | |||
doctorVisibilityProvider: Option[Boolean], | |||
bspStatusBarProvider: Option[String], | |||
autoImportBuild: Option[AutoImportBuildKind], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a user rather than a client setting? I think that many users no matter the client don't want to auto import, because they switch to sbt
right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately so far as I can see Helix, which is one of the main use cases for this I suspect, doesn't seem to have a mechanism for setting user settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok digging in a bit deeper looks like helix does support didChangeConfiguration
so will revert to configuring via user settings
This reverts commit 9e13b15.
…nOptions.scala Co-authored-by: Filip Wiechowski <filip.wiechowski@gmail.com>
e90ef0c
to
90304ac
Compare
This reverts commit 7a17c82.
notification.dismiss(2, TimeUnit.MINUTES) | ||
Future.successful(WorkspaceLoadedStatus.Rejected) | ||
if ( | ||
userConfig().automaticImportBuild == AutoImportBuildKind.Initial || userConfig().automaticImportBuild == AutoImportBuildKind.All |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late question, but was just wondering if this will only work with Bloop, or other build servers as well (like direct BSP with sbt, mill, etc.)? Asking especially in context of the upcoming changes which would allow the user to choose the preferred build server and skip initial import with Bloop in #6121 (plus I believe there are plans to switch to sbt by default anyway). 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far as I can see looking through the code only Bloop (and possibly Bazel? https://github.com/scalameta/metals/blob/main/metals/src/main/scala/scala/meta/internal/builds/BazelBuildTool.scala#L155-L156) send a request to the user for an initial import. @kasiaMarek @tgodzik maybe you can confirm I've got this right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and @filipwiech is probably right that in #6121 it should be changed to be consistent with what we do in Bloop and I should adjust it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, if it's going to be aligned across the board in @kasiaMarek's PR, then I think it's fine (otherwise I guess it would be nice to at least change the setting description and documentation to mention the Bloop limitation). 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise I'd merge this.
metals/src/main/scala/scala/meta/internal/metals/UserConfiguration.scala
Outdated
Show resolved
Hide resolved
…tion.scala Co-authored-by: Katarzyna Marek <kasia@marek.net>
Fixes scalameta/metals-feature-requests#310