Skip to content

markdown: Fix visible escape characters in LSP diagnostics#51766

Merged
smitbarmase merged 7 commits into
zed-industries:mainfrom
Dnreikronos:fix/markdown-escape-visible-in-diagnostics
Apr 3, 2026
Merged

markdown: Fix visible escape characters in LSP diagnostics#51766
smitbarmase merged 7 commits into
zed-industries:mainfrom
Dnreikronos:fix/markdown-escape-visible-in-diagnostics

Conversation

@Dnreikronos

Copy link
Copy Markdown
Contributor

Closes #51622

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Release Notes:

  • Fixed markdown escape characters being visible in LSP diagnostic messages when leading whitespace caused indented code blocks

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 17, 2026

@smitbarmase smitbarmase left a comment

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.

Thanks, I think we should not strip the leading whitespace since it might lead to stylistic changes that LSP didn't advertise. Can we replace these whitespaces with   so that Markdown renderer still adds those intended spacing, without turning it into a codeblock?

@Dnreikronos Dnreikronos force-pushed the fix/markdown-escape-visible-in-diagnostics branch 2 times, most recently from 0b6b88f to 525f642 Compare April 2, 2026 16:50
@Dnreikronos

Copy link
Copy Markdown
Contributor Author

Thanks, I think we should not strip the leading whitespace since it might lead to stylistic changes that LSP didn't advertise. Can we replace these whitespaces with   so that Markdown renderer still adds those intended spacing, without turning it into a codeblock?

Just adjusted as you requested!

@Dnreikronos Dnreikronos requested a review from smitbarmase April 2, 2026 16:51

@smitbarmase smitbarmase left a comment

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.

Thanks, I made a couple of fixes here:

  1. Tabs in leading whitespace were getting replaced with a single non-breaking space instead of 4. This means tab-indented diagnostics would look collapsed. Fixed it by expanding each tab to 4 NBSPs.

  2. String::with_capacity was underestimating. It accounted for doubled newlines and backslash prefixes but missed the NBSP expansion (each \u{00A0} is 2 bytes in UTF-8 vs 1 for the original space/tab). The capacity is now computed exactly upfront.

I think now it is in right shape! Thanks again.

Dnreikronos and others added 6 commits April 3, 2026 13:28
Replace leading whitespace with U+00A0 (non-breaking space) instead of
stripping it, so markdown won't trigger indented code blocks while still
preserving the visual indentation that LSP diagnostics intended.
add markdown escaper
@smitbarmase smitbarmase force-pushed the fix/markdown-escape-visible-in-diagnostics branch from 808a065 to bf05143 Compare April 3, 2026 07:58
@smitbarmase smitbarmase enabled auto-merge (squash) April 3, 2026 08:10
@smitbarmase smitbarmase merged commit 843615c into zed-industries:main Apr 3, 2026
30 checks passed
rtfeldman pushed a commit that referenced this pull request Apr 4, 2026
Closes #51622

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed markdown escape characters being visible in LSP diagnostic
messages when leading whitespace caused indented code blocks

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
piper-of-dawn pushed a commit to piper-of-dawn/zed that referenced this pull request Apr 25, 2026
…tries#51766)

Closes zed-industries#51622

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [ ] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed markdown escape characters being visible in LSP diagnostic
messages when leading whitespace caused indented code blocks

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
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.

Markdown escapes visible in LSP errors

2 participants