-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add Steel as an optional plugin system #8675
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
base: master
Are you sure you want to change the base?
Conversation
Work in progress for language configuration
xtask/src/main.rs
Outdated
<<<<<<< HEAD | ||
code-gen: Generate files associated with steel | ||
steel: Install steel | ||
======= | ||
theme-check: Check that theme files in runtime/themes are valid. | ||
>>>>>>> origin |
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.
Just want to note that some merge-conflicts sneaked in here (as well for commented-out code in helix-term/src/commands/typed.rs
)
@ronisbr I had the same issue with the spell checker so I ported the VSCode Code Spell plugin to have a standard LSP interface. It works ok for me, I have no idea how it can be configured for different languages but I dont think it will be complicated. It also works with neovim |
(define rng (rand::thread-rng!)) | ||
;; Picking one from the possible themes | ||
(define possible-themes '("ayu_mirage" "tokyonight_storm" "catppuccin_macchiato")) | ||
(define (select-random lst) | ||
(let ([index (rand::rng->gen-range rng 0 (length lst))]) (list-ref lst index))) |
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.
The steel random lib has changed, so this demo script needs the rng
bit removed in order to work:
(define rng (rand::thread-rng!)) | |
;; Picking one from the possible themes | |
(define possible-themes '("ayu_mirage" "tokyonight_storm" "catppuccin_macchiato")) | |
(define (select-random lst) | |
(let ([index (rand::rng->gen-range rng 0 (length lst))]) (list-ref lst index))) | |
;; Picking one from the possible themes | |
(define possible-themes '("ayu_mirage" "tokyonight_storm" "catppuccin_macchiato")) | |
(define (select-random lst) | |
(let ([index (rand::rng->gen-range 0 (length lst))]) (list-ref lst index))) |
Juicy new commits just dropped 🤩 |
I have some questions: Are people already using this PR in their local fork? Is it [somewhat] ready? Also, in general, what's the status of it? What are the milestones? Are we near done? Thanks in advance :) |
I think it is generally ready for consumption by eager users. The status is that I'm unhappy with some of the ways I've glued the configuration - namely, there are lots of options, and there are lots of options for language configuration, theming, and LSP that I haven't really tackled yet besides proof of concepts. I've been slowly working on that, and working on improving the documentation around this. The basic options are handled well, and for the most part seem to work alright, but I'm not sold on the api that I've chosen in general. One way to view it, is that I think it is very much usable, however the bar for quality is very high, and a lot of this will require some improvements, so I'm unable to say if its "near" completion. That will require sitting down and genuinely cleaning the code up, and have an honest assessment of the status that I haven't yet done besides tinkering here and there. TL;DR- feel free to give it a shot and provide some feedback. I use this every day and things seem to work pretty well from a "human using the thing" perspective. The code could use some love in places and docs will need to be improved |
Do you think it could be merged into the main branch with a warning label such as "experimental" or "beta" feature? That might attract some attention and help drive the development of plugins. I'm not sure if this is something you would be in favor of, but you could likely receive some assistance on this PR as well. |
I noticed that the build litters my |
And it also makes it easy for those who prefer to package it before trying it. |
Or perhaps a way to override the path of the steel standard library / whatever that is getting put into the config directory? Would make packaging and modification of it easier, in nixpkgs it could be a separate derivation that gets included using Plus it can be implemented in very few lines of code. |
I did this in this PR (still waiting to be merged): mattwparas#16 |
Optionally load init.scm and helix.scm from env var
I would be fine with that, although it still needs a little work before then. It is set up now to be a compile time feature flag, so I could reasonably convert it to a run time feature flag, and/or set up a separate binary that is built with the flag enabled. Contributions are also welcome on this branch as well - I got a little behind with some of the PRs which I'm looking at this morning |
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.