-
Notifications
You must be signed in to change notification settings - Fork 343
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
FR: Using jj
as library in third party projects
#3034
Comments
Thanks for asking! This is an important problem that we'll need to figure out sooner or later. I'm afraid I don't have to give a very detailed answer right now, but here are some points I'd like to make:
We have discussed the second problem a bit on Discord (see link below) a few times. One solution is to make the Because of problem (1), I would recommend subprocessing to the binary for now, especially if you want to do any mutating operations. An alternative is that you start refactoring the
We have a Discord server: https://discord.gg/dkmfj3aGQN. There are typically around 75 people there these days. |
Yes you're right. We'll probably need a well defined way to communicate with the binary then, either as a server or a subprocess like LSPs do I made helix-editor/helix#9643, using the |
I'd been wondering about the plans here. This seems related to the classic issue where it's hard to make changes to git's backend because not only do you have to update three implementations (git, libgit2, JGit), you also have to wait for Xcode and Visual Studio to update their libraries. Mercurial has a command server for this reason (though over there, Python startup speed is pretty slow -- not an issue that happens with jj.) Dynamic loading of backends seems like the cleanest solution, assuming the interface between |
Another option is similar to what sapling does. Sapling has an interactive smartlog which when run from the command line starts a web-based graphical interface, which is designed for use by humans. But in addition, the interactive smartlog webserver also exposes some REST-style and websocket routes which are used by the editor plugins. For example, the vscode editor plugin starts isl and then communicates with it via HTTP (see e.g. DiffContextProvider. Now, I don't know if jj plans any web-based interface for humans similar to the interactive smartlog, but there is a large overlap between functionality (at least on the backend side) with editor plugins and it might make sense to combine them. |
I mentioned elsewhere that we could provide a |
Oh, another thing to note, version differences between what is integrated and what is on the system could become a pain point. User machines are already a security hole, I think it's beyond the scope of these kinds of tools to ensure the user is actually getting jj ran and not something else in the same path. If they have a name conflict, they likely use enough tools where they can figure out how to resolve it. |
FWIW I've found that jj-lib operates at a useful level of abstraction to build a GUI client around; in particular, it's important to be able to recompose its primitives, rather than just executing a series of the same commands the CLI uses. Targeted higher-level additions would still be useful; there are definitely parts I've had to copy or reimplement. In particular, gg's gui_util.rs duplicates a lot of code from jj-cli's |
@gulbanana even if this is the case right now, if internal changes to how jj stores data are made and you're using an older version of gg with the latest jj you would run into issues. I think having a gRPC API or something like that which is kept stable is a lot easier in the long run than not being able to change internal structures. |
I'm not suggesting internal structures shouldn't change. Clients like
In short- while I'm sure a daemon with an RPC interface would be useful, I don't see it as a replacement for what jj-lib can do when used as a crate. It could provide a rich interface tailored to some specific client, but probably at the cost of being a semantic bottleneck for others. |
@wuzzeb The issue for To summarize a gRPC interface and a good library solve two very different goals and having one doesn't invalidate the use-case of the other. I assume that at some point As we're currently permanently unstable, I'd not worry about the "best" way forward as it is an issue for the eventual v1, we should accomodate both clients as best as possible. |
Is your feature request related to a problem? Please describe.
I would like to implement the
DiffProvider
trait inhelix
for Jujutsu, like it is for GitDescribe the solution you'd like
Overall I would like to be able to use
jj-lib
tohelix
usingimara-diff
repo.view_at_commit(...).parents()
or.children()
or equivalents in some wayI'm sure there are dozens of other "common" things that will be asked over time so it could be done in a new library on top of
jj-lib
that is intended for use by third parties without interfering with the core algorithms and data structures injj-lib
. Lots of helpers only available injj-cli
could be moved in that hypothetical lib for example.Describe alternatives you've considered
Documentation doesn't exist much but honestly that wasn't such a bother, rustdoc makes it easy to navigate code and the types are named mostly logically so it would make things easier but I'm not gonna blame Jujutsu for not having very expansive docs in a 0.x version :)
I tried to look into using
jj-cli
to use all the helpers and things available there but it wasn't much better: the entry point ofCliRunner::init()
only accepts moving forward through.run()
, returning anExitCode
, which makes it hard to do anything with it. I could use a channel for example, but for a diff in a single code file (so often very very small), that's overkill both in code and ergonomics.I could invoke
jj
as a subprogram, overriding the config to define some custom diff handler and go from there, but again, that's way more layers of abstractions and possible failures that needed. It would also meanhelix
needs to invokejj
as binary, trusting it's not malicious and actuallyjj
and not some third party command that happens to have the same name but doesn't at all does the correct thing.It would also be sad because both
jj
and `helix are developed in Rust, so it's not like I'm trying to interface two incompatibles languages here 😅Additional context
If you have any questions or channels on which rapid discussions is possible I can join them to help with that, if you have guidance to give I can try and help implement/document all that 😄
The text was updated successfully, but these errors were encountered: