# language: Fix \`language_scope_at\` for markdown code comments \(\#29230\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a50fbc9b5c8aab7324c40d8bd63809e715ae5fde)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a50fbc9b5c8aab7324c40d8bd63809e715ae5fde

Requested commit: a50fbc9b5c8aab7324c40d8bd63809e715ae5fde

Commit: a50fbc9b5c8aab7324c40d8bd63809e715ae5fde

Tree: 50cc2d7abb1670ee3fa9a7cb84c175cb4cd377e0

Author: Smit Barmase

Committer: GitHub

## Message

```
language: Fix `language_scope_at` for markdown code comments (#29230)

Closes #29176

This PR fix an issue where uncommenting a code block in Markdown would
add Markdown comments instead of removing the language-specific
comments.

Why?
`language_scope_at` for comments in a code block in Markdown would
result in the language being detected as Markdown. This happens because
the smallest range, such as `//` or `#` on the Markdown layer, is
preferred over `// whole comment line` for any other language. This
results in language detection as Markdown for that point.

To fix this, we also use a depth factor and try to prefer the layer with
greater depth over one with lesser depth. In this case, the code block's
language depth would be preferred over Markdown. The smallest range is
now used as a tiebreaker.

Added test for this case.

Release Notes:

- Fixed issue where uncommenting a code block in Markdown would add
Markdown comments instead of removing the language comments.
```

## Parents

- [9bbc2e0fb26c1ec144e05de132bedec53f9022c5](https://git.cafe/gitcafe/zed/commit/9bbc2e0fb26c1ec144e05de132bedec53f9022c5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a50fbc9b5c8aab7324c40d8bd63809e715ae5fde?format=markdown)
