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

improvement: add custom bsp as possible build tool #5791

Merged
merged 5 commits into from
Dec 18, 2023

Conversation

kasiaMarek
Copy link
Contributor

@kasiaMarek kasiaMarek commented Oct 26, 2023

Previously: For custom BSP we would still use some other build tool if discovered.
Now: Custom BSP is in itself treated as a build tool, we look for .bsp configs in:

  1. root directory,
  2. custom project root directory,
  3. bspGlobalInstallDirectories.

As a followup we should deduplicate code in build servers and build tools discovery and selection:

  1. BspServers.findAvailableServers repeats a lot from BuildTools.loadSupported,
  2. build tool selection adjust build server selection when needed and the other way around.

@kasiaMarek kasiaMarek force-pushed the custom-bsp branch 3 times, most recently from 64eaad4 to f64429e Compare October 31, 2023 15:55
@kasiaMarek kasiaMarek force-pushed the custom-bsp branch 3 times, most recently from eac1a09 to 7e18b77 Compare November 9, 2023 10:22
@kasiaMarek kasiaMarek marked this pull request as ready for review November 9, 2023 11:29
override val executableName: String,
override val projectRoot: AbsolutePath,
) extends BuildTool {
override def digest(workspace: AbsolutePath): Option[String] = Some("OK")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the digest of the json, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so as well. But then again on change we do workspaceReload and that would require a reconnect to have the changes apply.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also do a custom logic if the current server's json changes to reconnect. Would that make more sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, I added this logic.

Comment on lines 126 to 130
val bspFolder = workspace.resolve(".bsp")
val root = customProjectRoot.getOrElse(workspace)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val bspFolder = workspace.resolve(".bsp")
val root = customProjectRoot.getOrElse(workspace)
val root = customProjectRoot.getOrElse(workspace)
val bspFolder = root.resolve(".bsp")

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we always create .bsp in the root I assumed we search only there. The root only says where the bsp command will be run. We can change this behaviour though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally, we would look for .bsp in the custom root also.

@@ -28,7 +28,6 @@ class PopupChoiceReset(
val result = if (value == BuildTool) {
scribe.info("Resetting build tool selection.")
tables.buildTool.reset()
tables.buildServers.reset()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reset the choice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we only change the build tool? So either we trust the user to be reasonable and not chose mill build tool for sbt build server. I they do it is still mostly fine. If we reset buildServer choice we'd have to do full reconnect (quickConnect & slowConnect) to be connected to correct build server for metals state consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say that we have to servers in .bsp without resetting we will have to manually do the switch to the other tool, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since those "forceBuildServer", so it will switch automatically in slowConnect.

@@ -918,8 +944,7 @@ class MetalsLspService(
.sequence(
List[Future[Unit]](
Future(buildTools.initialize()),
quickConnectToBuildServer().ignoreValue,
slowConnectToBuildServer(forceImport = false).ignoreValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how we should rename these methods. firstConnectToBuildServer and connectToBuildServer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, though I'm not sure those names explain it much better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it later on if anyone has a good idea about the names

@kasiaMarek kasiaMarek force-pushed the custom-bsp branch 2 times, most recently from e5de41b to 8e60ab1 Compare November 21, 2023 11:41
@kasiaMarek kasiaMarek requested a review from tgodzik November 21, 2023 11:42
@kasiaMarek
Copy link
Contributor Author

I wonder if this line:

name <- tables.buildServers.selectedServer(md5)
even makes sense anymore. I don't see that we ever chooseServer with anything else than md5 = "EXPLICIT". I don't know what was the original reasoning behind this. I'm guessing it had something to do with discovering new .bsp configs.

Copy link
Member

@jkciesluk jkciesluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love these changes!

About didChangeWatchedFiles (in line 1357), do we still need this check for creating file in .bsp directory, if it's already handled in the other didChangeWatchedFiles method?
Also, I think we can remove starting fileWatcher in supportedBuildTool, since we now have .bsp directory in Config

@@ -306,17 +305,6 @@ class TestingClient(workspace: AbsolutePath, val buffers: Buffers)
// NOTE: (ckipp01) Just for easiness of testing, we are going to just look
// for sbt and mill builds together, which are most common. The logic however
// is identical for all build tools.
def isSameMessageFromList(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover comment above

@kasiaMarek kasiaMarek requested a review from jkciesluk December 5, 2023 09:33
Copy link
Member

@jkciesluk jkciesluk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but otherwise looks good!

case buildTool: BuildServerProvider
if buildTool.buildServerName.contains(buildServerName) =>
true
case buildTool => buildTool.executableName == buildServerName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment when this would be different?

@@ -918,8 +944,7 @@ class MetalsLspService(
.sequence(
List[Future[Unit]](
Future(buildTools.initialize()),
quickConnectToBuildServer().ignoreValue,
slowConnectToBuildServer(forceImport = false).ignoreValue,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it later on if anyone has a good idea about the names

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@kasiaMarek kasiaMarek merged commit 73706fa into scalameta:main Dec 18, 2023
24 of 25 checks passed
jkciesluk added a commit to jkciesluk/metals that referenced this pull request Dec 21, 2023
Since scalameta#5791 Pants can be used as custom BSP.
This should be more reliable, since most of the support was alredy removed.
jkciesluk added a commit that referenced this pull request Dec 21, 2023
Since #5791 Pants can be used as custom BSP.
This should be more reliable, since most of the support was alredy removed.
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

Successfully merging this pull request may close these issues.

3 participants