Fix detection of conf files, closes #569

This commit is contained in:
Adam Stankiewicz
2020-09-29 19:11:11 +02:00
parent 46b09b0d5b
commit 1872af2d5e
9 changed files with 201 additions and 71 deletions

View File

@@ -7,7 +7,7 @@ A collection of language packs for Vim.
> One to rule them all, one to find them, one to bring them all and in the darkness bind them.
- It **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 120+ times faster** than the <!--Package Count-->202<!--/Package Count--> packages it consists of.
- It **installs and updates 120+ times faster** than the <!--Package Count-->203<!--/Package Count--> packages it consists of.
- It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect).
- Solid syntax and indentation support (other features skipped). Only the best language packs.
- All unnecessary files are ignored (like enormous documentation from php support).
@@ -89,6 +89,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [clojure](https://github.com/guns/vim-clojure-static)
- [cmake](https://github.com/pboettch/vim-cmake-syntax)
- [coffee-script](https://github.com/kchmck/vim-coffee-script)
- [conf](https://github.com/vim/vim/tree/master/runtime)
- [cpp-modern](https://github.com/bfrg/vim-cpp-modern)
- [cql](https://github.com/elubow/cql-vim)
- [cryptol](https://github.com/victoredwardocallaghan/cryptol.vim)

View File

@@ -45,6 +45,7 @@ let s:globs = {
\ 'clojure': '*.clj,*.boot,*.cl2,*.cljc,*.cljs,*.cljs.hl,*.cljscm,*.cljx,*.hic,*.edn,riemann.config,build.boot,profile.boot',
\ 'cmake': '*.cmake,*.cmake.in,CMakeLists.txt',
\ 'coffee': '*.coffee,*._coffee,*.cake,*.cjsx,*.iced,*.coffeekup,Cakefile',
\ 'conf': '*.conf,auto.master,config',
\ 'cpp': '*.cpp,*.c++,*.cc,*.cp,*.cxx,*.h,*.h++,*.hh,*.hpp,*.hxx,*.inc,*.inl,*.ipp,*.tcc,*.tpp,*.moc,*.tlh',
\ 'cql': '*.cql',
\ 'cryptol': '*.cry,*.cyl,*.lcry,*.lcyl',
@@ -94,7 +95,7 @@ let s:globs = {
\ 'groovy': '*.groovy,*.grt,*.gtpl,*.gvy,*.gradle,Jenkinsfile',
\ 'grub': '',
\ 'haml': '*.haml,*.haml.deface,*.hamlc,*.hamlbars',
\ 'haproxy': '*.cfg,haproxy.cfg,haproxy*.c*',
\ 'haproxy': '*.cfg,haproxy.cfg,haproxy*.conf*',
\ 'haskell': '*.hs,*.hs-boot,*.hsc,*.bpk,*.hsig',
\ 'haxe': '*.hx,*.hxsl',
\ 'hcl': '*.hcl,*.nomad,*.workflow,Appfile',

View File

@@ -102,6 +102,10 @@ if !has_key(s:disabled_packages, '8th')
au! BufRead,BufNewFile *.8th
endif
if !has_key(s:disabled_packages, 'conf')
au! BufRead,BufNewFile auto.master
endif
if !has_key(s:disabled_packages, 'haproxy')
au! BufRead,BufNewFile *.cfg
endif
@@ -254,6 +258,10 @@ if !has_key(s:disabled_packages, 'dlang')
au! BufRead,BufNewFile *.sdl
endif
if !has_key(s:disabled_packages, 'yaml')
au! BufRead,BufNewFile *.yml,*.yaml
endif
if !has_key(s:disabled_packages, 'dockerfile')
au! BufRead,BufNewFile *.Dockerfile,Dockerfile
endif
@@ -270,10 +278,6 @@ if !has_key(s:disabled_packages, 'forth')
au! BufRead,BufNewFile *.fs,*.ft,*.fth
endif
if !has_key(s:disabled_packages, 'glsl')
au! BufRead,BufNewFile *.fs,*.gs,*.comp
endif
if !has_key(s:disabled_packages, 'fsharp')
au! BufRead,BufNewFile *.fs
endif
@@ -282,6 +286,10 @@ if !has_key(s:disabled_packages, 'git')
au! BufRead,BufNewFile .gitconfig,.gitmodules,*.git/config,*/.config/git/config,*.git/modules/*/config,git-rebase-todo
endif
if !has_key(s:disabled_packages, 'glsl')
au! BufRead,BufNewFile *.fs,*.gs,*.comp
endif
if !has_key(s:disabled_packages, 'gnuplot')
au! BufRead,BufNewFile *.gp,*.gpi
endif
@@ -482,10 +490,6 @@ if !has_key(s:disabled_packages, 'xsl')
au! BufRead,BufNewFile *.xslt,*.xsl
endif
if !has_key(s:disabled_packages, 'yaml')
au! BufRead,BufNewFile *.yml,*.yaml
endif
if !has_key(s:disabled_packages, 'help')
au! BufRead,BufNewFile $VIMRUNTIME/doc/*.txt
endif
@@ -518,9 +522,13 @@ if !has_key(s:disabled_packages, '8th')
au BufNewFile,BufRead *.8th set ft=8th
endif
if !has_key(s:disabled_packages, 'conf')
au BufNewFile,BufRead *.conf,auto.master,config set ft=conf
endif
if !has_key(s:disabled_packages, 'haproxy')
au BufNewFile,BufRead *.cfg,haproxy.cfg set ft=haproxy
au BufNewFile,BufRead haproxy*.c* call s:StarSetf('haproxy')
au BufNewFile,BufRead haproxy*.conf* call s:StarSetf('haproxy')
endif
if !has_key(s:disabled_packages, 'a2ps')
@@ -583,6 +591,10 @@ if !has_key(s:disabled_packages, 'ampl')
au BufNewFile,BufRead *.run set ft=ampl
endif
if !has_key(s:disabled_packages, 'csv')
au BufNewFile,BufRead *.csv,*.tab,*.tsv set ft=csv
endif
if !has_key(s:disabled_packages, 'xml')
au BufNewFile,BufRead *.adml,*.admx,*.ant,*.axml,*.builds,*.ccproj,*.ccxml,*.cdxml,*.clixml,*.cproject,*.cscfg,*.csdef,*.csl,*.csproj,*.csproj.user,*.ct,*.depproj,*.dita,*.ditamap,*.ditaval,*.dll.config,*.dotsettings,*.filters,*.fsproj,*.fxml,*.glade,*.gml,*.gmx,*.grxml,*.gst,*.iml,*.ivy,*.jelly,*.jsproj,*.kml,*.launch,*.mdpolicy,*.mjml,*.mm,*.mod,*.mxml,*.natvis,*.ncl,*.ndproj,*.nproj,*.nuspec,*.odd,*.osm,*.pkgproj,*.pluginspec,*.proj,*.props,*.ps1xml,*.psc1,*.pt,*.rdf,*.resx,*.rss,*.sch,*.scxml,*.sfproj,*.shproj,*.srdf,*.storyboard,*.sublime-snippet,*.targets,*.tml,*.tpm,*.ui,*.urdf,*.ux,*.vbproj,*.vcxproj,*.vsixmanifest,*.vssettings,*.vstemplate,*.vxml,*.wixproj,*.workflow,*.wpl,*.wsdl,*.wsf,*.wxi,*.wxl,*.wxs,*.x3d,*.xacro,*.xaml,*.xib,*.xlf,*.xliff,*.xmi,*.xml,*.xml.dist,*.xproj,*.xsd,*.xspec,*.xul,*.zcml,*/etc/blkid.tab,*/etc/blkid.tab.old,*/etc/xdg/menus/*.menu,*fglrxrc,{.,}classpath,{.,}cproject,{.,}project,App.config,NuGet.config,Settings.StyleCop,Web.Debug.config,Web.Release.config,Web.config,packages.config set ft=xml
endif
@@ -717,10 +729,6 @@ if !has_key(s:disabled_packages, 'crystal')
au BufNewFile,BufRead *.cr,Projectfile set ft=crystal
endif
if !has_key(s:disabled_packages, 'csv')
au BufNewFile,BufRead *.csv,*.tab,*.tsv set ft=csv
endif
if !has_key(s:disabled_packages, 'cucumber')
au BufNewFile,BufRead *.feature,*.story set ft=cucumber
endif
@@ -745,6 +753,10 @@ if !has_key(s:disabled_packages, 'dlang')
au BufNewFile,BufRead *.d,*.di set ft=d
endif
if !has_key(s:disabled_packages, 'yaml')
au BufNewFile,BufRead *.mir,*.reek,*.rviz,*.sublime-syntax,*.syntax,*.yaml,*.yaml-tmlanguage,*.yaml.sed,*.yml,*.yml.mysql,{.,}clang-format,{.,}clang-tidy,{.,}gemrc,fish_history,fish_read_history,glide.lock,yarn.lock set ft=yaml
endif
if !has_key(s:disabled_packages, 'dockerfile')
au BufNewFile,BufRead docker-compose*.yaml,docker-compose*.yml set ft=yaml.docker-compose
au BufNewFile,BufRead *.Dockerfile,*.dock,*.dockerfile,Dockerfile,dockerfile set ft=Dockerfile
@@ -793,11 +805,6 @@ if !has_key(s:disabled_packages, 'forth')
au BufNewFile,BufRead *.ft,*.fth set ft=forth
endif
if !has_key(s:disabled_packages, 'glsl')
au! BufNewFile,BufRead *.fs call polyglot#DetectFsFiletype()
au BufNewFile,BufRead *.comp,*.fp,*.frag,*.frg,*.fsh,*.fshader,*.geo,*.geom,*.glsl,*.glslf,*.glslv,*.gs,*.gshader,*.shader,*.tesc,*.tese,*.vert,*.vrx,*.vsh,*.vshader set ft=glsl
endif
if !has_key(s:disabled_packages, 'fsharp')
au! BufNewFile,BufRead *.fs call polyglot#DetectFsFiletype()
au BufNewFile,BufRead *.fsi,*.fsx set ft=fsharp
@@ -815,6 +822,11 @@ if !has_key(s:disabled_packages, 'git')
au BufNewFile,BufRead */{.,}gitconfig.d/* call s:StarSetf('gitconfig')
endif
if !has_key(s:disabled_packages, 'glsl')
au! BufNewFile,BufRead *.fs call polyglot#DetectFsFiletype()
au BufNewFile,BufRead *.comp,*.fp,*.frag,*.frg,*.fsh,*.fshader,*.geo,*.geom,*.glsl,*.glslf,*.glslv,*.gs,*.gshader,*.shader,*.tesc,*.tese,*.vert,*.vrx,*.vsh,*.vshader set ft=glsl
endif
if !has_key(s:disabled_packages, 'gmpl')
au BufNewFile,BufRead *.mod set ft=gmpl
endif
@@ -1333,10 +1345,6 @@ if !has_key(s:disabled_packages, 'xsl')
au BufNewFile,BufRead *.xsl,*.xslt set ft=xsl
endif
if !has_key(s:disabled_packages, 'yaml')
au BufNewFile,BufRead *.mir,*.reek,*.rviz,*.sublime-syntax,*.syntax,*.yaml,*.yaml-tmlanguage,*.yaml.sed,*.yml,*.yml.mysql,{.,}clang-format,{.,}clang-tidy,{.,}gemrc,fish_history,fish_read_history,glide.lock,yarn.lock set ft=yaml
endif
if !has_key(s:disabled_packages, 'ansible')
au BufNewFile,BufRead handlers.*.y{a,}ml,local.y{a,}ml,main.y{a,}ml,playbook.y{a,}ml,requirements.y{a,}ml,roles.*.y{a,}ml,site.y{a,}ml,tasks.*.y{a,}ml set ft=yaml.ansible
au BufNewFile,BufRead host_vars/* call s:StarSetf('yaml.ansible')

23
ftplugin/conf.vim Normal file
View File

@@ -0,0 +1,23 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'conf') == -1
" Vim filetype plugin file
" Language: generic configuration file
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2008-07-09
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let s:cpo_save = &cpo
set cpo&vim
let b:undo_ftplugin = "setl com< cms< fo<"
setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
let &cpo = s:cpo_save
unlet s:cpo_save
endif

View File

@@ -10,8 +10,6 @@ filetypes:
name: a2ps
remote: vim/vim:runtime
glob: '**/a2ps.vim'
after:
- haproxy
filetypes:
- name: a2ps
filenames:
@@ -142,7 +140,6 @@ filetypes:
name: ant
remote: vim/vim:runtime
glob: '**/ant.vim'
after: xml
filetypes:
- name: ant
filenames:
@@ -210,7 +207,7 @@ filetypes:
---
name: arduino
remote: sudar/vim-arduino-syntax
after: c/c++
dependencies: c/c++
filetypes:
- name: arduino
linguist: Processing
@@ -240,7 +237,6 @@ filetypes:
name: automake
remote: vim/vim:runtime
glob: '**/automake.vim'
after: elf
filetypes:
- name: automake
filenames:
@@ -260,7 +256,6 @@ name: aspvbs
remote: vim/vim:runtime
globs:
- '**/aspvbs.vim'
dependencies:
filetypes:
- name: aspvbs
extensions:
@@ -271,7 +266,6 @@ name: aspperl
remote: vim/vim:runtime
globs:
- '**/aspperl.vim'
dependencies:
filetypes:
- name: aspperl
extensions:
@@ -347,7 +341,7 @@ filetypes:
---
name: cpp-modern
remote: bfrg/vim-cpp-modern
after: c/c++
dependencies: c/c++
filetypes: []
---
name: carp
@@ -590,7 +584,6 @@ name: fsharp
remote: ionide/Ionide-vim
ignored_dirs:
- ftplugin
after: glsl
filetypes:
- name: fsharp
linguist: F#
@@ -681,7 +674,8 @@ filetypes:
---
name: graphql
remote: jparise/vim-graphql
after: [javascript, jsx]
dependencies: javascript
after: jsx
ignored_dirs:
# TODO: remove after bug is fixed:
# https://github.com/jparise/vim-graphql/issues/62
@@ -692,7 +686,7 @@ filetypes:
---
name: gradle
remote: tfnico/vim-gradle
after: groovy
dependencies: groovy
# Just adds compiler
filetypes: []
---
@@ -708,7 +702,6 @@ filetypes:
name: grub
remote: vim/vim:runtime
glob: '**/grub.vim'
after: dlang
filetypes:
- name: grub
filenames:
@@ -747,6 +740,8 @@ filetypes:
- name: haproxy
linguist: HAProxy
extra_filenames:
- 'haproxy*.conf*'
ignored_warnings:
- 'haproxy*.c*'
---
name: haskell
@@ -858,7 +853,7 @@ filetypes:
---
name: javascript-sql
remote: statico/vim-javascript-sql
after: javascript
dependencies: javascript
filetypes: []
---
name: jenkins
@@ -931,7 +926,7 @@ filetypes:
---
name: jsx
remote: MaxMEllon/vim-jsx-pretty
after: javascript
dependencies: javascript
filetypes:
- name: javascriptreact
linguist: JSX
@@ -1158,7 +1153,7 @@ filetypes:
---
name: octave
remote: McSinyx/vim-octave
after: mathematica
dependencies: mathematica
filetypes:
- name: octave
extensions:
@@ -1223,7 +1218,7 @@ filetypes:
---
name: blade
remote: jwalton512/vim-blade
after: php
dependencies: php
filetypes:
- name: blade
linguist: Blade
@@ -1245,7 +1240,6 @@ filetypes:
---
name: powershell
remote: PProvost/vim-ps1
after: xml
filetypes:
- name: ps1
linguist: PowerShell
@@ -1388,7 +1382,6 @@ filetypes:
---
name: reason
remote: reasonml-editor/vim-reason-plus
after: c/c++
filetypes:
- name: reason
linguist: Reason
@@ -1780,7 +1773,7 @@ filetypes:
---
name: ansible
remote: pearofducks/ansible-vim
after: yaml
dependencies: yaml
filetypes:
- name: yaml.ansible
filenames:
@@ -1928,3 +1921,14 @@ filetypes:
- tyb
- typ
- tyc
---
name: conf
remote: vim/vim:runtime
glob: '**/conf.vim'
filetypes:
- name: conf
extensions:
- conf
filenames:
- auto.master
- config

View File

@@ -27,23 +27,81 @@ def except(hash, *keys)
h
end
def verify(packages, heuristics)
extensions_with_heuristics = Set.new(heuristics.flat_map { |e| e["extensions"] })
no_heuristics = Hash.new { |a, b| a[b] = [] }
for p in packages
for f in p["filetypes"]
for e in f["extensions"]
if !extensions_with_heuristics.include?(e)
no_heuristics[e] << p["name"]
end
end
end
end
no_heuristics.select! { |a, b| b.size > 1}
for e, names in no_heuristics
if ENV["DEV"]
puts "No heuristics for .#{e} extension (#{names.join(", ")})"
end
end
end
def sort_packages(packages)
implicit_dependencies = Hash.new { |h, k| h[k] = [] }
by_extension = Hash.new { |h, k| h[k] = [] }
for p in packages
for f in p["filetypes"]
for e in f["extensions"]
by_extension[e] << p["name"]
end
end
end
for p in packages
for f in p["filetypes"]
for t in f["filenames"]
filename = t.split('/').last
if filename.include?(".")
ext = filename.split(".").last.gsub('*', '')
if by_extension[ext]
for name in by_extension[ext]
if p["name"] != name
implicit_dependencies[p["name"]] |= [name]
end
end
end
end
end
end
end
packages = Hash[packages.group_by { |a| a.fetch("name") }.map { |a, b| [a, b.first] }]
each_node = lambda { |&b| packages.keys.each(&b) }
each_child = lambda { |n, &b|
[
implicit_dependencies[n] || [],
packages[n]["dependencies"] || [],
packages[n]["after"] || []
].flatten.each(&b)
}
TSort.tsort(each_node, each_child).map { |a| packages[a] }
end
def load_data()
packages = Hash[YAML.load_stream(File.read('packages.yaml'))
.group_by { |a| a.fetch("name") }
.map { |a, b| [a, b.first] }]
deps = Hash.new { |h, k| h[k] = [] }
each_node = lambda {|&b| packages.keys.each(&b) }
each_child = lambda {|n, &b| [packages[n]["after"] || []].flatten.each(&b) }
packages = load_packages
languages = load_languages
heuristics = load_heuristics
# Reason can have ocaml as interpreter but let's not depend on it...
languages["Reason"]["interpreters"] -= ["ocaml"]
packages = TSort.tsort(each_node, each_child).map { |a| packages[a] }
for package in packages
for filetype in package["filetypes"]
if filetype["linguist"]
@@ -90,7 +148,9 @@ def load_data()
end
end
heuristics = YAML.load_stream(File.read('heuristics.yaml'))
verify(packages, heuristics)
packages = sort_packages(packages)
[packages, transform_patterns(heuristics)]
end
@@ -144,6 +204,14 @@ def load_languages
YAML.load(File.read(file))
end
def load_packages
YAML.load_stream(File.read('packages.yaml'))
end
def load_heuristics
YAML.load_stream(File.read('heuristics.yaml'))
end
def parse_remote(remote)
match = remote.match(/(?<repo>[^@:]+)(?:@(?<branch>[^:]+))?(?::(?<path>.*))?/)
dir = "tmp/" + match[:repo] + (match[:branch] ? "-#{match[:branch]}" : "")
@@ -423,16 +491,6 @@ end
def generate_ftdetect(packages, heuristics)
output = "\n"
extensions = Hash.new { |h, k| h[k] = [] }
for package in packages
for filetype in package["filetypes"]
for ext in filetype["extensions"]
extensions[ext] << filetype["name"]
end
end
end
all_filetypes = packages.flat_map { |f| f["filetypes"] || [] }
filetype_names = Set.new(all_filetypes.map { |f| f["name"] })
@@ -738,8 +796,8 @@ def show_warnings(all_filetypes, expected_filetypes)
all_handled = process_list(all_filetypes, all_expected) do |f|
[f["filenames"], f["ignored_filenames"], f["ignored_warnings"]].compact.flatten +
[f["extensions"], f["ignored_extensions"]].compact.flatten.map { |e| "*." + e }
[f["filenames"], f["ignored_filenames"], f["ignored_warnings"], f["extra_filenames"]].compact.flatten +
[f["extensions"], f["ignored_extensions"], f["extra_extensions"]].compact.flatten.map { |e| "*." + e }
end
all_handled_regexps = Hash[all_handled.group_by { |a, b| a }.map do |a, b|

30
syntax/conf.vim Normal file
View File

@@ -0,0 +1,30 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'conf') == -1
" Vim syntax file
" Language: generic configure file
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2005 Jun 20
" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
finish
endif
syn keyword confTodo contained TODO FIXME XXX
" Avoid matching "text#text", used in /etc/disktab and /etc/gettytab
syn match confComment "^#.*" contains=confTodo
syn match confComment "\s#.*"ms=s+1 contains=confTodo
syn region confString start=+"+ skip=+\\\\\|\\"+ end=+"+ oneline
syn region confString start=+'+ skip=+\\\\\|\\'+ end=+'+ oneline
" Define the default highlighting.
" Only used when an item doesn't have highlighting yet
hi def link confComment Comment
hi def link confTodo Todo
hi def link confString String
let b:current_syntax = "conf"
" vim: ts=8 sw=2
endif

View File

@@ -376,6 +376,10 @@ call TestExtension("html", "template.html", "{{ item.href }}")
call TestExtension("gitignore", ".gitignore", "")
" .xml
call TestExtension("xml", ".fglrxrc", "")
call TestExtension("xml", "fglrxrc", "")
" .conf
call TestExtension("conf", "foo.conf", "")
call TestExtension("conf", "config", "")
call TestExtension("conf", "auto.master", "")

View File

@@ -6,6 +6,7 @@ function! TestFiletype(filetype)
endfunction
call TestFiletype('8th')
call TestFiletype('conf')
call TestFiletype('haproxy')
call TestFiletype('a2ps')
call TestFiletype('a65')
@@ -22,6 +23,7 @@ call TestFiletype('aidl')
call TestFiletype('alsaconf')
call TestFiletype('aml')
call TestFiletype('ampl')
call TestFiletype('csv')
call TestFiletype('xml')
call TestFiletype('ant')
call TestFiletype('apache')
@@ -53,7 +55,6 @@ call TestFiletype('litcoffee')
call TestFiletype('cryptol')
call TestFiletype('crystal')
call TestFiletype('ecrystal')
call TestFiletype('csv')
call TestFiletype('cucumber')
call TestFiletype('cuesheet')
call TestFiletype('dart')
@@ -63,6 +64,7 @@ call TestFiletype('dcov')
call TestFiletype('dd')
call TestFiletype('ddoc')
call TestFiletype('dsdl')
call TestFiletype('yaml')
call TestFiletype('Dockerfile')
call TestFiletype('yaml.docker-compose')
call TestFiletype('elixir')
@@ -76,13 +78,13 @@ call TestFiletype('ferm')
call TestFiletype('fish')
call TestFiletype('fbs')
call TestFiletype('forth')
call TestFiletype('glsl')
call TestFiletype('fsharp')
call TestFiletype('gdscript3')
call TestFiletype('gitconfig')
call TestFiletype('gitrebase')
call TestFiletype('gitsendemail')
call TestFiletype('gitcommit')
call TestFiletype('glsl')
call TestFiletype('gmpl')
call TestFiletype('gnuplot')
call TestFiletype('go')
@@ -221,7 +223,6 @@ call TestFiletype('vmasm')
call TestFiletype('vue')
call TestFiletype('xdc')
call TestFiletype('xsl')
call TestFiletype('yaml')
call TestFiletype('yaml.ansible')
call TestFiletype('helm')
call TestFiletype('help')