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.
This commit is contained in:
parent
649072d140
commit
f4b361f04d
3 changed files with 177 additions and 52 deletions
|
@ -1,6 +1,6 @@
|
|||
name = "TypeScript"
|
||||
grammar = "typescript"
|
||||
path_suffixes = ["ts", "cts", "d.cts", "d.mts", "mts"]
|
||||
path_suffixes = ["ts", "cts", "mts"]
|
||||
first_line_pattern = '^#!.*\b(?:deno run|ts-node|bun|tsx)\b'
|
||||
line_comments = ["// "]
|
||||
block_comment = ["/*", "*/"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue