-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add Steel as an optional plugin system #8675
base: master
Are you sure you want to change the base?
Conversation
Can i just point out janet, the language was written by the same guy who made fennel(compiles to regular lua but uses s-expression and few more things), hear is an introduction It also has a rust bindings |
As far as I understand those bindings suffer from the same problem as bindings to Guile a while ago: languages internally use setjmp/longjmp and that can skip destructors in Rust |
I didn't know that, sorry... |
I'm trying to write a (require (prefix-in helix. "helix/commands.scm"))
(require (prefix-in config. "helix/configuration.scm"))
(require (prefix-in term. "term.scm"))
(provide save-without-formatting)
(define (save-without-formatting)
(config.auto-format #f)
(helix.write)
(config.auto-format #t)) But the problem is, I want it to preserve whatever option
But any idea on how to get the value of a config option in steel? |
So the reason for that would be that this sets the value to the status line, but it doesn't actually return anything: // Fetch the current value of a config option and output as status.
fn get_option(
cx: &mut compositor::Context,
args: &[Cow<str>],
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}
if args.len() != 1 {
anyhow::bail!("Bad arguments. Usage: `:get key`");
}
let key = &args[0].to_lowercase();
let key_error = || anyhow::anyhow!("Unknown key `{}`", key);
let config = serde_json::json!(cx.editor.config().deref());
let pointer = format!("/{}", key.replace('.', "/"));
let value = config.pointer(&pointer).ok_or_else(key_error)?;
cx.editor.set_status(value.to_string());
Ok(())
} There would just need to be a version of this function that actually returns the value. I can push something up in a few hours. |
Think I found a bug, because I couldn't call the function in steel. |
FYI, if there's any other plugin authors out there, here's a pretty useful function to re-load the current file into the steel repl: (require (prefix-in helix.editor. "helix/editor.scm"))
(require "cogs/package.scm")
(provide load-current-steel-file-into-helix)
;;@doc
;; reloads the path of the current buffer, pretty useful for developing plugins for helix
(define (load-current-steel-file-into-helix)
(define current-path
(let* ([focus (helix.editor.editor-focus)]
[focus-doc-id (helix.editor.editor->doc-id focus)])
(helix.editor.editor-document->path focus-doc-id)))
(load-package current-path))
|
builtin_configuration_module.push_str(&format!( | ||
r#" | ||
(provide get-config-option-value) | ||
(define (get-config-option-value arg) | ||
(helix.get-config-option-value *helix.cx*)) | ||
"#, | ||
)); | ||
|
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.
Hi @mattwparas, thanks for your work on this PR! 🎉
I noticed that in the call to helix.get-config-option-value
in the code-gen, the argument arg
is unused. From looking at the surrounding context, it seems like this argument is necessary to ensure being passed to the helix.get-config-option-value
.
Would it make sense to pass the argument like this: (helix.get-config-option-value *helix.cx* arg)
? Let me know if I can help further with this. Thanks again for the great work!
get_option_value: fix argument
I have an idea, for people who build plugins, suffix your plugin names with ".hx" basically all neovim plugins end in "plugin.nvim", so let's do something like that and have "plugin.hx" :D |
If I recall that is the file extension used by Haxe code files. |
plugin.hx is just the plugin's name, it isn't used for a file extension |
This thread is really long, so I haven't checked the history. Who's working on plugins? Maybe we could make an awesome-helix repository that links Helix distributions & plugins. Would also be nice to have it on the website |
I think people are waiting until release to start working on plugins, since there may be breaking changes |
I would absolutely adore that. |
Not to put the horse before the cart too much, but I do wonder about the distribution mechanism for packages. Other editors have entire package managers just for plugins. I can’t say I miss the days of deciding which Neovim plugin manager to use. It would be cool if there was a sensible default. |
I have a functioning package manager working on a branch for steel, which will work for helix as well. Trying to dog food it a bit and iron out some details before releasing. At the moment the distribution mechanism is just git urls, which will probably work to start. |
I think it shouldn't be bundled by default, as people might want to use other package managers. I'm going to use home-manager for example and a builtin But a recommended plugin would be great, for people who want the default experience |
That’s a good point. I would use home-manager too. |
I think it's fine if it's bundled by default, but not enabled by default(maybe you meant it that way, and I misread). Besides there are plenty of things in home-manager that do ship with a package manager, like Node or even Emacs comes with |
As a happy (lurking) user I'd like to throw in vote on the package manager discussion... IMO it should be installed and enabled by default but easy to disable. I don't think standalone environment managers like home-manager are that pervasive and most users would benefit from having package management be a solved issue that they didn't have to consider. Thanks. |
Including modules in steel is really quite simple; just tell steel where to look for them. Given that flexibility (for better or for worse), it means that no one package management solution will be the only way to do things. I'm hoping to provide a very sensible and functional default, but if you'd like to use another solution you should be more than welcome to. I myself don't use nix, so rest assured we'll have something that works for non nix users |
I guess that straight.el's comparison to use-package might come useful when discussing what's needed from the plugin management system, but starting from reading a single directory configured at startup seems flexible enough for plugin systems to proliferate and explore a common plugin definition, config, and versioning system. Being able to configure that single directory is important, on Emacs trying out different configs or patches/fixes to existing ones and such was painful enough that chemacs and chemacs2 came out to help define what configuration and set of plugins should be used. |
Having a default package manager is one of the greatest feature in new language in my opinion, it standardize and regulate stuffs. It's good to have different possibility but it should be an option and you shouldn't have to make a choice in the first place to try stuff. Having a lot of possibility when it comes to plugin management in neovim is, in my opinion, a weakness concerning beginner as every plugin will have different instruction of installation and it's a real pain when you start your nvim journey |
Will steel allow something like this ?
|
I was thinking what kind of plugins would be really nice to have when Helix has a plugin system. So I browsed Dotfyle Neovim Plugins for quite a while. Most of the features I'd want Helix either already has, PRs already exist to add those features, or doesn't make sense to be in core. But those that don't make sense in core would still be nice features that could exist as plugins. So I feel like plugins which target specific tooling or languages and don't make an overall impact on the editor are the perfect example of what Helix plugins could be used for. For example, it would be nice to have an SQL query builder within Helix. But it doesn't make sense for that to be anything but a plugin, for example Once this PR drops, I may wish to develop a plugin so I'm putting this list I've compiled of nice-to-have plugins down here. Feel free to add to it or use it for inspiration.
|
The two plugins I would really like to see is something like hardtime.nvim and precognition.nvim. These would really help beginners learn commands |
More ideas of plugins that would be very nice:
|
Notes:
Opening this just to track progress on the effort and gather some feedback. There is still work to be done but I would like to gather some opinions on the direction before I continue more.
You can see my currently functioning helix config here and there are instructions listed in the
STEEL.md
file. The main repo for steel lives here, however much documentation is in works and will be added soon.The bulk of the implementation lies in the
engine.rs
andscheme.rs
files.Design
Given prior conversation about developing a custom language implementation, I attempted to make the integration with Steel as agnostic of the engine as possible to keep that door open.
The interface I ended up with (which is subject to change and would love feedback on) is the following:
If you can implement this, the engine should be able to be embedded within Helix. On top of that, I believe what I have allows the coexistence of multiple scripting engines, with a built in priority for resolving commands / configurations / etc.
As a result, Steel here is entirely optional and also remains completely backwards compatible with the existing toml configuration. Steel is just another layer on the existing configuration chain, and as such will be applied last. This applies to both the
config.toml
and thelanguages.toml
. Keybindings can be defined via Steel as well, and these can be buffer specific, language specific, or global. Themes can also be defined from Steel code and enabled, although this is not as rigorously tested and is a relatively recent addition. Otherwise, I have been using this as my daily driver to develop for the last few months.I opted for a two tiered approach, centered around a handful of design ideas that I'd like feedback on:
The first, there is a
init.scm
and ahelix.scm
file - thehelix.scm
module is where you define any commands that you would like to use at all. Any function exposed via that module is eligible to be used as a typed command or via a keybinding. For example:This would then make the command
:shell
available, and it will just replace the%
with the current file. The documentation listed in the@doc
doc comment will also pop up explaining what the command does:Once the
helix.scm
module isrequire
'd - then theinit.scm
file is run. One thing to note is that thehelix.scm
module does not have direct access to a running helix context. It must act entirely stateless of anything related to the helix context object. Runninginit.scm
gives access to a helix object, currently defined as*helix.cx*
. This is something I'm not sure I particularly love, as it makes async function calls a bit odd - I think it might make more sense to make the helix context just a global inside of a module. This would also save the hassle that every function exposed has to accept acx
parameter - this ends up with a great deal of boilerplate that I don't love. Consider the following:Every function call to helix built ins requires passing in the
cx
object - I think just having them be able to reference the global behind the scenes would make this a bit ergonomic. The integration with the helix runtime would make sure whether that variable actually points to a legal context, since we pass this in via reference, so it is only alive for the duration of the call to the engine.Async functions
Steel has support for async functions, and has successfully been integrated with the tokio runtime used within helix, however it requires constructing manually the callback function yourself, rather than elegantly being able to use something like
await
. More to come on this, since the eventual design will depend on the decision to use a local context variable vs a global one.Built in functions
The basic built in functions are first all of the function that are typed and static - i.e. everything here:
However, these functions don't return values so aren't particularly useful for anything but their side effects to the editor state. As a result, I've taken the liberty of defining functions as I've needed/wanted them. Some care will need to be decided what those functions actually exposed are.
Examples
Here are some examples of plugins that I have developed using Steel:
File tree
Source can be found here
filetree.webm
Recent file picker
Source can be found here
recent-files.webm
This persists your recent files between sessions.
Scheme indent
Since steel is a scheme, there is a relatively okay scheme indent mode that only applied on
.scm
files, which can be found here. The implementation requires a little love, but worked enough for me to use helix to write scheme code 😄Terminal emulator
I did manage to whip up a terminal emulator, however paused the development of it while focusing on other things. When I get it back into working shape, I will post a video of it here. I am not sure what the status is with respect to a built in terminal emulator, but the one I got working did not attempt to do complete emulation, but rather just maintained a shell to interact with non-interactively (e.g. don't try to launch helix in it, you'll have a bad time 😄 )
Steel as a choice for a language
I understand that there is skepticism around something like Steel, however I have been working diligently on improving it. My current projects include shoring up the documentation, and working on an LSP for it to make development easier - but I will do that in parallel with maintaining this PR. If Steel is not chosen and a different language is picked, in theory the API I've exposed should do the trick at least with matching the implementation behavior that I've outlined here.
Pure rust plugins
As part of this, I spent some time trying to expose a C ABI from helix to do rust to rust plugins directly in helix without a scripting engine, with little success. Steel supports loading dylibs over a stable abi (will link to documentation once I've written it). I used this to develop the proof of concept terminal emulator. So, you might not be a huge fan of scheme code, but in theory you can write mostly Rust and use Steel as glue if you'd like - you would just be limited to the abi compatible types.
System compatibility
I develop off of Linux and Mac - but have not tested on windows. I have access to a windows system, and will get around to testing on that when the time comes.