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.
This commit is contained in:
Guldoman 2022-10-13 00:10:11 +02:00 committed by GitHub
parent 48c800cde7
commit 334a7da5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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)