Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use real buffer names instead of `noname.lua'
  • Loading branch information
xolox committed Aug 15, 2010
1 parent 2a33bcb commit 2e93bdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions autoload.vim
Expand Up @@ -36,6 +36,7 @@ endfunction

function! luainspect#make_request(action) " {{{1
let starttime = xolox#timer#start()
let bufname = fnamemodify(bufname(a:action != 'tooltip' ? '%' : v:beval_bufnr), ':p')
if a:action == 'tooltip'
let lines = getbufline(v:beval_bufnr, 1, "$")
call insert(lines, v:beval_col)
Expand All @@ -45,11 +46,12 @@ function! luainspect#make_request(action) " {{{1
call insert(lines, col('.'))
call insert(lines, line('.'))
endif
call insert(lines, bufname)
call insert(lines, a:action)
call s:parse_text(join(lines, "\n"), s:prepare_search_path())
if !empty(b:luainspect_output)
let response = b:luainspect_output[0]
let bufname = fnamemodify(bufname(a:action != 'tooltip' ? '%' : v:beval_bufnr), ':p:~')
let friendlyname = fnamemodify(bufname, ':~')
if response == 'syntax_error' && len(b:luainspect_output) >= 4
" Never perform syntax error highlighting in non-Lua buffers!
let linenum = b:luainspect_output[1] + 0
Expand All @@ -60,38 +62,38 @@ function! luainspect#make_request(action) " {{{1
let error_cmd = 'syntax match luaInspectSyntaxError /\%%>%il\%%<%il.*/ containedin=ALLBUT,lua*Comment*'
execute printf(error_cmd, linenum - 1, (linenum2 ? linenum2 : line('$')) + 1)
endif
call xolox#timer#stop("%s: Found a syntax error in %s in %s.", s:script, bufname, starttime)
call xolox#timer#stop("%s: Found a syntax error in %s in %s.", s:script, friendlyname, starttime)
" But always let the user know that a syntax error exists.
call xolox#warning("Syntax error around line %i in %s: %s", linenum, bufname, b:luainspect_syntax_error)
call xolox#warning("Syntax error around line %i in %s: %s", linenum, friendlyname, b:luainspect_syntax_error)
return
endif
unlet! b:luainspect_syntax_error
if response == 'highlight'
call s:define_default_styles()
call s:clear_previous_matches()
call s:highlight_variables()
call xolox#timer#stop("%s: Highlighted variables in %s in %s.", s:script, bufname, starttime)
call xolox#timer#stop("%s: Highlighted variables in %s in %s.", s:script, friendlyname, starttime)
elseif response == 'goto'
if len(b:luainspect_output) < 3
call xolox#warning("No variable under cursor!")
else
let linenum = b:luainspect_output[1] + 0
let colnum = b:luainspect_output[2] + 0
call setpos('.', [0, linenum, colnum, 0])
call xolox#timer#stop("%s: Jumped to definition in %s in %s.", s:script, bufname, starttime)
call xolox#timer#stop("%s: Jumped to definition in %s in %s.", s:script, friendlyname, starttime)
if &verbose == 0
" Clear previous "No variable under cursor!" message to avoid confusion.
call xolox#message("")
endif
endif
elseif response == 'tooltip'
if len(b:luainspect_output) > 1
call xolox#timer#stop("%s: Rendered tool tip for %s in %s.", s:script, bufname, starttime)
call xolox#timer#stop("%s: Rendered tool tip for %s in %s.", s:script, friendlyname, starttime)
return join(b:luainspect_output[1:-1], "\n")
endif
elseif response == 'rename'
if len(b:luainspect_output) > 1
call xolox#timer#stop("%s: Prepared for rename in %s in %s.", s:script, bufname, starttime)
call xolox#timer#stop("%s: Prepared for rename in %s in %s.", s:script, friendlyname, starttime)
call s:rename_variable()
else
call xolox#warning("No variable under cursor!")
Expand Down
6 changes: 3 additions & 3 deletions luainspect4vim.lua
Expand Up @@ -3,7 +3,7 @@
This module is part of the luainspect.vim plug-in for the Vim text editor.
Author: Peter Odding <peter@peterodding.com>
Last Change: August 12, 2010
Last Change: August 15, 2010
URL: http://peterodding.com/code/vim/lua-inspect/
License: MIT
Expand Down Expand Up @@ -253,7 +253,7 @@ end
-- }}}
return function(src)
local action, line, column, src = src:match '^(%S+)\n(%d+)\n(%d+)\n(.*)$'
local action, file, line, column, src = src:match '^(%S+)\n([^\n]+)\n(%d+)\n(%d+)\n(.*)$'
line = tonumber(line)
column = tonumber(column)
src = LA.remove_shebang(src)
Expand All @@ -269,7 +269,7 @@ return function(src)
return
end
-- Now parse the source code using metalua to build an abstract syntax tree.
local ast; ast, err, linenum, colnum, linenum2 = LA.ast_from_string(src, "noname.lua")
local ast = LA.ast_from_string(src, file)
if not ast then return end
-- Create a list of tokens from the AST and decorate it using luainspect.
local tokenlist = LA.ast_to_tokenlist(ast, src)
Expand Down

0 comments on commit 2e93bdd

Please sign in to comment.