mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 11:25:33 +00:00
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:
committed by
Christian Clason
parent
66a74535d4
commit
95e0289cb2
@@ -273,6 +273,16 @@ local extension = {
|
|||||||
cfm = 'cf',
|
cfm = 'cf',
|
||||||
cfi = 'cf',
|
cfi = 'cf',
|
||||||
hgrc = 'cfg',
|
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',
|
chf = 'ch',
|
||||||
chai = 'chaiscript',
|
chai = 'chaiscript',
|
||||||
ch = detect.change,
|
ch = detect.change,
|
||||||
@@ -355,6 +365,14 @@ local extension = {
|
|||||||
dart = 'dart',
|
dart = 'dart',
|
||||||
drt = 'dart',
|
drt = 'dart',
|
||||||
ds = 'datascript',
|
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',
|
dcd = 'dcd',
|
||||||
decl = detect.decl,
|
decl = detect.decl,
|
||||||
dec = detect.decl,
|
dec = detect.decl,
|
||||||
@@ -635,6 +653,14 @@ local extension = {
|
|||||||
kts = 'kotlin',
|
kts = 'kotlin',
|
||||||
kt = 'kotlin',
|
kt = 'kotlin',
|
||||||
ktm = 'kotlin',
|
ktm = 'kotlin',
|
||||||
|
sub = 'krl',
|
||||||
|
suB = 'krl',
|
||||||
|
sUb = 'krl',
|
||||||
|
sUB = 'krl',
|
||||||
|
Sub = 'krl',
|
||||||
|
SuB = 'krl',
|
||||||
|
SUb = 'krl',
|
||||||
|
SUB = 'krl',
|
||||||
ks = 'kscript',
|
ks = 'kscript',
|
||||||
k = 'kwt',
|
k = 'kwt',
|
||||||
ACE = 'lace',
|
ACE = 'lace',
|
||||||
@@ -668,6 +694,14 @@ local extension = {
|
|||||||
lt = 'lite',
|
lt = 'lite',
|
||||||
lite = 'lite',
|
lite = 'lite',
|
||||||
livemd = 'livebook',
|
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',
|
lgt = 'logtalk',
|
||||||
lotos = 'lotos',
|
lotos = 'lotos',
|
||||||
lot = detect_line1('\\contentsline', 'tex', 'lotos'),
|
lot = detect_line1('\\contentsline', 'tex', 'lotos'),
|
||||||
@@ -734,6 +768,14 @@ local extension = {
|
|||||||
wl = 'mma',
|
wl = 'mma',
|
||||||
mmp = 'mmp',
|
mmp = 'mmp',
|
||||||
mms = detect.mms,
|
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',
|
DEF = 'modula2',
|
||||||
m3 = 'modula3',
|
m3 = 'modula3',
|
||||||
i3 = 'modula3',
|
i3 = 'modula3',
|
||||||
@@ -763,6 +805,14 @@ local extension = {
|
|||||||
n1ql = 'n1ql',
|
n1ql = 'n1ql',
|
||||||
nql = 'n1ql',
|
nql = 'n1ql',
|
||||||
nanorc = 'nanorc',
|
nanorc = 'nanorc',
|
||||||
|
NSA = 'natural',
|
||||||
|
NSC = 'natural',
|
||||||
|
NSG = 'natural',
|
||||||
|
NSL = 'natural',
|
||||||
|
NSM = 'natural',
|
||||||
|
NSN = 'natural',
|
||||||
|
NSP = 'natural',
|
||||||
|
NSS = 'natural',
|
||||||
ncf = 'ncf',
|
ncf = 'ncf',
|
||||||
nginx = 'nginx',
|
nginx = 'nginx',
|
||||||
nim = 'nim',
|
nim = 'nim',
|
||||||
@@ -772,6 +822,15 @@ local extension = {
|
|||||||
nix = 'nix',
|
nix = 'nix',
|
||||||
norg = 'norg',
|
norg = 'norg',
|
||||||
nqc = 'nqc',
|
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',
|
roff = 'nroff',
|
||||||
tmac = 'nroff',
|
tmac = 'nroff',
|
||||||
man = 'nroff',
|
man = 'nroff',
|
||||||
@@ -803,6 +862,14 @@ local extension = {
|
|||||||
['or'] = 'openroad',
|
['or'] = 'openroad',
|
||||||
scad = 'openscad',
|
scad = 'openscad',
|
||||||
ovpn = 'openvpn',
|
ovpn = 'openvpn',
|
||||||
|
opl = 'opl',
|
||||||
|
opL = 'opl',
|
||||||
|
oPl = 'opl',
|
||||||
|
oPL = 'opl',
|
||||||
|
Opl = 'opl',
|
||||||
|
OpL = 'opl',
|
||||||
|
OPl = 'opl',
|
||||||
|
OPL = 'opl',
|
||||||
ora = 'ora',
|
ora = 'ora',
|
||||||
org = 'org',
|
org = 'org',
|
||||||
org_archive = 'org',
|
org_archive = 'org',
|
||||||
@@ -834,6 +901,16 @@ local extension = {
|
|||||||
ctp = 'php',
|
ctp = 'php',
|
||||||
php = 'php',
|
php = 'php',
|
||||||
phpt = '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',
|
phtml = 'php',
|
||||||
theme = 'php',
|
theme = 'php',
|
||||||
pike = 'pike',
|
pike = 'pike',
|
||||||
@@ -866,6 +943,14 @@ local extension = {
|
|||||||
it = 'ppwiz',
|
it = 'ppwiz',
|
||||||
ih = 'ppwiz',
|
ih = 'ppwiz',
|
||||||
action = 'privoxy',
|
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',
|
pc = 'proc',
|
||||||
pdb = 'prolog',
|
pdb = 'prolog',
|
||||||
pml = 'promela',
|
pml = 'promela',
|
||||||
@@ -1043,6 +1128,14 @@ local extension = {
|
|||||||
sqi = 'sqr',
|
sqi = 'sqr',
|
||||||
sqr = 'sqr',
|
sqr = 'sqr',
|
||||||
nut = 'squirrel',
|
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',
|
s28 = 'srec',
|
||||||
s37 = 'srec',
|
s37 = 'srec',
|
||||||
srec = 'srec',
|
srec = 'srec',
|
||||||
@@ -1069,6 +1162,14 @@ local extension = {
|
|||||||
swift = 'swift',
|
swift = 'swift',
|
||||||
swig = 'swig',
|
swig = 'swig',
|
||||||
swg = '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',
|
svh = 'systemverilog',
|
||||||
sv = 'systemverilog',
|
sv = 'systemverilog',
|
||||||
cmm = 'trace32',
|
cmm = 'trace32',
|
||||||
@@ -2210,19 +2311,12 @@ local pattern = {
|
|||||||
['^bzr_log%.'] = 'bzr',
|
['^bzr_log%.'] = 'bzr',
|
||||||
['^cabal%.project%.'] = starsetf('cabalproject'),
|
['^cabal%.project%.'] = starsetf('cabalproject'),
|
||||||
['^sgml%.catalog'] = starsetf('catalog'),
|
['^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',
|
['hgrc$'] = 'cfg',
|
||||||
['^[cC]hange[lL]og'] = starsetf(detect.changelog),
|
['^[cC]hange[lL]og'] = starsetf(detect.changelog),
|
||||||
['%.%.ch$'] = 'chill',
|
['%.%.ch$'] = 'chill',
|
||||||
['%.cmake%.in$'] = 'cmake',
|
['%.cmake%.in$'] = 'cmake',
|
||||||
['^crontab%.'] = starsetf('crontab'),
|
['^crontab%.'] = starsetf('crontab'),
|
||||||
['^cvs%d+$'] = 'cvs',
|
['^cvs%d+$'] = 'cvs',
|
||||||
['%.[Dd][Aa][Tt]$'] = detect.dat,
|
|
||||||
['^php%.ini%-'] = 'dosini',
|
['^php%.ini%-'] = 'dosini',
|
||||||
['^drac%.'] = starsetf('dracula'),
|
['^drac%.'] = starsetf('dracula'),
|
||||||
['/dtrace/.*%.d$'] = 'dtrace',
|
['/dtrace/.*%.d$'] = 'dtrace',
|
||||||
@@ -2253,38 +2347,28 @@ local pattern = {
|
|||||||
['^[jt]sconfig.*%.json$'] = 'jsonc',
|
['^[jt]sconfig.*%.json$'] = 'jsonc',
|
||||||
['^Config%.in%.'] = starsetf('kconfig'),
|
['^Config%.in%.'] = starsetf('kconfig'),
|
||||||
['^Kconfig%.'] = starsetf('kconfig'),
|
['^Kconfig%.'] = starsetf('kconfig'),
|
||||||
['%.[Ss][Uu][Bb]$'] = 'krl',
|
|
||||||
['/ldscripts/'] = 'ld',
|
['/ldscripts/'] = 'ld',
|
||||||
['lftp/rc$'] = 'lftp',
|
['lftp/rc$'] = 'lftp',
|
||||||
['/LiteStep/.*/.*%.rc$'] = 'litestep',
|
['/LiteStep/.*/.*%.rc$'] = 'litestep',
|
||||||
['%.[Ll][Oo][Gg]$'] = detect.log,
|
|
||||||
['^/tmp/SLRN[0-9A-Z.]+$'] = 'mail',
|
['^/tmp/SLRN[0-9A-Z.]+$'] = 'mail',
|
||||||
['^ae%d+%.txt$'] = 'mail',
|
['^ae%d+%.txt$'] = 'mail',
|
||||||
['^pico%.%d+$'] = 'mail',
|
['^pico%.%d+$'] = 'mail',
|
||||||
['^reportbug%-'] = starsetf('mail'),
|
['^reportbug%-'] = starsetf('mail'),
|
||||||
['^snd%.%d+$'] = 'mail',
|
['^snd%.%d+$'] = 'mail',
|
||||||
['%.[Mm][Oo][Dd]$'] = detect.mod,
|
|
||||||
['^rndc.*%.key$'] = 'named',
|
['^rndc.*%.key$'] = 'named',
|
||||||
['%.NS[ACGLMNPS]$'] = 'natural',
|
|
||||||
['%.[1-9]$'] = detect.nroff,
|
|
||||||
['^tmac%.'] = starsetf('nroff'),
|
['^tmac%.'] = starsetf('nroff'),
|
||||||
['%.ml%.cppo$'] = 'ocaml',
|
['%.ml%.cppo$'] = 'ocaml',
|
||||||
['%.mli%.cppo$'] = 'ocaml',
|
['%.mli%.cppo$'] = 'ocaml',
|
||||||
['/octave/history$'] = 'octave',
|
['/octave/history$'] = 'octave',
|
||||||
['%.opam%.locked$'] = 'opam',
|
['%.opam%.locked$'] = 'opam',
|
||||||
['%.opam%.template$'] = 'opam',
|
['%.opam%.template$'] = 'opam',
|
||||||
['%.[Oo][Pp][Ll]$'] = 'opl',
|
|
||||||
['%.php%d$'] = 'php',
|
|
||||||
['%.[Pp][Rr][Gg]$'] = detect.prg,
|
|
||||||
['printcap'] = starsetf(function(path, bufnr)
|
['printcap'] = starsetf(function(path, bufnr)
|
||||||
return require('vim.filetype.detect').printcap('print')
|
return require('vim.filetype.detect').printcap('print')
|
||||||
end),
|
end),
|
||||||
['/queries/.*%.scm$'] = 'query', -- treesitter queries (Neovim only)
|
['/queries/.*%.scm$'] = 'query', -- treesitter queries (Neovim only)
|
||||||
[',v$'] = 'rcs',
|
[',v$'] = 'rcs',
|
||||||
['%.[Ss][Rr][Cc]$'] = detect.src,
|
|
||||||
['^svn%-commit.*%.tmp$'] = 'svn',
|
['^svn%-commit.*%.tmp$'] = 'svn',
|
||||||
['%.swift%.gyb$'] = 'swiftgyb',
|
['%.swift%.gyb$'] = 'swiftgyb',
|
||||||
['%.[Ss][Yy][Ss]$'] = detect.sys,
|
|
||||||
['termcap'] = starsetf(function(path, bufnr)
|
['termcap'] = starsetf(function(path, bufnr)
|
||||||
return require('vim.filetype.detect').printcap('term')
|
return require('vim.filetype.detect').printcap('term')
|
||||||
end),
|
end),
|
||||||
|
|||||||
Reference in New Issue
Block a user