Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 17bb37cefb7e562cacc0d076c6189aaf92026aca 1 parent 75359a0
Peter Odding authored August 15, 2010
30  autoload.vim
@@ -174,14 +174,18 @@ endfunction
174 174
 function! s:highlight_variables() " {{{1
175 175
   call clearmatches()
176 176
   for line in b:luainspect_output[1:-1]
177  
-    if s:check_output(line, '^\w\+\(\s\+\d\+\)\{3}$')
178  
-      let [group, linenum, firstcol, lastcol] = split(line)
179  
-      let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
  177
+    if s:check_output(line, '^\w\+\(\s\+\d\+\)\{4}$')
  178
+      let [group, l1, c1, l2, c2] = split(line)
  179
+      let l1 += 0
  180
+      let c1 -= 1
  181
+      let l2 += 0
  182
+      let c2 += 2
180 183
       if group == 'luaInspectWrongArgCount'
181  
-        call matchadd(group, pattern)
  184
+        call matchadd(group, s:highlight_position(l1, c1, l2, c2, 0))
182 185
       elseif group == 'luaInspectSelectedVariable' 
183  
-        call matchadd(group, pattern, 20)
  186
+        call matchadd(group, s:highlight_position(l1, c1, l2, c2, 1), 20)
184 187
       else
  188
+        let pattern = s:highlight_position(l1, c1, l2, c2, 1)
185 189
         execute 'syntax match' group '/' . pattern . '/'
186 190
       endif
187 191
     endif
@@ -193,8 +197,11 @@ function! s:rename_variable() " {{{1
193 197
   let highlights = []
194 198
   for line in b:luainspect_output[1:-1]
195 199
     if s:check_output(line, '^\d\+\(\s\+\d\+\)\{2}$')
196  
-      let [linenum, firstcol, lastcol] = split(line)
197  
-      let pattern = s:highlight_position(linenum + 0, firstcol - 1, lastcol + 2)
  200
+      let [l1, c1, c2] = split(line)
  201
+      let l1 += 0
  202
+      let c1 -= 1
  203
+      let c2 += 2
  204
+      let pattern = s:highlight_position(l1, c1, l1, c2, 1)
198 205
       call add(highlights, matchadd('IncSearch', pattern))
199 206
     endif
200 207
   endfor
@@ -233,9 +240,12 @@ function! s:check_output(line, pattern) " {{{1
233 240
   endif
234 241
 endfunction
235 242
 
236  
-function! s:highlight_position(linenum, firstcol, lastcol) " {{{1
237  
-  return printf('\%%%il\%%>%ic\<\w\+\>\%%<%ic', a:linenum, a:firstcol, a:lastcol)
238  
-endfunction
  243
+function! s:highlight_position(l1, c1, l2, c2, ident_only) " {{{1
  244
+  let l1 = a:l1 >= 1 ? (a:l1 - 1) : a:l1
  245
+  let p = '\%>' . l1 . 'l\%>' . a:c1 . 'c'
  246
+  let p .= a:ident_only ? '\<\w\+\>' : '\_.\+'
  247
+  return p . '\%<' . (a:l2 + 1) . 'l\%<' . a:c2 . 'c'
  248
+ endfunction
239 249
 
240 250
 " Highlighting groups and their default light/dark styles. {{{1
241 251
 
2  luainspect.vim
@@ -2,7 +2,7 @@
2 2
 " Author: Peter Odding <peter@peterodding.com>
3 3
 " Last Change: August 15, 2010
4 4
 " URL: http://peterodding.com/code/vim/lua-inspect/
5  
-" Version: 0.3.9
  5
+" Version: 0.3.10
6 6
 " License: MIT
7 7
 
8 8
 " Support for automatic update using the GLVS plug-in.
2  luainspect4vim.lua
@@ -49,7 +49,7 @@ function actions.highlight(tokenlist, line, column) -- {{{1
49 49
   local function dump(token, hlgroup)
50 50
     local l1, c1 = unpack(token.ast.lineinfo.first, 1, 2)
51 51
     local l2, c2 = unpack(token.ast.lineinfo.last, 1, 2)
52  
-    myprint(hlgroup .. ' ' .. l1 .. ' ' .. c1 .. ' ' .. c2)
  52
+    myprint(('%s %i %i %i %i'):format(hlgroup, l1, c1, l2, c2))
53 53
   end
54 54
   local curvar = getcurvar(tokenlist, line, column)
55 55
   for i, token in ipairs(tokenlist) do

0 notes on commit 17bb37c

Please sign in to comment.
Something went wrong with that request. Please try again.