Module Refactor

Refactoring module

Fields

refactor Global refactoring state

Class RefactorState

RefactorState:run_command (name, args) Run a builtin refactoring command
RefactorState:transform (callback) Run a custom refactoring transformation

Class MatchCtxt

MatchCtxt:parse_stmts (pat) Parse statements and add them to this MatchCtxt
MatchCtxt:parse_expr (pat) Parse an expression and add it to this MatchCtxt
MatchCtxt:fold_with (needle, callback) Find matches of pattern and rewrite using callback
MatchCtxt:get_expr (pattern) Get matched binding for an expression variable
MatchCtxt:get_stmt (pattern) Get matched binding for a statement variable
MatchCtxt:try_match (pat, target) Attempt to match target against pat, updating bindings if matched.
MatchCtxt:subst (replacement) Substitute the currently matched AST node with a new AST node

Class TransformCtxt

TransformCtxt:replace_stmts_with (needle, callback) Replace matching statements using given callback
TransformCtxt:replace_expr_with (needle, callback) Replace matching expressions using given callback
TransformCtxt:match (callback) Create a new, empty MatchCtxt
TransformCtxt:visit_crate (object) Visits an entire crate via a lua object's methods
TransformCtxt:visit_crate (object) Visits an entire crate via a lua object's methods
TransformCtxt:visit_fn_like (object) Visits every fn like via a lua object's methods
TransformCtxt:visit_paths (node, QSelf) Rewrite all paths in a crate
TransformCtxt:create_use (Array) Create a new use item

scripting.into_lua_ast Functions

Stmt AST Stmt
Expr AST Expr

Class ItemAstNode

ItemAstNode:visit_stmts (callback) Visit statements


Fields

refactor
Global refactoring state
  • refactor RefactorState object

Class RefactorState

Refactoring context
RefactorState:run_command (name, args)
Run a builtin refactoring command

Parameters:

RefactorState:transform (callback)
Run a custom refactoring transformation

Parameters:

  • callback function(TransformCtxt) Transformation function called with a fresh TransformCtxt. This TransformCtxt can operate on the crate to implement transformations.

Class MatchCtxt

A match context
MatchCtxt:parse_stmts (pat)
Parse statements and add them to this MatchCtxt

Parameters:

Returns:

    LuaAstNode The parsed statements
MatchCtxt:parse_expr (pat)
Parse an expression and add it to this MatchCtxt

Parameters:

Returns:

    LuaAstNode The parsed expression
MatchCtxt:fold_with (needle, callback)
Find matches of pattern and rewrite using callback

Parameters:

  • needle LuaAstNode Pattern to search for
  • callback function(LuaAstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match.
MatchCtxt:get_expr (pattern)
Get matched binding for an expression variable

Parameters:

  • pattern string Expression variable pattern

Returns:

    LuaAstNode Expression matched by this binding
MatchCtxt:get_stmt (pattern)
Get matched binding for a statement variable

Parameters:

  • pattern string Statement variable pattern

Returns:

    LuaAstNode Statement matched by this binding
MatchCtxt:try_match (pat, target)
Attempt to match target against pat, updating bindings if matched.

Parameters:

  • pat LuaAstNode AST (potentially with variable bindings) to match with
  • target LuaAstNode AST to match against

Returns:

    bool true if match was successful
MatchCtxt:subst (replacement)
Substitute the currently matched AST node with a new AST node

Parameters:

  • replacement LuaAstNode New AST node to replace the currently matched AST. May include variable bindings if these bindings were matched by the search pattern.

Returns:

    LuaAstNode New AST node with variable bindings replaced by their matched values

Class TransformCtxt

Transformation context
TransformCtxt:replace_stmts_with (needle, callback)
Replace matching statements using given callback

Parameters:

  • needle string Statements pattern to search for, may include variable bindings
  • callback function(LuaAstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match. See MatchCtxt:fold_with
TransformCtxt:replace_expr_with (needle, callback)
Replace matching expressions using given callback

Parameters:

  • needle string Expression pattern to search for, may include variable bindings
  • callback function(LuaAstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match. See MatchCtxt:fold_with
TransformCtxt:match (callback)
Create a new, empty MatchCtxt

Parameters:

  • callback function(MatchCtxt) Function called with the new match context
TransformCtxt:visit_crate (object)
Visits an entire crate via a lua object's methods

Parameters:

  • object Visitor Visitor whose methods will be called during the traversal
TransformCtxt:visit_crate (object)
Visits an entire crate via a lua object's methods

Parameters:

  • object Visitor Visitor whose methods will be called during the traversal
TransformCtxt:visit_fn_like (object)
Visits every fn like via a lua object's methods

Parameters:

  • object Visitor Visitor whose methods will be called during the traversal
TransformCtxt:visit_paths (node, QSelf)
Rewrite all paths in a crate

Parameters:

  • node LuaAstNode AST node to visit. Valid node types: {P}.
  • QSelf function(NodeId, , Path, Def) callback Function called for each path. Can modify QSelf and/or Path to rewrite the path.
TransformCtxt:create_use (Array)
Create a new use item

Parameters:

  • Array path of idents for use item

Returns:

    LuaAstNode New use item node

scripting.into_lua_ast Functions

Stmt
AST Stmt

Fields:

  • type "Stmt"
  • kind string StmtKind of this statement

    StmtKind::Local only:

  • ty LuaAstNode Type of local (optional)
  • init LuaAstNode Initializer of local (optional)
  • pat LuaAstNode Name of local

    StmtKind::Item only:

  • item LuaAstNode Item node

    StmtKind::Semi and StmtKind::Expr only:

  • expr LuaAstNode Expression in this statement
Expr
AST Expr

Fields:

  • type "Expr"
  • kind string ExprKind of this expression

    ExprKind::Lit only:

  • value Literal value of this expression

Class ItemAstNode

Item AST node handle

This object is NOT thread-safe. Do not use an object of this class from a thread that did not acquire it.

ItemAstNode:visit_stmts (callback)
Visit statements

Parameters:

  • callback function(LuaAstNode) Function to call when visiting each statement
generated by LDoc 1.4.6 Last updated 2019-06-24 11:50:01