# Improve handling of \`injection.combined\` injections in \`SyntaxSnapshot::layers_for_range\` \(\#32145\) · gitcafe/zed

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

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

Visibility: public

Requested revision: a40ee74a1f45cc3ada75bff90ad5a71c8dbff6e3

Requested commit: a40ee74a1f45cc3ada75bff90ad5a71c8dbff6e3

Commit: a40ee74a1f45cc3ada75bff90ad5a71c8dbff6e3

Tree: c93f72ae38c62869fadc965f6a35c3bf1482509d

Author: Ben Kunkle

Committer: GitHub

## Message

```
Improve handling of `injection.combined` injections in `SyntaxSnapshot::layers_for_range` (#32145)

Closes #27596

The problem in this case was incorrect identification of which language
(layer) contains the selection.

Language layer selection incorrectly assumed that the deepest
`SyntaxLayer` containing a range was the most specific. This worked for
Markdown (base document + injected subtrees) but failed for PHP, where
`injection.combined` injections are used to make HTML logically function
as the base layer, despite being at a greater depth in the layer stack.
This caused HTML to be incorrectly identified as the most specific
language for PHP ranges.

The solution is to track included sub-ranges for syntax layers and
filter out layers that don't contain a sub-range covering the desired
range. The top-level layer is never filtered to ensure gaps between
sibling nodes always have a fallback language, as the top-level layer is
likely more correct than the default language settings.

Release Notes:

- Fixed an issue in PHP where PHP language settings would be
occasionally overridden by HTML language settings
```

## Parents

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

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