Skip to content

Add rudimentary settings.json support#779

Merged
lhecker merged 4 commits intomainfrom
dev/lhecker/syntax-highlighting-config
Mar 25, 2026
Merged

Add rudimentary settings.json support#779
lhecker merged 4 commits intomainfrom
dev/lhecker/syntax-highlighting-config

Conversation

@lhecker
Copy link
Copy Markdown
Member

@lhecker lhecker commented Mar 25, 2026

Adds settings.json loading and parsing.
For now, that's just for a files.associations key.

Part of #22
Part of #624

@lhecker lhecker requested a review from DHowett March 25, 2026 13:06
Copy link
Copy Markdown
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much does simple JSON settings grow our binary?


#[cfg(target_os = "windows")]
{
var_path("APPDATA").map(|p| push(p, "Microsoft/Edit"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we should use one of the Known Folder APIs. Should this type of thing live in the edit sys crate?

Copy link
Copy Markdown
Member Author

@lhecker lhecker Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it would be neat if the edit code (the code outside the bin directory) had as little to do with edit as possible. I've already extracted substantial parts into other crates out of necessity, and I expect this to continue. Additionally, it would indeed make a neat TUI library if it was properly cleaned up. And a TUI library probably wouldn't need any known-dir APIs.

Re: SHGetKnownFolderPath. I avoided it because of the [internal implementation details].

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I did some measurements. I knew what the result would be, reading the implementation, but hard numbers are technically the right thing to do, eh?

GetEnvironmentVariableW = 187ns/op
SHGetKnownFolderPath = 569ns/op (3x)

This may lead you to believe that we did solid™ engineering™, but this was measured when running those APIs in a loop. If you measure the latency-to-first-result it changes drastically:

GetEnvironmentVariableW = ~6us/op
SHGetKnownFolderPath = ~1700us/op (283x)

You see, I'm not irrationally snarky, but fully-justified-snarky! The windows.storage.dll APIs are en...hanced and I'd prefer avoiding it.

@lhecker
Copy link
Copy Markdown
Member Author

lhecker commented Mar 25, 2026

272384 -> 297984, so 25.6kB. Roughly half of that (11kB) are Rust's f64 parsing tables, aka core::num::imp::dec2flt::table::POWER_OF_FIVE_128, plus another few kB for the parsing logic. The rest is the JSON parser (which is now newly included; hard to say, but around 3kB?).

Switching to f32 doesn't change this, since edit didn't do any float parsing previously and f32 parsing is still complex. If anyone would be up for some fun time, we could implement our own float parsing. It is technically not that difficult if we don't care at all about theoretical last digit precision (we don't need that) or performance (definitely don't need that for settings parsing).

pub fn bootstrap(tb: &mut TextBuffer) {
tb.set_crlf(false);
tb.write_raw(b"{\n}\n");
tb.cursor_move_to_logical(Default::default());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm some way for the cursor to go inside the {} ? is that silly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also considered that, but VS Code puts it at 0,0 and I'll keep that for consistency.


#[cfg(target_os = "windows")]
{
var_path("APPDATA").map(|p| push(p, "Microsoft\\Edit"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw when i said "edit sys crate" i actually thought edit itself had its own system specific crate, different from the generic sys one in this repo. I ask mostly because if I were to add UEFI, I would want this to return None without having to put uefi-specific things all over the code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point!

@DHowett
Copy link
Copy Markdown
Member

DHowett commented Mar 25, 2026

Also link to the issue number where people are asking for settings!

@lhecker lhecker merged commit d1908b0 into main Mar 25, 2026
6 checks passed
@lhecker lhecker deleted the dev/lhecker/syntax-highlighting-config branch March 25, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants