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
Support global and local vendor completions #11395
Conversation
crates/nu-path/src/helpers.rs
Outdated
}; | ||
|
||
// global directory | ||
let global = std::env::var("NUSHELL_GLOBAL_VENDOR_COMPLETIONS_DIR") |
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.
We should probably limit the size of this env var name. Environment space isn't infinite in Windows.
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.
Any concrete suggestions? I agree that it's a bit long, but not long enough to actually make a difference when it comes to limits like that.
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.
Github marked this review as outdated, but the conversation itself here is not resolved, the var name is still as it was before.
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.
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.
That wouldn't allow for differentiating between the global dir and the user dir. What about NU_COMPLETIONS_DIR
for the user one, and NU_VENDOR_COMPLETIONS_DIR
for the one managed by the system package manager?
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.
What is the point of having a VENDOR one and one without VENDOR? Why do we care, this is just a place to put completions. We don't have that convention in nushell for any other config files. I'm not sure why we'd start with this?
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.
why not a NU_COMPLETION_DIRS: list<path>
? similar to NU_LIB_DIRS
for modules
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'd be ok with that too @amtoine. Then we just add a couple of default folders and make the default_config.nu match.
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.
yup, exactly 😋
from my experience, $env.NU_LIB_DIRS
and $env.NU_PLUGIN_DIRS
are pretty useful and practical objects and notions 👌
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 can see how that might be useful, but that also means that if a distribution changes the place where they place their completions and a user has overridden that var while including that folder, they will end up breaking it. I'd therefore be inclined to keep those separated.
If someone wants to modify this so that additionally to the system one a user one a list instead of a single directory, I'd prefer if that was done by someone else in a follow-up PR, to keep this one simpler.
Thanks. This is pretty good. Just a few minor issues mentioned above. We'll also need to see what others think about 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.
i think it would be great to add to default-env.nu
a line like
$env.NUSHELL_GLOBAL_VENDOR_COMPLETIONS_DIR = ...
to show the default 😋
871db82
to
21afa1e
Compare
With the |
21afa1e
to
a700ce5
Compare
Tested on windows too, works fine there as well (after a few little changes, which I've just pushed). |
it appears requested changes have been implemented
6b93bb2
to
14ac699
Compare
14ac699
to
22e3dac
Compare
Anything still needed here? |
I thought it was ready but remembered these items.
std::env::var("NU_VENDOR_COMPLETIONS_DIR") I believe we want to use the built-in nushell functions. I think that's We really need more eyes on this. |
Darren's right, However, see my comment in #11337. I think we should first think about the design. |
I think Jakub's |
That's also addressed by #11337 (comment):
I don't think that security concerns here are a valid concern: If you're concerned about the security of a piece of software, you shouldn't install it. If you want to try/test it, do so in a sandboxed environment. One concern I still have is this bit:
There should be a default for this, and the distributors should be able to override that during compile time. This default needs to be platform specific. If that needs to be overridden during runtime, it should happen in With all that said: Is someone interested in implementing that? I think not much from this can be re-used for the suggested design, and I don't see myself having time to implement this myself. |
I'm not a big fan of the compile-time configuration because instead of one Nushell binary, we'd have an array of potentially incompatible Nushell binaries. For example, the Nushell binaries downloaded from our releases / cargo install / compiled by yourself wouldn't have this distro-specific patch and might behave differently, leading to surprises (“Why are my completions suddenly not working?”). If it's kept only as a runtime config, the same Nushell binary works on every system identically. What is the problem of keeping NU_AUTOLOAD_DIRS as a runtime-only option (perhaps with a default value, but not compile-configurable)? Is setting an environment variable out of question for package maintainers? |
Setting an environment variable during compile time is easier than setting it at runtime. There is no default way to ensure a binary is invoked with a given environment variable. The closest there is would be The other point is: There are platform specific defaults that need to be set here, And regarding "If it's kept only as a runtime config, the same Nushell binary works on every system identically.": This assumes that the systems are identical. There are Linux Distributions which take a vastly different approach to the filesystem hierarchy. By not allowing them to override this at a compile time, you're making nushell increasingly hard to package. Not providing a compile time override won't stop distros from changing the default, you'll just make it harder for them to do so. |
Closing after discussions here and in #11337 |
Description
This adds both a global/system vendor completions dir, and a local one. The global one is primarily meant for the use with system package managers, such as the ones used by Linux distributions. The local one is specific to the user, and can be used for automatically including completions installed locally by the user.
The global/system vendor completions dir can be overridden at both compile time and run time, the local user one only at run time, as I don't see why a distribution would want to override that.
Fixes #11337
User-Facing Changes
Not sure how much users should see of this at all. This is primarily so that completions magically work when packages ship with them. If anyone has any ideas of how to document this properly for users, please, contribute that bit as well.
Tests + Formatting
I haven't added any new tests here, and I don't want to either. I've got quite limited time at the moment and spent way too much of it on this already, so if someone else could take over this bit, I'd be happy about that as well.
I have run
toolkit check pr
on my changes though, and that was happy.