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

Auto import builds option #6064

Merged
merged 10 commits into from Feb 16, 2024
Merged

Conversation

keirlawson
Copy link
Contributor

@keirlawson keirlawson commented Jan 30, 2024

// Don't spam the user with requests during rapid build changes.
notification.dismiss(2, TimeUnit.MINUTES)
Future.successful(WorkspaceLoadedStatus.Rejected)
if (userConfig().automaticImportBuild) {
Copy link
Contributor

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,.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@keirlawson keirlawson marked this pull request as ready for review February 5, 2024 20:12
@filipwiech
Copy link
Contributor

filipwiech commented Feb 5, 2024

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. 😉

@keirlawson
Copy link
Contributor Author

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?

@tgodzik
Copy link
Contributor

tgodzik commented Feb 6, 2024

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

@keirlawson
Copy link
Contributor Author

Ok, have switched to an enum to control the behavior, manually tested against Helix and seems to work well

@tgodzik
Copy link
Contributor

tgodzik commented Feb 6, 2024

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.

@keirlawson
Copy link
Contributor Author

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 :)

Copy link
Contributor

@filipwiech filipwiech left a 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! 👍

tables.dismissedNotifications.ImportChanges
.dismiss(2, TimeUnit.MINUTES)
Future.successful(BuildChange.None)
if (clientConfig.autoImportBuilds == AutoImportBuildKind.All) {
Copy link
Contributor

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)? 🙂

Copy link
Contributor Author

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],
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

notification.dismiss(2, TimeUnit.MINUTES)
Future.successful(WorkspaceLoadedStatus.Rejected)
if (
userConfig().automaticImportBuild == AutoImportBuildKind.Initial || userConfig().automaticImportBuild == AutoImportBuildKind.All
Copy link
Contributor

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). 🙂

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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). 👍

Copy link
Contributor

@kasiaMarek kasiaMarek left a 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.

…tion.scala

Co-authored-by: Katarzyna Marek <kasia@marek.net>
@kasiaMarek kasiaMarek merged commit 3228b3f into scalameta:main Feb 16, 2024
25 of 26 checks passed
@keirlawson keirlawson deleted the auto-import-builds branch February 16, 2024 08:10
@ckipp01 ckipp01 added the affects clients Use this if you are adding a new setting or making a change that will affect clients. label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects clients Use this if you are adding a new setting or making a change that will affect clients.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically import/reload build after changes
5 participants