-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Describe the bug
In Vim9 script, we cannot put an inline comment after the opening parenthesis in a function header.
To Reproduce
Run this shell command:
vim -Nu NONE -S <(cat <<'EOF'
vim9
def Func( # this is the function name
n: number, # this is a number
s: string # this is a string
)
echo [n, s]
enddef
Func(123, 'string')
EOF
)
E125 is raised:
E125: Illegal argument: # this is the function name
Expected behavior
No error is raised.
Environment
- Vim version: 8.2 Included patches: 1-2293
- OS: Ubuntu 16.04.7 LTS
- Terminal: xterm(363)
Additional context
The same code doesn't raise any error when we remove the inline comment after the opening parenthesis.
vim9
def Func(
n: number, # this is a number
s: string # this is a string
)
echo [n, s]
enddef
Func(123, 'string')[123, 'string']
Vim is perfectly able to skip over an inline comment after the opening parenthesis in a function call:
vim9
def Func(n: number, s: string)
echo [n, s]
enddef
Func( # some comment
123, # some comment
'string' # some comment
)[123, 'string']
All of this is inconsistent.
We can put an inline comment after:
(in a function call- an argument in a function call
- an argument in a function header
But we cannot put an inline comment after ( in a function header.
It would be useful, for example, for a folding marker:
def Func( #{{{1
Otherwise, if we want to fold a function with a long header, and we want to split the latter on multiple lines, we need to do either this:
def ComplexHeaderWithLotsOfArguments(arg1: number, #{{{1
arg2: string,
arg3: bool,
...
Or this:
ComplexHeaderWithLotsOfArguments #{{{1
def ComplexHeaderWithLotsOfArguments(
arg1: number,
arg2: string,
arg3: bool,
...
It's subjective, but I find the first snippet ugly because asymmetric (only the first argument is joined with the function name line), and the second snippet forces us to repeat the function name.
For a real example, see here.