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 function find(string, field)
|
||||||
|
local best_match = 0
|
||||||
|
local best_syntax
|
||||||
for i = #syntax.items, 1, -1 do
|
for i = #syntax.items, 1, -1 do
|
||||||
local t = syntax.items[i]
|
local t = syntax.items[i]
|
||||||
if common.match_pattern(string, t[field] or {}) then
|
local s, e = common.match_pattern(string, t[field] or {})
|
||||||
return t
|
if s and e - s > best_match then
|
||||||
|
best_match = e - s
|
||||||
|
best_syntax = t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return best_syntax
|
||||||
end
|
end
|
||||||
|
|
||||||
function syntax.get(filename, header)
|
function syntax.get(filename, header)
|
||||||
|
|
Loading…
Reference in New Issue