# language: Select language based on longest matching path extension \(\#29716\) · gitcafe/zed

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

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

Visibility: public

Requested revision: f4b361f04ddb15184407ba0988cf8f0c9c44d1ff

Requested commit: f4b361f04ddb15184407ba0988cf8f0c9c44d1ff

Commit: f4b361f04ddb15184407ba0988cf8f0c9c44d1ff

Tree: 878055b4abb9af8dc1def06db296ccc6ae11f101

Author: claytonrcarter

Committer: GitHub

## Message

```
language: Select language based on longest matching path extension (#29716)

Closes #8408  
Closes #10997

This is a reboot of [my original
PR](https://github.com/zed-industries/zed/pull/11697) from last year. I
believe that I've addressed all the comments raised in that original
review, but Zed has changed a lot in the past year, so I'm sure there
will be some new stuff to consider too.

- updates the language matching and lookup to consider not just "does
the suffix/glob match" but also "... and is it the longest such match"
- adds a new `LanguageCustomFileTypes` struct to pass user globs from
settings to the registry
- _minor/unrelated:_ updates a test for the JS extension that wasn't
actually testing what is intended to
- _minor/unrelated:_ removed 2 redundant path extensions from the JS
lang extension

**Languages that may use this**

- Laravel Blade templates use the `blade.php` compound extension
-
[apparently](https://github.com/zed-industries/zed/issues/10765#issuecomment-2091293304)
Angular uses `component.html`
  - see also https://github.com/zed-industries/extensions/issues/169
- _hypothetically_ someone could publish a "JS test" extension w/ custom
highlights and/or snippets; many JS tests use `test.js` or `spec.js`

**Verifying these changes**

I added a number of assertions for this new behavior, and I also
confirmed that the (recently patched) [Laravel Blade
extension](https://github.com/bajrangCoder/zed-laravel-blade) opens as
expected for `blade.php` files, whereas on `main` it does not.

cc @maxbrunsfeld (reviewed my original PR last year), @osiewicz and
@MrSubidubi (have recently been in this part of the code)

Release Notes:

- Added support for "compound" file extensions in language extensions,
such `blade.php` and `component.html`. Closes #8408 and #10997.
```

## Parents

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

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