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

Indent guides #11503

Merged
merged 64 commits into from
May 23, 2024
Merged

Indent guides #11503

merged 64 commits into from
May 23, 2024

Conversation

bennetbo
Copy link
Collaborator

@bennetbo bennetbo commented May 7, 2024

Builds on top of existing work from #2249, but here's a showcase:

Screen.Recording.2024-05-07.at.19.01.44.mov

TODO:

  • handle line wrapping
  • implement handling in multibuffer (crashes currently)
  • add configuration option
  • new theme properties? What colors to use?
  • Possibly support indents with different colors or background colors
  • investigate edge cases (e.g. indent guides and folds continue on empty lines even if the next indent is different)
  • add more tests (also test find_active_indent_index)
  • docs (will do in a follow up PR)
  • benchmark performance impact

Release Notes:

  • Added indent guides (#5373)

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label May 7, 2024
@d1y
Copy link
Contributor

d1y commented May 8, 2024

It looks great, I hope it can have built-in rainbow indentation :)

@bennetbo bennetbo marked this pull request as ready for review May 22, 2024 17:26
@bennetbo
Copy link
Collaborator Author

bennetbo commented May 22, 2024

It looks great, I hope it can have built-in rainbow indentation :)

@d1y It is actually built-in. In your settings file you will be able to do something like this:

"experimental.theme_overrides": {
    "accents": [ // Specify some accent colors to use for the indent guide lines/background
      "#ffff40",
      "#7fff7f",
      "#ff7fff",
      "#4fecec"
    ]
  },
  "indent_guides": {
    "coloring": "indent_aware",  // Set this to indent_aware to paint the lines in rainbow colors
    "background_coloring": "indent_aware" // Set this to indent_aware to paint the background in rainbow colors
  },

You can also only colorize/disable the lines/the background by customizing the coloring and background_coloring values

image

@baldwindavid
Copy link
Contributor

baldwindavid commented May 22, 2024

@bennetbo Great work! For the "fixed" color mode is there a way to set the color of the active and inactive indent guides via the theme? I see an example for the gruvbox theme accents, but thinking that is only for "indent_aware" colors. What I would be shooting for is to set the "active" indent guide to a more prominent color (maybe) and the inactive guides to transparent. Regardless of whether that is in here this will be a great addition. Thanks!

@baldwindavid
Copy link
Contributor

baldwindavid commented May 22, 2024

The other notes for future consideration are:

  • It would be nice to be able to toggle on and off with a command like editor::ToggleIndentGuides (similar to editor::ToggleLineNumbers).
  • I want indent guides more in some languages than others. For example, I don't typically want guides in Elixir, but need them in HTML-ish code with deeper nesting. Might be nice to support language overrides similar to those for hard warp, tab size, etc.

I'm not even sure I'd want to mess with the default active/inactive theme colors mentioned in my previous comment if these sorts of settings were available.

@bennetbo
Copy link
Collaborator Author

bennetbo commented May 23, 2024

@baldwindavid Indent guides use the theme color's editor.indent_guide and editor.indent_guide_active when coloring is set to fixed (which is the default). So they can be styled by both the theme and also the theme overrides.
Thanks for the suggestions! Will add them in a follow up PR

@baldwindavid
Copy link
Contributor

@bennetbo Super cool. I added "editor.indent_guide": "#00000000" and it works great.

I also see that you went ahead and added the per language config. I tried it out and quickly realized that my plan to disable for Elixir is kind of foiled in that this also disables it for heex (the elixir HTML template language). I tried this, but didn't seem to achieve what I was trying to do as the guides are still disabled for heex...

  "languages": {
    "Elixir": {
      "language_servers": ["lexical", "!elixir-ls", "!next-ls", "..."],
      "indent_guides": {
        "enabled": false
      }
    },
    "HEEX": {
      "indent_guides": {
        "enabled": true
      }
    },

At any rate, don't think that has anything to do with this PR as the language-level settings do work. Thanks!

@bennetbo
Copy link
Collaborator Author

@bennetbo Super cool. I added "editor.indent_guide": "#00000000" and it works great.

I also see that you went ahead and added the per language config. I tried it out and quickly realized that my plan to disable for Elixir is kind of foiled in that this also disables it for heex (the elixir HTML template language). I tried this, but didn't seem to achieve what I was trying to do as the guides are still disabled for heex...

  "languages": {
    "Elixir": {
      "language_servers": ["lexical", "!elixir-ls", "!next-ls", "..."],
      "indent_guides": {
        "enabled": false
      }
    },
    "HEEX": {
      "indent_guides": {
        "enabled": true
      }
    },

At any rate, don't think that has anything to do with this PR as the language-level settings do work. Thanks!

I am not familiar with HEEX and elixir, is the HEEX code in the same file as the elixir code? Right now there's no support for rendering indent guides only for a certain part of a file (the language settings get inferred from the first line of the buffer, which in your case is probably elixir -> that's why they don't show up)

@bennetbo bennetbo merged commit feea607 into main May 23, 2024
9 checks passed
@bennetbo bennetbo deleted the indent-guides-experiment branch May 23, 2024 13:51
@baldwindavid
Copy link
Contributor

Elixir is the main language and HEEX a templating language for Elixir. They are both in the elixir extension within the zed repo.

While the elixir extension does support heex injections, the scenario I'm talking about here is for elixir in a file with a .ex extension and a heex template in a different file with the extension .heex.

@bennetbo
Copy link
Collaborator Author

Elixir is the main language and HEEX a templating language for Elixir. They are both in the elixir extension within the zed repo.

While the elixir extension does support heex injections, the scenario I'm talking about here is for elixir in a file with a .ex extension and a heex template in a different file with the extension .heex.

Hmm that is odd, I just tested it and specifying something like tab_size will also not work, HEEX always seems to use the settings that I specify for elixir

@WeetHet WeetHet mentioned this pull request May 26, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants