zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.6k stars 3.04k forks source link

Add option to turn off HTML tag auto-closing #14814

Closed Liz-Lovelace closed 3 months ago

Liz-Lovelace commented 3 months ago

Check for existing issues

Describe the feature

When I open an .html file and type <div>, I don't want the editor to insert </div> after my cursor

I have tried setting use_autoclose to false, and it didn't help

I'm a bit crazy about my editor changing the file without my explicit command, so I'd really appreciate if an option was added to disable HTML tag auto-closing, thanks!

If applicable, add mockups / screenshots to help present your vision of the feature

No response

JosephTLyons commented 3 months ago

cc: @osiewicz - I think this used to work, maybe some sort of a regression?

osiewicz commented 3 months ago

No, disabling it is possible; it's not use_autoclose though; the tag closing comes from language server, so you have to disable it via:

"lsp": {
  "vscode-html-language-server": {
    "settings": {
      "html": { "tagAutoclosing": false }
    }
  }
}

Admittedly, we may want to link one to the other; if user does have "use_autoclose` set to false and they don't have an explicit setting for vsc, we could disable it for them. I think it deserves a separate ticket though.

Liz-Lovelace commented 3 months ago

Oh, thanks, that solves it! Would be nice if it was documented somewhere obvious, I couldn't find this option after quite a bit of googling ^_^

tenry92 commented 3 months ago

Does the solution form @osiewicz apply to empty tags like <br> as well? I added the mentioned snippet to my settings, which now looks like this:

{
  "ui_font_size": 16,
  "buffer_font_size": 16,
  "theme": {
    "mode": "system",
    "light": "Ayu Mirage",
    "dark": "One Dark"
  },
  "preferred_line_length": 80,
  "tab_size": 2,
  "lsp": {
    "vscode-html-language-server": {
      "settings": {
        "html": { "tagAutoclosing": false }
      }
    }
  }
}

However, when saving my HTML file, it still changes <br> tags to <br />, even after restarting Zed. I'm using Zed 0.144.4 on Linux.

osiewicz commented 3 months ago

@tenry92 I believe that HTML language server is formatting your code and closing <br>. Can you try disabling format_on_save for HTML and see how it goes?

tenry92 commented 3 months ago

Hi @osiewicz! Adding "format_on_save": "off" to my settings actually disables that behavior. On the downside it obviously disables the formatting completely, which is not what I'm looking for.

osiewicz commented 3 months ago

I totally get that; it's just that the closing / is added automatically by the language server, which is not something we can remedy on the side of Zed itself. We could look into configuring it so that br is on a list of tags excluded from autoformat (which looks to be controlled by html.format.unformatted setting from this site)