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

Replace hand-written bsp4j and bsp4s with generated versions #555

Merged
merged 30 commits into from
Jul 17, 2023

Conversation

agluszak
Copy link
Collaborator

@agluszak agluszak commented Jun 23, 2023

Some things are going to break because bsp4j, bsp4s and the typescript definition of the protocol sometimes didn't agree one with another. In other cases the libraries were internally inconsistent because of copy-pasting.

What's going to break:

In bsp4j:

  • onConnectWithServer is removed - it wasn't a proper json-rpc notification anyway - probably a leftover from some older version? Also it wasn't defined in the spec at all.
  • MessageType.INFORMATION is renamed to MessageType.INFO. The spec clearly says INFO: https://build-server-protocol.github.io/docs/specification#messagetype
  • fields in JvmBuildTarget structure were optional in the protocol and bsp4s, so in the corresponding bsp4j class they were moved from constructor parameters to setters. We can either change (the protocol AND bsp4s) or bsp4j. I chose the latter option. But I don't know if these fields being optional make any sense.
  • analogous changes in the cpp extension, but it's not used by anyone anyway
  • DebugSessionParams had an obligatory dataKind which was illegal according to the spec

In bsp4s:

  • CleanCacheResult no longer has a message field. It wasn't defined in the spec.
  • all bsp enums now use value for getting the inner value (previously some used id, some used code and some used value)

In spec:

Non-breaking changes:

All of the changes above come from the fact that now everything is generated from the smithy model in a consistent way. Hand-written implementations were inconsistent in many places. I didn't introduce any special cases/hardcode anything. But as you can see, all of the breaking changes are very minor/simple.

In bsp4s there's a constant Bsp4s.ProtocolVersion and in bsp4j Bsp4j.PROTOCOL_VERSION with the supported protocol version.

To test this you'll need to do the following

  1. Run sbt generate
  2. Rest sbt test to show that all the normal tests are still passing, etc

@agluszak agluszak force-pushed the agluszak/generate-everything branch 3 times, most recently from de14105 to 1758f35 Compare June 28, 2023 12:46
@agluszak agluszak changed the title Replace hand-written bsp4j and bsp4s with generated versions (done, but waiting for the previous PR to be merged) Replace hand-written bsp4j and bsp4s with generated versions Jun 28, 2023
@agluszak agluszak marked this pull request as ready for review June 28, 2023 12:47
@agluszak agluszak force-pushed the agluszak/generate-everything branch from 1758f35 to 2986cbe Compare June 28, 2023 12:48
Copy link
Member

@jastice jastice left a comment

Choose a reason for hiding this comment

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

In this PR we have a lot of breaking method name changes, such as buildInitialize -> initializeBuild. From separate discussion, I understand this is for consistency of naming. I also understand we couldn't keep the current naming of everything and have it be both consistent and api/binary compatible. However I'd prefer to keep incompatible changes to a minimum. What do others think?

@agluszak
Copy link
Collaborator Author

I don't think there are that many users of our libraries, so introducing these (minor tbh - that's a few renames and moving setters to constructor parameters or vice versa in a few classes) breaking changes will not cause a leftpad incident ;)

@ckipp01
Copy link
Member

ckipp01 commented Jun 30, 2023

I'll try to review this early next week when I'm back, but since this does include some breaking changes I think we should also ping

Just so they are aware ASAP and can also provide some input on the breakage.

Also, can you include a few words/steps for others to test if this if they wanted? For example:

To test this you'll need to do the following

  1. Run this sbt command, which will generate X
  2. Rest this sbt command to show that all the normal tests are still passing, etc

This would be helpful to ensure a quicker review so people don't have to dig through it to find out how to run it.

@tgodzik
Copy link
Collaborator

tgodzik commented Jun 30, 2023

Could we put the renames into a separate commit, so that they are easier to review?

@agluszak
Copy link
Collaborator Author

Could we put the renames into a separate commit, so that they are easier to review?

not really, but I did my best to list all the breaking changes in the PR description

@jastice
Copy link
Member

jastice commented Jun 30, 2023

buildInitialize is renamed to initializeBuild and buildShutdown to shutdownBuild. Their params were named "InitializeBuildParams" and "ShutdownBuildParams", so to keep things consistent we either have to rename the method names or the params. All other params are named "${methodName}Params}". BTW, I think we should remove the "build" part of it altogether, because these methods are not related in any way to building. They are related to the lifetime of the server.

They are named based on the json-rpc method name, like build/initialize. Other methods such as buildTarget/resources still retain the name buildTargetResources in bsp4j. So I think we should try to be consistent in the name transformation and maybe rename the parameters instead.

in every extension buildTarget${name}Options method is renamed to ${name}Options (the base protocol doesn't use the buildTarget prefix in method names)

It does, as in above example

In ScalaWorkspaceEdit the list of changes is optional. That's how it was defined in the protocol ¯_(ツ)_/¯ (I agree, it doesn't make any sense, but again, we either break the protocol or the library)

The addition is still new, maybe we can fix it?

in bsp4s order of definitions is changed (from one seemingly random ordering to another seemingly random ordering; I can sort them alphabetically for example)

I guess alphabetical makes sense for minimal conflicts in future additions

constants are renamed from UpperCamelCase to SCREAMING_CASE (e.g. TaskDataKind.CompileReport -> TaskDataKind.COMPILE_REPORT). This one is easy to "un-break" if you insist.

UpperCamelCase is pretty idiomatic for constants in Scala

@agluszak
Copy link
Collaborator Author

agluszak commented Jun 30, 2023

It does, as in above example

Yes, of course you are right. I'll fix it then.

I guess alphabetical makes sense for minimal conflicts in future additions

I'll fix it in the next commit.

UpperCamelCase is pretty idiomatic for constants in Scala

This too.

@agluszak
Copy link
Collaborator Author

I reverted the renames and opened #562

@agluszak
Copy link
Collaborator Author

agluszak commented Jun 30, 2023

Question to SBT wizards: what should I do to have codegen and xtend tasks run automatically in sequence before each compile task?

@jastice
Copy link
Member

jastice commented Jun 30, 2023

Question to SBT wizards: what should I do to have codegen and xtend tasks run automatically in sequence after each compile task?

You could do that, but I don't think you'd want to. compile supports incremental compilation, the code gen afaik doesn't.

@agluszak
Copy link
Collaborator Author

There's also #506

@agluszak
Copy link
Collaborator Author

agluszak commented Jun 30, 2023

You could do that, but I don't think you'd want to.

Because the entire codebase for bsp4j and bsp4s are now generated, there's never a situation where you'd want to run a compile without running codegen and xtend beforehand.

@jastice
Copy link
Member

jastice commented Jun 30, 2023

Because the entire codebase for bsp4j and bsp4s are now generated, there's never a situation where you'd want to run a compile without running codegen and xtend beforehand.

I suggest creating a dedicated task for generating and compiling then to not mess with expected behavior of tasks too much. Something like

val buildGeneratedCode := {
  codegen.value
  xtend.value
  compile.value
}

My sbt is rusty, might not fully work like this

Copy link
Member

@jastice jastice left a comment

Choose a reason for hiding this comment

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

So I think we can live with some minor breaking changes on generated API level, so from my side it's good to go! I'd like to get feedback from the other tool maintainers though.

@agluszak
Copy link
Collaborator Author

agluszak commented Jul 5, 2023

I think all remaining issues have been addressed :) @ckipp01 @jastice @tgodzik @lefou

@agluszak
Copy link
Collaborator Author

agluszak commented Jul 5, 2023

Unfortunately our property tests are flaky... This current run failed because a URI generator generated an incorrect URI (not related to my changes in any way). (it was related, the order of constructor arguments was switched around in the previous PR) Some time ago a run failed because the test didn't stop after 6 hours. This happened to me locally a few times as well. Again, it's not related in any way to this PR.

@lefou
Copy link
Contributor

lefou commented Jul 5, 2023

I might have overlooked it, as this PR is quite large. Is there an API now, to get the implemented protocol version? Or did you decide to make version-specific artifacts?

@jastice
Copy link
Member

jastice commented Jul 6, 2023

I might have overlooked it, as this PR is quite large. Is there an API now, to get the implemented protocol version? Or did you decide to make version-specific artifacts?

I don't think we've decided anything :)
Adding a version API seems like the easier thing though. Any opinions?

@agluszak
Copy link
Collaborator Author

agluszak commented Jul 7, 2023

But there's always been a request for getting the BSP version: in the build/initialize request first the client says the version of BSP it uses and then the server replies with its BSP version

@jastice
Copy link
Member

jastice commented Jul 7, 2023

But there's always been a request for getting the BSP version: in the build/initialize request first the client says the version of BSP it uses and then the server replies with its BSP version

The issue here though is knowing which BSP version the library supports, as opposed to the server. It should be somehow clear or discernible from the programmer's perspective. It could be as simple as a hard coded string that can be reall easily navigated to.

@lefou
Copy link
Contributor

lefou commented Jul 7, 2023

But there's always been a request for getting the BSP version: in the build/initialize request first the client says the version of BSP it uses and then the server replies with its BSP version

The issue here though is knowing which BSP version the library supports, as opposed to the server. It should be somehow clear or discernible from the programmer's perspective. It could be as simple as a hard coded string that can be reall easily navigated to.

Exactly. I'd like to use that library hard-coded version to use in the BSP Server implementation to answer the question, which BSP version does this server speak.

@agluszak
Copy link
Collaborator Author

agluszak commented Jul 7, 2023

Ahh, I see now. Okay, so let me implement it.

@agluszak
Copy link
Collaborator Author

Implemented @lefou @jastice.

In bsp4s there's a constant Bsp4s.ProtocolVersion and in bsp4j Bsp4j.PROTOCOL_VERSION

@lefou
Copy link
Contributor

lefou commented Jul 10, 2023

Implemented @lefou @jastice.

In bsp4s there's a constant Bsp4s.ProtocolVersion and in bsp4j Bsp4j.PROTOCOL_VERSION

Great, thanks!

@jastice
Copy link
Member

jastice commented Jul 17, 2023

If there's no objections by Wednesday, let's merge this, okay?
@adpi2

@adpi2
Copy link
Member

adpi2 commented Jul 17, 2023

Thanks for notifying me. I won't have time to review this PR but I support the main idea and I have no objection to merge it.

build.sbt Show resolved Hide resolved
@agluszak agluszak merged commit 80daa16 into master Jul 17, 2023
5 checks passed
@agluszak agluszak deleted the agluszak/generate-everything branch July 17, 2023 18:29
@jastice
Copy link
Member

jastice commented Jul 17, 2023

6 months in the making! Thank you to everyone involved, especially @Baccata and @agluszak !

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.

None yet

7 participants