mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
vim-patch:9.0.1478: filetypes for *.v files not detected properly (#23282)
* vim-patch:9.0.1478: filetypes for *.v files not detected properly
Problem: Filetypes for *.v files not detected properly.
Solution: Use the file contents to detect the filetype. (Turiiya,
closes vim/vim#12281)
80406c2618
Co-authored-by: Turiiya <34311583+tobealive@users.noreply.github.com>
Co-authored-by: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com>
This commit is contained in:
parent
bf0ac4f241
commit
f17bb4f411
@ -1091,7 +1091,9 @@ local extension = {
|
|||||||
vr = 'vera',
|
vr = 'vera',
|
||||||
vri = 'vera',
|
vri = 'vera',
|
||||||
vrh = 'vera',
|
vrh = 'vera',
|
||||||
v = 'verilog',
|
v = function(path, bufnr)
|
||||||
|
return require('vim.filetype.detect').v(bufnr)
|
||||||
|
end,
|
||||||
va = 'verilogams',
|
va = 'verilogams',
|
||||||
vams = 'verilogams',
|
vams = 'verilogams',
|
||||||
vhdl = 'vhdl',
|
vhdl = 'vhdl',
|
||||||
|
@ -1322,6 +1322,24 @@ function M.txt(bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Determine if a .v file is Verilog, V, or Coq
|
||||||
|
function M.v(bufnr)
|
||||||
|
if vim.fn.did_filetype() ~= 0 then
|
||||||
|
-- Filetype was already detected
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _, line in ipairs(getlines(bufnr, 1, 200)) do
|
||||||
|
if not line:find('^%s*/') then
|
||||||
|
if findany(line, { ';%s*$', ';%s*/' }) then
|
||||||
|
return 'verilog'
|
||||||
|
elseif findany(line, { '%.%s*$', '%.%s*%(%*' }) then
|
||||||
|
return 'coq'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 'v'
|
||||||
|
end
|
||||||
|
|
||||||
-- WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
|
-- WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
|
||||||
-- lines in a WEB file).
|
-- lines in a WEB file).
|
||||||
function M.web(bufnr)
|
function M.web(bufnr)
|
||||||
|
@ -646,7 +646,6 @@ let s:filename_checks = {
|
|||||||
\ 'vdmrt': ['file.vdmrt'],
|
\ 'vdmrt': ['file.vdmrt'],
|
||||||
\ 'vdmsl': ['file.vdm', 'file.vdmsl'],
|
\ 'vdmsl': ['file.vdm', 'file.vdmsl'],
|
||||||
\ 'vera': ['file.vr', 'file.vri', 'file.vrh'],
|
\ 'vera': ['file.vr', 'file.vri', 'file.vrh'],
|
||||||
\ 'verilog': ['file.v'],
|
|
||||||
\ 'verilogams': ['file.va', 'file.vams'],
|
\ 'verilogams': ['file.va', 'file.vams'],
|
||||||
\ 'vgrindefs': ['vgrindefs'],
|
\ 'vgrindefs': ['vgrindefs'],
|
||||||
\ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 'file.vhdl_123', 'file.vho', 'some.vhdl_1', 'some.vhdl_1-file'],
|
\ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 'file.vhdl_123', 'file.vho', 'some.vhdl_1', 'some.vhdl_1-file'],
|
||||||
@ -1771,6 +1770,27 @@ func Test_ttl_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_v_file()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
call writefile(['module tb; // Looks like a Verilog'], 'Xfile.v', 'D')
|
||||||
|
split Xfile.v
|
||||||
|
call assert_equal('verilog', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['module main'], 'Xfile.v')
|
||||||
|
split Xfile.v
|
||||||
|
call assert_equal('v', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['Definition x := 10. (*'], 'Xfile.v')
|
||||||
|
split Xfile.v
|
||||||
|
call assert_equal('coq', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_xpm_file()
|
func Test_xpm_file()
|
||||||
filetype on
|
filetype on
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user