Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved highlighting for argument count warnings
The highlighting for function calls with wrong arguments now applies to
the full function call expression, starting with the function's name and
continuing until the closing paren, even when the expression spans
multiple lines and/or includes comments, e.g.:

    function two_args(a, b) end

    -- this shouldn't be highlighted:
    two_args(1, 2)

    -- this should be highlighted:
    two_args --[[ foobar ]] (1)

    -- this should also be highlighted:
    two_args(
        var1,
        var2,
        var3)
  • Loading branch information
xolox committed Aug 15, 2010
1 parent 75359a0 commit 17bb37c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions autoload.vim
Expand Up @@ -174,14 +174,18 @@ endfunction
function! s:highlight_variables() " {{{1
call clearmatches()
for line in b:luainspect_output[1:-1]
if s:check_output(line, '^\w\+\(\s\+\d\+\)\{3}$')
let [group, linenum, firstcol, lastcol] = split(line)
let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
if s:check_output(line, '^\w\+\(\s\+\d\+\)\{4}$')
let [group, l1, c1, l2, c2] = split(line)
let l1 += 0
let c1 -= 1
let l2 += 0
let c2 += 2
if group == 'luaInspectWrongArgCount'
call matchadd(group, pattern)
call matchadd(group, s:highlight_position(l1, c1, l2, c2, 0))
elseif group == 'luaInspectSelectedVariable'
call matchadd(group, pattern, 20)
call matchadd(group, s:highlight_position(l1, c1, l2, c2, 1), 20)
else
let pattern = s:highlight_position(l1, c1, l2, c2, 1)
execute 'syntax match' group '/' . pattern . '/'
endif
endif
Expand All @@ -193,8 +197,11 @@ function! s:rename_variable() " {{{1
let highlights = []
for line in b:luainspect_output[1:-1]
if s:check_output(line, '^\d\+\(\s\+\d\+\)\{2}$')
let [linenum, firstcol, lastcol] = split(line)
let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
let [l1, c1, c2] = split(line)
let l1 += 0
let c1 -= 1
let c2 += 2
let pattern = s:highlight_position(l1, c1, l1, c2, 1)
call add(highlights, matchadd('IncSearch', pattern))
endif
endfor
Expand Down Expand Up @@ -233,9 +240,12 @@ function! s:check_output(line, pattern) " {{{1
endif
endfunction

function! s:highlight_position(linenum, firstcol, lastcol) " {{{1
return printf('\%%%il\%%>%ic\<\w\+\>\%%<%ic', a:linenum, a:firstcol, a:lastcol)
endfunction
function! s:highlight_position(l1, c1, l2, c2, ident_only) " {{{1
let l1 = a:l1 >= 1 ? (a:l1 - 1) : a:l1
let p = '\%>' . l1 . 'l\%>' . a:c1 . 'c'
let p .= a:ident_only ? '\<\w\+\>' : '\_.\+'
return p . '\%<' . (a:l2 + 1) . 'l\%<' . a:c2 . 'c'
endfunction

" Highlighting groups and their default light/dark styles. {{{1

Expand Down
2 changes: 1 addition & 1 deletion luainspect.vim
Expand Up @@ -2,7 +2,7 @@
" Author: Peter Odding <peter@peterodding.com>
" Last Change: August 15, 2010
" URL: http://peterodding.com/code/vim/lua-inspect/
" Version: 0.3.9
" Version: 0.3.10
" License: MIT

" Support for automatic update using the GLVS plug-in.
Expand Down
2 changes: 1 addition & 1 deletion luainspect4vim.lua
Expand Up @@ -49,7 +49,7 @@ function actions.highlight(tokenlist, line, column) -- {{{1
local function dump(token, hlgroup)
local l1, c1 = unpack(token.ast.lineinfo.first, 1, 2)
local l2, c2 = unpack(token.ast.lineinfo.last, 1, 2)
myprint(hlgroup .. ' ' .. l1 .. ' ' .. c1 .. ' ' .. c2)
myprint(('%s %i %i %i %i'):format(hlgroup, l1, c1, l2, c2))
end
local curvar = getcurvar(tokenlist, line, column)
for i, token in ipairs(tokenlist) do
Expand Down

0 comments on commit 17bb37c

Please sign in to comment.