From 334a7da5c936ab8292eafeb58549b8f0893e9526 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Thu, 13 Oct 2022 00:10:11 +0200 Subject: [PATCH] Use the syntax with the longest match (#919) This way, for example, a syntax that applies to `docker-compose.yml` files will take precedence over one that applies to `*.yml` files. --- data/core/syntax.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/data/core/syntax.lua b/data/core/syntax.lua index 89208bce..977983c1 100644 --- a/data/core/syntax.lua +++ b/data/core/syntax.lua @@ -30,12 +30,17 @@ end local function find(string, field) + local best_match = 0 + local best_syntax for i = #syntax.items, 1, -1 do local t = syntax.items[i] - if common.match_pattern(string, t[field] or {}) then - return t + local s, e = common.match_pattern(string, t[field] or {}) + if s and e - s > best_match then + best_match = e - s + best_syntax = t end end + return best_syntax end function syntax.get(filename, header)