Lua Inspect |
|
Inspect is a tool that does Lua code analysis. The result of this analysis can also be rendered as HTML. A plugin is also included for the SciTE text editor for real-time source code analysis, intelligent highlighting, and refactoring. The code is in working condition but still preliminary.
The tool operates by both static and dynamic analysis, using the AST converted via MetaLua (pure Lua portions).
lua luainspectlib/luainspect/command.lua examples.lua > test-output/examples.html
* analysis: * identifies global (red) and local variables (blue), including locals that are function arguments (dark blue) and upvalues (light blue) * identifies unused local variables: e.g. `do local x=1 end` (white-on-blue) * identifies local variables masking other locals (same name): e.g. `local x=1; local x=2` (strikethrough and squiggle line) * identifies local variables that have non-constant binding (`local x = 1; x = 2`) (italic) * identifies unknown global variables (white-on-red) and table fields (red), inferred by static and dynamic evaluation. * infers values of variables (e.g. `local sum = math.pi + 2` is 5.14. and defined-ness of members of imported modules (`local mt = require "math"; math.sqrtt(2) -- undefined`) * infers signatures of functions (including local, global, and module functions) * checks number of function arguments against signatures (SciTE only) * cross-references variables (locals and module fields) with their definitions and uses (pink highlight), identifies range of lines/scope where the local is defined (currently SciTE only), and supports jump-to-definition and jump-to-uses (SciTE only) * identifies all keywords in selected block (underline) * evaluate special comments (prefixed by '!') to inject semantic information into analysis (similar to luaanalyze / lint). * refactoring: * command to rename all occurrences of selected variable (SciTE only) * browsing: * inspect members of selected table. * select statement or comment containing current cursor selection (SciTE only) * display real-time annotations of all local variables, like an Excel/Mathcad worksheet (experimental feature via ANNOTATE_ALL_LOCALS) (currently SciTE only) * auto-complete typing support (SciTE only) (experimental) * interfaces: SciTE plugin, VIM plugin, and HTML output.
Features not implemented (but probably should be):
local x = "foo"; math.sqrt(x)
Doc comment consistency.
.rockspec
files in LuaRocks, README, COPYRIGHT, library naming conventions, etc.
math.sqrt(2)
, prior to typing the final (2)
to make it a valid statement, an error displays and syntax highlighting is lacking.
math.sqrt(2) --> local math_sqrt = math.sqrt ..... math_sqrt(2)
), and others
The latest version is available on [github].
Note: A patched version of SciteExtMan is bundled (the older 2006-11-10 version on SciteExtMan won't work fully).
Tested with SciTE version 2.12 (older versions might not work) and SciteExtMan (as of 2010-07-20). ctagsdx.lua from the full SciteExtMan is optional (allows "goto mark" command to return to previous location following a "go to definition").
This could be used on the lua-users wiki and on [snippets.luacode.org] to display Lua code.
Inspect to perform semantic highlighting for Lua in Vim
Inspect.
Inspect [screencast]
Brains IntelliJ IDEA [1]