refactor(filetype): use extension match instead of pattern if possible

Problem: some patterns are used as a replacement for several explicit
  extension matches (like '%.[Ss][Yy][Ss]$', '%.php%d$', etc.).
  They usually correspond to Vim's "ignore case" regexes (like
  '*.sys\c') and "convenience" patterns to not define many of them (like
  '*.php\d').
  As matching extension directly is faster and more explicit, it should
  be preferred.
Solution: move all such patterns to direct extension match.
This commit is contained in:
Evgeni Chasnovski 2024-07-19 12:01:27 +03:00 committed by Christian Clason
parent 66a74535d4
commit 95e0289cb2

View File

@ -273,6 +273,16 @@ local extension = {
cfm = 'cf',
cfi = 'cf',
hgrc = 'cfg',
-- Extension match does not conflict with specific patterns such as '.*/etc/a2ps/.*%.cfg', etc.,
-- as it is done after those are tried to match
cfg = detect.cfg,
cfG = detect.cfg,
cFg = detect.cfg,
cFG = detect.cfg,
Cfg = detect.cfg,
CfG = detect.cfg,
CFg = detect.cfg,
CFG = detect.cfg,
chf = 'ch',
chai = 'chaiscript',
ch = detect.change,
@ -355,6 +365,14 @@ local extension = {
dart = 'dart',
drt = 'dart',
ds = 'datascript',
dat = detect.dat,
daT = detect.dat,
dAt = detect.dat,
dAT = detect.dat,
Dat = detect.dat,
DaT = detect.dat,
DAt = detect.dat,
DAT = detect.dat,
dcd = 'dcd',
decl = detect.decl,
dec = detect.decl,
@ -635,6 +653,14 @@ local extension = {
kts = 'kotlin',
kt = 'kotlin',
ktm = 'kotlin',
sub = 'krl',
suB = 'krl',
sUb = 'krl',
sUB = 'krl',
Sub = 'krl',
SuB = 'krl',
SUb = 'krl',
SUB = 'krl',
ks = 'kscript',
k = 'kwt',
ACE = 'lace',
@ -668,6 +694,14 @@ local extension = {
lt = 'lite',
lite = 'lite',
livemd = 'livebook',
log = detect.log,
loG = detect.log,
lOg = detect.log,
lOG = detect.log,
Log = detect.log,
LoG = detect.log,
LOg = detect.log,
LOG = detect.log,
lgt = 'logtalk',
lotos = 'lotos',
lot = detect_line1('\\contentsline', 'tex', 'lotos'),
@ -734,6 +768,14 @@ local extension = {
wl = 'mma',
mmp = 'mmp',
mms = detect.mms,
mod = detect.mod,
moD = detect.mod,
mOd = detect.mod,
mOD = detect.mod,
Mod = detect.mod,
MoD = detect.mod,
MOd = detect.mod,
MOD = detect.mod,
DEF = 'modula2',
m3 = 'modula3',
i3 = 'modula3',
@ -763,6 +805,14 @@ local extension = {
n1ql = 'n1ql',
nql = 'n1ql',
nanorc = 'nanorc',
NSA = 'natural',
NSC = 'natural',
NSG = 'natural',
NSL = 'natural',
NSM = 'natural',
NSN = 'natural',
NSP = 'natural',
NSS = 'natural',
ncf = 'ncf',
nginx = 'nginx',
nim = 'nim',
@ -772,6 +822,15 @@ local extension = {
nix = 'nix',
norg = 'norg',
nqc = 'nqc',
['1'] = detect.nroff,
['2'] = detect.nroff,
['3'] = detect.nroff,
['4'] = detect.nroff,
['5'] = detect.nroff,
['6'] = detect.nroff,
['7'] = detect.nroff,
['8'] = detect.nroff,
['9'] = detect.nroff,
roff = 'nroff',
tmac = 'nroff',
man = 'nroff',
@ -803,6 +862,14 @@ local extension = {
['or'] = 'openroad',
scad = 'openscad',
ovpn = 'openvpn',
opl = 'opl',
opL = 'opl',
oPl = 'opl',
oPL = 'opl',
Opl = 'opl',
OpL = 'opl',
OPl = 'opl',
OPL = 'opl',
ora = 'ora',
org = 'org',
org_archive = 'org',
@ -834,6 +901,16 @@ local extension = {
ctp = 'php',
php = 'php',
phpt = 'php',
php0 = 'php',
php1 = 'php',
php2 = 'php',
php3 = 'php',
php4 = 'php',
php5 = 'php',
php6 = 'php',
php7 = 'php',
php8 = 'php',
php9 = 'php',
phtml = 'php',
theme = 'php',
pike = 'pike',
@ -866,6 +943,14 @@ local extension = {
it = 'ppwiz',
ih = 'ppwiz',
action = 'privoxy',
prg = detect.prg,
prG = detect.prg,
pRg = detect.prg,
pRG = detect.prg,
Prg = detect.prg,
PrG = detect.prg,
PRg = detect.prg,
PRG = detect.prg,
pc = 'proc',
pdb = 'prolog',
pml = 'promela',
@ -1043,6 +1128,14 @@ local extension = {
sqi = 'sqr',
sqr = 'sqr',
nut = 'squirrel',
src = detect.src,
srC = detect.src,
sRc = detect.src,
sRC = detect.src,
Src = detect.src,
SrC = detect.src,
SRc = detect.src,
SRC = detect.src,
s28 = 'srec',
s37 = 'srec',
srec = 'srec',
@ -1069,6 +1162,14 @@ local extension = {
swift = 'swift',
swig = 'swig',
swg = 'swig',
sys = detect.sys,
syS = detect.sys,
sYs = detect.sys,
sYS = detect.sys,
Sys = detect.sys,
SyS = detect.sys,
SYs = detect.sys,
SYS = detect.sys,
svh = 'systemverilog',
sv = 'systemverilog',
cmm = 'trace32',
@ -2210,19 +2311,12 @@ local pattern = {
['^bzr_log%.'] = 'bzr',
['^cabal%.project%.'] = starsetf('cabalproject'),
['^sgml%.catalog'] = starsetf('catalog'),
['%.[Cc][Ff][Gg]$'] = {
detect.cfg,
-- Decrease priority to avoid conflicts with more specific patterns
-- such as '.*/etc/a2ps/.*%.cfg', '.*enlightenment/.*%.cfg', etc.
{ priority = -1 },
},
['hgrc$'] = 'cfg',
['^[cC]hange[lL]og'] = starsetf(detect.changelog),
['%.%.ch$'] = 'chill',
['%.cmake%.in$'] = 'cmake',
['^crontab%.'] = starsetf('crontab'),
['^cvs%d+$'] = 'cvs',
['%.[Dd][Aa][Tt]$'] = detect.dat,
['^php%.ini%-'] = 'dosini',
['^drac%.'] = starsetf('dracula'),
['/dtrace/.*%.d$'] = 'dtrace',
@ -2253,38 +2347,28 @@ local pattern = {
['^[jt]sconfig.*%.json$'] = 'jsonc',
['^Config%.in%.'] = starsetf('kconfig'),
['^Kconfig%.'] = starsetf('kconfig'),
['%.[Ss][Uu][Bb]$'] = 'krl',
['/ldscripts/'] = 'ld',
['lftp/rc$'] = 'lftp',
['/LiteStep/.*/.*%.rc$'] = 'litestep',
['%.[Ll][Oo][Gg]$'] = detect.log,
['^/tmp/SLRN[0-9A-Z.]+$'] = 'mail',
['^ae%d+%.txt$'] = 'mail',
['^pico%.%d+$'] = 'mail',
['^reportbug%-'] = starsetf('mail'),
['^snd%.%d+$'] = 'mail',
['%.[Mm][Oo][Dd]$'] = detect.mod,
['^rndc.*%.key$'] = 'named',
['%.NS[ACGLMNPS]$'] = 'natural',
['%.[1-9]$'] = detect.nroff,
['^tmac%.'] = starsetf('nroff'),
['%.ml%.cppo$'] = 'ocaml',
['%.mli%.cppo$'] = 'ocaml',
['/octave/history$'] = 'octave',
['%.opam%.locked$'] = 'opam',
['%.opam%.template$'] = 'opam',
['%.[Oo][Pp][Ll]$'] = 'opl',
['%.php%d$'] = 'php',
['%.[Pp][Rr][Gg]$'] = detect.prg,
['printcap'] = starsetf(function(path, bufnr)
return require('vim.filetype.detect').printcap('print')
end),
['/queries/.*%.scm$'] = 'query', -- treesitter queries (Neovim only)
[',v$'] = 'rcs',
['%.[Ss][Rr][Cc]$'] = detect.src,
['^svn%-commit.*%.tmp$'] = 'svn',
['%.swift%.gyb$'] = 'swiftgyb',
['%.[Ss][Yy][Ss]$'] = detect.sys,
['termcap'] = starsetf(function(path, bufnr)
return require('vim.filetype.detect').printcap('term')
end),