Skip to content
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

Use refs in jsonschema #4309

Merged

Conversation

karimkhaleel
Copy link
Contributor

  • PR Description

This turns the generated jsonschema into a flat-ter schema by using refs. This helps avoid the stack overflow described here: #4276 (comment)

As a side effect: os.editInTerminal started appearing in the generated section of Config.md. I think this is the correct behavior, and I am not sure why it wasn't in there before.

I feel like this still could use a bit of cleaning up. I might be able to get rid of the OriginalPropertiesMapping field that we added to jsonschema, but I need experiment some more when I get time.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@stefanhaller stefanhaller force-pushed the use-refs-in-jsonschema branch from 95aaf2b to 1f3050c Compare February 23, 2025 07:39
Copy link
Collaborator

@stefanhaller stefanhaller left a comment

Choose a reason for hiding this comment

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

This is very nice, thanks for figuring out how to do this!

I took the liberty of dropping the commits from my branch and force-pushing, so that we can make this a stand-alone PR.

Just a few small things below, but apart from that I'm very happy with this.

// This means the schema is defined on the rootSchema's Definitions
if subSchema.Ref != "" {
key, _ = strings.CutPrefix(subSchema.Ref, "#/$defs/")
refSchema := rootSchema.Definitions[key]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:

		refSchema, ok := rootSchema.Definitions[key]
		if !ok {
			panic(fmt.Sprintf("Failed to find #/$defs/%s", key))
		}

Comment on lines 232 to 241
if pair.Key == "confirmOnQuit" {
_ = pair
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some leftover from debugging, I suppose?

docs/Config.md Outdated
Comment on lines 414 to 415
# Whether lazygit suspends until an edit process returns
# Pointer to bool so that we can distinguish unset (nil) from false.
# We're naming this `editInTerminal` for backwards compatibility
editInTerminal: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that it's good that this now shows up in the file. However, only the first line of the comment is for users, the other two are for developers and shouldn't be here.

I pushed a commit that lets us annotate such lines with a tag and filter them out: 1f3050c.

}

schema := orderedmap.New()
userConfigSchema := schema.Definitions["UserConfig"]
for pair := userConfigSchema.Properties.Oldest(); pair != nil; pair = pair.Next() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This loop looks almost identical to the one in recurseOverSchema. Shouldn't it be possible to call recurseOverSchema on the root directly to avoid the duplication? I haven't looked very closely at this, so maybe I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right. I think there was a point during development where they had some differences but this loop became redundant after I wrote getSubSchema.

@karimkhaleel karimkhaleel force-pushed the use-refs-in-jsonschema branch from 1f3050c to 958aa29 Compare February 23, 2025 18:10
@karimkhaleel karimkhaleel marked this pull request as ready for review February 23, 2025 18:13
@karimkhaleel karimkhaleel force-pushed the use-refs-in-jsonschema branch from 958aa29 to 09696ca Compare February 23, 2025 18:14
@stefanhaller stefanhaller force-pushed the use-refs-in-jsonschema branch from 09696ca to 8d3a2dd Compare February 23, 2025 19:50
@stefanhaller stefanhaller added the maintenance For refactorings, CI changes, tests, version bumping, etc label Feb 23, 2025
@stefanhaller stefanhaller force-pushed the use-refs-in-jsonschema branch 2 times, most recently from e7e146c to 276e379 Compare February 23, 2025 19:54
karimkhaleel and others added 2 commits February 23, 2025 20:55
This makes it possible to use recursive structures in the user config.
@stefanhaller stefanhaller force-pushed the use-refs-in-jsonschema branch from 276e379 to 3b85307 Compare February 23, 2025 19:55
@stefanhaller
Copy link
Collaborator

Thanks for addressing my complaints, looks great now.

I had to run go mod vendor and go mod tidy to remove iancoleman/orderedmap, which is no longer used now. CI complained about this. I squashed this into the first commit.

@stefanhaller stefanhaller merged commit 2ceecad into jesseduffield:master Feb 23, 2025
15 checks passed
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | patch | `v0.47.1` -> `v0.47.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.47.2`](https://github.com/jesseduffield/lazygit/releases/tag/v0.47.2)

[Compare Source](jesseduffield/lazygit@v0.47.1...v0.47.2)

<!-- Release notes generated using configuration in .github/release.yml at v0.47.2 -->

Small patch release for you all. This is mainly to fix an issue with v0.47.1 which erroneously re-indented users' lazygit config files on startup.

Shout-out to [@&#8203;karimkhaleel](https://github.com/karimkhaleel) for his MR with some gnarly yaml-handling code.

And a special shout-out to [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) who has been pumping out many great contributions lately. Great to have you aboard.

#### What's Changed

##### Enhancements 🔥

-   Skip post-checkout hook when discarding changes by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4313

##### Fixes 🔧

-   fix: Disable global keybinds when confirmation is active by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4284
-   Don't rewrite config file unnecessarily when it contains commitPrefixes by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4311
-   Change side panel width calculation to work for larger numbers by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4287

##### Maintenance ⚙️

-   Fix auto-release schedule by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4308
-   Use indentation of 2 when rewriting auto-migrated config file by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4312
-   Use refs in jsonschema by [@&#8203;karimkhaleel](https://github.com/karimkhaleel) in jesseduffield/lazygit#4309
-   Improve release workflow by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4307
-   Filter out dev comments from schema by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4319
-   Fix release script by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4322
-   Fix release script once again by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4323

##### Docs 📖

-   Improve the error message when users have gpg signing turned on by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4296

**Full Changelog**: jesseduffield/lazygit@v0.47.1...v0.47.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODAuMiIsInVwZGF0ZWRJblZlciI6IjM5LjE4MC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance For refactorings, CI changes, tests, version bumping, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants