Skip to content

Commit f9f5424

Browse files
Freed-Wuraimon49
authored andcommitted
patch 9.1.0326: filetype: some requirements files are not recognized
Problem: filetype: some requirements files are not recognized Solution: Detect '*-requirements.txt', 'constraints.txt', 'requirements.in', 'requirements/*.txt' and 'requires/*.txt' as requirements filetype, include pip compiler, include requirements filetype and syntax plugin (Wu, Zhenyu, @raimon49) closes: #14379 Co-authored-by: raimon <raimon49@hotmail.com> Signed-off-by: Wu, Zhenyu <wuzhenyu@ustc.edu> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 62c09e0 commit f9f5424

7 files changed

Lines changed: 163 additions & 3 deletions

File tree

runtime/compiler/pip_compile.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
" the Requirements File Format syntax support for Vim
2+
" Version: 1.8.0
3+
" Author: raimon <raimon49@hotmail.com>
4+
" Upstream: https://github.com/raimon49/requirements.txt.vim
5+
" License: MIT LICENSE
6+
" The MIT License (MIT)
7+
"
8+
" Copyright (c) 2015 raimon
9+
"
10+
" Permission is hereby granted, free of charge, to any person obtaining a copy
11+
" of this software and associated documentation files (the "Software"), to deal
12+
" in the Software without restriction, including without limitation the rights
13+
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
" copies of the Software, and to permit persons to whom the Software is
15+
" furnished to do so, subject to the following conditions:
16+
"
17+
" The above copyright notice and this permission notice shall be included in all
18+
" copies or substantial portions of the Software.
19+
"
20+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
" SOFTWARE.
27+
28+
if exists('b:current_compiler')
29+
finish
30+
endif
31+
let b:current_compiler = 'pip_compile'
32+
33+
let s:save_cpoptions = &cpoptions
34+
set cpoptions&vim
35+
36+
CompilerSet makeprg=pip-compile\ %:S
37+
CompilerSet errorformat=%ECould\ not\ find\ a\ version\ that\ matches\ %o\ (from\ -r\ %f\ (line\ %l)),
38+
\%C%m,
39+
\%Z,
40+
\%-G%.%#
41+
let &cpoptions = s:save_cpoptions
42+
unlet s:save_cpoptions
43+
" vim: et sw=4 ts=4 sts=4:

runtime/filetype.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,11 @@ au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex setf pine
17291729
" Pip requirements
17301730
au BufNewFile,BufRead *.pip setf requirements
17311731
au BufNewFile,BufRead requirements.txt setf requirements
1732+
au BufNewFile,BufRead *-requirements.txt setf requirements
1733+
au BufNewFile,BufRead constraints.txt setf requirements
1734+
au BufNewFile,BufRead requirements.in setf requirements
1735+
au BufNewFile,BufRead requirements/*.txt setf requirements
1736+
au BufNewFile,BufRead requires/*.txt setf requirements
17321737

17331738
" Pipenv Pipfiles
17341739
au BufNewFile,BufRead Pipfile setf toml

runtime/ftplugin/requirements.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
" the Requirements File Format syntax support for Vim
2+
" Version: 1.8.0
3+
" Author: raimon <raimon49@hotmail.com>
4+
" Upstream: https://github.com/raimon49/requirements.txt.vim
5+
" License: MIT LICENSE
6+
" The MIT License (MIT)
7+
"
8+
" Copyright (c) 2015 raimon
9+
"
10+
" Permission is hereby granted, free of charge, to any person obtaining a copy
11+
" of this software and associated documentation files (the "Software"), to deal
12+
" in the Software without restriction, including without limitation the rights
13+
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
" copies of the Software, and to permit persons to whom the Software is
15+
" furnished to do so, subject to the following conditions:
16+
"
17+
" The above copyright notice and this permission notice shall be included in all
18+
" copies or substantial portions of the Software.
19+
"
20+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
" SOFTWARE.
27+
if exists("b:did_ftplugin")
28+
finish
29+
endif
30+
let b:did_ftplugin = 1
31+
32+
let s:save_cpoptions = &cpoptions
33+
set cpoptions&vim
34+
35+
let b:undo_ftplugin = "setl iskeyword< commentstring<"
36+
" pip options contain "-"
37+
setlocal iskeyword+=-
38+
setlocal commentstring=#\ %s
39+
compiler pip_compile
40+
41+
let &cpoptions = s:save_cpoptions
42+
unlet s:save_cpoptions
43+
" vim: et sw=4 ts=4 sts=4:

runtime/syntax/requirements.vim

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
" the Requirements File Format syntax support for Vim
2+
" Version: 1.8.0
3+
" Author: raimon <raimon49@hotmail.com>
4+
" Upstream: https://github.com/raimon49/requirements.txt.vim
5+
" License: MIT LICENSE
6+
" The MIT License (MIT)
7+
"
8+
" Copyright (c) 2015 raimon
9+
"
10+
" Permission is hereby granted, free of charge, to any person obtaining a copy
11+
" of this software and associated documentation files (the "Software"), to deal
12+
" in the Software without restriction, including without limitation the rights
13+
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
" copies of the Software, and to permit persons to whom the Software is
15+
" furnished to do so, subject to the following conditions:
16+
"
17+
" The above copyright notice and this permission notice shall be included in all
18+
" copies or substantial portions of the Software.
19+
"
20+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
" SOFTWARE.
27+
28+
if exists("b:current_syntax") && b:current_syntax == "requirements"
29+
finish
30+
endif
31+
32+
syn case match
33+
34+
" https://pip.pypa.io/en/stable/reference/requirements-file-format/
35+
" https://pip.pypa.io/en/stable/reference/inspect-report/#example
36+
syn keyword requirementsKeyword implementation_name implementation_version os_name platform_machine platform_release platform_system platform_version python_full_version platform_python_implementation python_version sys_platform contained
37+
syn region requirementsSubst matchgroup=requirementsSubstDelim start="\V${" end="\V}"
38+
syn region requirementsString matchgroup=requirementsStringDelim start=`'` skip=`\\'` end=`'`
39+
syn region requirementsString matchgroup=requirementsStringDelim start=`"` skip=`\\"` end=`"`
40+
syn match requirementsVersion "\v\d+[a-zA-Z0-9\.\-\*]*"
41+
syn region requirementsComment start="[ \t]*#" end="$"
42+
syn match requirementsCommandOption "\v^\[?--?[a-zA-Z\-]*\]?"
43+
syn match requirementsVersionSpecifiers "\v(\=\=\=?|\<\=?|\>\=?|\~\=|\!\=)"
44+
syn match requirementsPackageName "\v^([a-zA-Z0-9][a-zA-Z0-9\-_\.]*[a-zA-Z0-9])"
45+
syn match requirementsExtras "\v\[\S+\]"
46+
syn match requirementsVersionControls "\v(git\+?|hg\+|svn\+|bzr\+).*://.\S+"
47+
syn match requirementsURLs "\v(\@\s)?(https?|ftp|gopher)://?[^\s/$.?#].\S*"
48+
syn match requirementsEnvironmentMarkers "\v;\s[^#]+" contains=requirementsKeyword,requirementsVersionSpecifiers,requirementsString
49+
50+
hi def link requirementsKeyword Keyword
51+
hi def link requirementsSubstDelim Delimiter
52+
hi def link requirementsSubst PreProc
53+
hi def link requirementsStringDelim Delimiter
54+
hi def link requirementsString String
55+
hi def link requirementsVersion Number
56+
hi def link requirementsComment Comment
57+
hi def link requirementsCommandOption Special
58+
hi def link requirementsVersionSpecifiers Boolean
59+
hi def link requirementsPackageName Identifier
60+
hi def link requirementsExtras Type
61+
hi def link requirementsVersionControls Underlined
62+
hi def link requirementsURLs Underlined
63+
hi def link requirementsEnvironmentMarkers Macro
64+
65+
let b:current_syntax = "requirements"
66+
67+
" vim: et sw=4 ts=4 sts=4:

src/testdir/test_compiler.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func Test_compiler_completion()
7171
call assert_match('^"compiler ' .. clist .. '$', @:)
7272

7373
call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx')
74-
call assert_match('"compiler pandoc pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
74+
call assert_match('"compiler pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
7575

7676
call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx')
77-
call assert_match('"compiler! pandoc pbx perl\( p[a-z]\+\)\+ pylint pyunit', @:)
77+
call assert_match('"compiler! pandoc pbx perl\( p[a-z_]\+\)\+ pylint pyunit', @:)
7878
endfunc
7979

8080
func Test_compiler_error()

src/testdir/test_filetype.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def s:GetFilenameChecks(): dict<list<string>>
594594
readline: ['.inputrc', 'inputrc'],
595595
rego: ['file.rego'],
596596
remind: ['.reminders', 'file.remind', 'file.rem', '.reminders-file'],
597-
requirements: ['file.pip', 'requirements.txt'],
597+
requirements: ['file.pip', 'requirements.txt', 'dev-requirements.txt', 'constraints.txt', 'requirements.in', 'requirements/dev.txt', 'requires/dev.txt'],
598598
rescript: ['file.res', 'file.resi'],
599599
resolv: ['resolv.conf'],
600600
reva: ['file.frt'],

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
326,
707709
/**/
708710
325,
709711
/**/

0 commit comments

Comments
 (0)