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:
parent
48c800cde7
commit
334a7da5c9
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue