helix icon indicating copy to clipboard operation
helix copied to clipboard

Support for EditorConfig

Open cessen opened this issue 4 years ago • 21 comments

In #239 it was mentioned that support for EditorConfig would be nice, and it seemed like there was general agreement that we want to do that at some point.

I'm opening this issue just so it stays on our radar.

cessen avatar Jun 16 '21 14:06 cessen

While we do that, I think we want to have a logo first to be able to put our editor in editorconfig.org

Should we use https://github.com/mrandri19/rust-editorconfig?

pickfire avatar Jun 16 '21 15:06 pickfire

It doesn't seem to be maintained so we might have to pull it in and make some changes.

sudormrfbin avatar Jun 16 '21 15:06 sudormrfbin

Maybe we can take over the maintainership of the crate?

pickfire avatar Jun 16 '21 16:06 pickfire

There's an open issue for that too (offering maintainership): https://github.com/mrandri19/rust-editorconfig/issues/13

sudormrfbin avatar Jun 16 '21 16:06 sudormrfbin

I wonder if we could just attempt to parse it via TOML, it shares some similarities with INI.

archseer avatar Jun 17 '21 00:06 archseer

There's also serde_ini, which seems like a reasonable way to go since we already have the serde dependency anyway.

cessen avatar Jun 17 '21 16:06 cessen

It might just make sense to adapt https://github.com/zonyitoo/rust-ini. It seems like the only difference between .ini and .editorconfig are wildcard patterns in the section names.

Actually, I wonder if we need to do that at all and can just use it directly.

Edit: I checked it out and it seems like we can just use that crate directly without modifying anything. We just need to eliminate any duplicates (and only retain the first parsed value). This should be easy since the values are in the order they were parsed.

kirawi avatar Sep 09 '21 01:09 kirawi

Dropping this here for future reference if we go for the manual implementation using an ini crate route, there is an editorconfig-plugin-tests repository containing instructions and sample files for testing.

sudormrfbin avatar Sep 11 '21 05:09 sudormrfbin

Worst case scenario, we can just bind to https://github.com/editorconfig/editorconfig-core-c. But I don't think we'll need to.

kirawi avatar Sep 11 '21 16:09 kirawi

What is the status of this feature's implementation? If there is a lack of manpower for it, then I'd be happy to contribute some.

TheDaemoness avatar Feb 12 '22 21:02 TheDaemoness

Feel free :) I had some IRL things happen that prevented me from tackling this.

kirawi avatar Feb 12 '22 22:02 kirawi

Is there a preference for wrapping editorconfig-core-c or writing something new in pure Rust? The spec seems simple enough for now.

TheDaemoness avatar Feb 17 '22 19:02 TheDaemoness

https://github.com/zonyitoo/rust-ini seems to be able to parse it just fine.

kirawi avatar Feb 18 '22 00:02 kirawi

I'll take that as a preference for writing a pure Rust implementation. That was my preference as well. :+1:

rust-ini appears unfit for this purpose, specifically because its section parser ends parsing at the first ] matched. That's fine for most INI, but Editorconfig allows regex-style character ranges in sections.

Either way, I think the largest challenge in writing a new Editorconfig implementation will be the globing behavior.

From there, integrating it doesn't seem particularly involved:

  • Changing the indent style, character encoding, and line ending seem like they can be done with some calls in Document::open.
  • Changing the tab width could be done by adding an Option<usize> field to Document, and making Document::tab_width check that first before falling back to its current behavior. Let me know if there's a better approach.
  • Trimming trailing whitespace and inserting a final newline if one doesn't exist is harder. It seems like the place to do this is in Document::save_impl after the LSP formatting changes are applied.
  • Helix doesn't currently support hard-wrapping (see #625), so the non-standard max_line_length property will be ignored for now.

TheDaemoness avatar Feb 18 '22 19:02 TheDaemoness

It's been just over two weeks, so here's a status update.

I've been writing a new EditorConfig core. At the time of writing, it passes 161 of the 196 core tests, and some of the glob-related code quality is not what I'd like it to be (can't use the glob crate, unfortunately).

Once it passes all of the tests, I'd like to publish a 1.0.0 release to crates.io and add it as a dependency of Helix. Its only dependency is on std, but in the future it might also depend on unicode-segmentation. Alternatively, since I'm not expecting its public API to change as I bring the library into full test compliance, I could make a 0.3.0 release after fixing its main issues, and use that in Helix. Then, when 1.0.0 is done, all that should be necessary is a version bump. I expect it should work pretty well in the real world even without full compliance. Let me know!

TheDaemoness avatar Mar 04 '22 16:03 TheDaemoness

I'll add that .editorconfig files also aren't highlighted at the moment, not sure if that's planned as a part of this issue

yoav-lavi avatar Aug 28 '23 09:08 yoav-lavi

I'll add that .editorconfig files also aren't highlighted at the moment, not sure if that's planned as a part of this issue

It already has a PR and mention to this PR. https://github.com/helix-editor/helix/pull/8076

danillos avatar Aug 28 '23 19:08 danillos

Highlighting temporarily added as INI in #8308

yoav-lavi avatar Sep 16 '23 20:09 yoav-lavi

Damn, I hope this will do the cut for the next release!

koalalorenzo avatar Apr 02 '24 14:04 koalalorenzo

Fingers crossed, this would be a very useful feature!

christ-offer avatar Apr 24 '24 06:04 christ-offer

so no .editorconfig support until now for helix ?

noor-tg avatar Aug 23 '24 20:08 noor-tg

Can someone clarify what this issue is for? Support for editing .editorconfig files or for actually using them in Helix?

The latter would be of significant more interest to me... 👍

hholst80 avatar Jan 23 '25 23:01 hholst80

Support for using .editorconfig files so that it adjusts tabs, spaces, etc. defined therein.

heaths avatar Jan 24 '25 00:01 heaths

Maybe a sidenote: When using prettier as formatter for JSON in Helix it somehow ignores the .editorconfig. But if you use it from the CLI urself it uses the .editorconfig

hnorkowski avatar Jan 26 '25 13:01 hnorkowski

Maybe a sidenote: When using prettier as formatter for JSON in Helix it somehow ignores the .editorconfig. But if you use it from the CLI urself it uses the .editorconfig

That behavior is due to https://github.com/helix-editor/helix/issues/3596

Helix doesn't tell Prettier where the file is, so Prettier doesn't know where to look for an editorconfig

buckley310 avatar Jan 26 '25 19:01 buckley310

I'll comment here as well for people who aren't subscribed to the PR. I created ec2hx, a CLI tool to generate a project-specific helix configuration from an editorconfig file.

It can do some gnarly stuff that you wouldn't want to do manually. For example, a section header like [scripts/**] will generate a custom language definition for each language that helix supports, plus the necessary runtime queries to preserve syntax highlighting. trim_trailing_whitespace is supported via a built-in formatter.

The details about what is and isn't supported are documented in the readme. Check it out, maybe it suits your needs. And of course, bug reports are welcome.

senekor avatar Feb 10 '25 22:02 senekor