ZIm/crates/language/src
Finn Evers 12b012eab3
language: Further optimize language_for_file (#28694)
Follow-up to #28671

This primarily follows two ideas:
1. We currently take the element with the highest score which appears
last in the iterator (see
[`last_by_key`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.max_by_key)),
so we can also just reverse the iterator and take the first highest
match instead.
2. Once we have a match with a given precedence, we are not interested
in any matches with a lower or even the same priority, given what was
established in 1. Thus, we also only have to check whether any language
checked afterwards has a higher priority match.

Furthermore, once we have a match with the highest possible precedence,
there is no need to look for any more possible matches. Thus, this PR
also adds short-circuiting for that scenario.

Lastly, I also cleaned-up the custom suffix match (an empty glob-set
will never match so no need to iterate there) as well reorder the
zip-call in the content matches, as we never need the content if there
is no first line pattern present for the checked languages.

Release Notes:

- N/A
2025-04-14 23:31:45 +00:00
..
syntax_map chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
buffer.rs snippets: Fix plaintext snippets not working (#28655) 2025-04-13 19:53:22 +02:00
buffer_tests.rs buffer: Fix broken auto indent when pasting code starting with new line (#28134) 2025-04-05 05:14:15 +05:30
diagnostic_set.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
highlight_map.rs Docs for indent_size_for_line and co 2024-01-09 20:50:34 +01:00
language.rs Support tasks from rust-analyzer (#28359) 2025-04-08 15:07:56 -06:00
language_registry.rs language: Further optimize language_for_file (#28694) 2025-04-14 23:31:45 +00:00
language_settings.rs language: Optimize language_for_file (#28671) 2025-04-14 13:18:45 +02:00
manifest.rs project: Track manifest locations per unique manifest locator (#27194) 2025-03-21 15:22:36 +01:00
outline.rs Fix panic when outline items have no name (#24574) 2025-02-10 18:50:26 +00:00
proto.rs Allow viewing past commits in Zed (#27636) 2025-03-31 23:26:47 +00:00
syntax_map.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
task_context.rs Support tasks from rust-analyzer (#28359) 2025-04-08 15:07:56 -06:00
text_diff.rs chore: Bump Rust edition to 2024 (#27800) 2025-03-31 20:55:27 +02:00
toolchain.rs toolchains: Add support for relative paths (#27777) 2025-03-31 19:48:09 +02:00