| Crates.io | salt_ide |
| lib.rs | salt_ide |
| version | 0.1.1 |
| created_at | 2025-01-27 16:52:04.546293+00 |
| updated_at | 2025-04-10 02:43:16.94831+00 |
| description | Compiler plugin for the SALT VS Code extension |
| homepage | |
| repository | https://github.com/mojeanmac/vscode-salt/tree/master/crates/salt_ide |
| max_upload_size | |
| id | 1532595 |
| size | 62,482 |
This crate currently provides data for a study of functional and imperial styles in Rust. It is intended to be used internally for the SALT extension for VS Code.
This crate also utilizes rustc_plugin for code analysis. The execution in print_result is forked from the print-all-items example plugin in the rustc_plugin repo.
Upon calling this crate on a Rust project, an HirVisitor produces the following output.
struct VisitorJson {
fns: HashMap<String, BlockJson>,
loops: Vec<BlockJson>,
matches: Vec<BlockJson>,
let_exprs: Vec<BlockJson>,
iter_mthds: Vec<BlockJson>,
calls: HashMap<String, HashMap<String, u32>>,
unsafe_blocks: Vec<BlockJson>,
}
The BlockJson enum serializes data represented gathered by HirVisitor to be printed. Most variants contain the following fields:
def_id is a hashed DefId of the item/function the block belongs to using DefaultHasher.depth is the number of nested blocks the expression is in (eg. Function level is depth=1).lines is simply the line count of the block.See visit_hir.rs for the implementation.
From the input parameters and return values, we observe the TyKind variants (eg. Int, Adt, Ref), mutability, and any trait implementations that indicate an anonymous closures (Fn, FnOnce, and FnMut).
Usage of closures in the function interface is a functional paradigm, while mut inputs and outputs are more imperative in style.
Loops are an imperative style.
Iterator methods are functional in style as they replace the need for loops.
Pattern matching is a functional paradigm.
Semantically equivalent to a one-armed match-- specifically, the if let ... = x expression, not to be confused with LetStmt (eg. let x = ... )
An unsafe block. Functions do not need to be unsafe in their function signature to contain these.
A collection of DefIds each representing a crate-local function call mapped to a collection of callers location DefIds and the count for how many times it was called.
Run the example crate like this:
# assuming working directory is <repo_root>/crates/salt
# install the print-all-items binaries
cargo install --path .
# run the binaries on an example crate
cd example-crate
cargo salt
You should see the output:
{"crate_id":"11573503235230656294","visit_res":{"calls":{},"fns":{"18270091135093349626":{"Def":{"lines":4,"params":{"closure_traits":[],"ty_kinds":[[true,"Uint"],[false,"Uint"]]},"recursive":false,"ret":{"closure_trait":null,"mutabl":false,"ty_kind":"Uint"},"unsafety":false}}},"iter_mthds":[],"let_exprs":[],"loops":[],"matches":[],"unsafe_blocks":[]}}