#parser #tree-sitter

vim-plugin-metadata

Parse and analyze your vim plugins, from Rust!

3 releases (unstable)

1.0.0-rc.0 Sep 10, 2024
0.2.1 Sep 2, 2024
0.1.0 Aug 30, 2024

#2683 in Parser implementations

Download history 380/week @ 2024-08-29 108/week @ 2024-09-05 57/week @ 2024-09-12 30/week @ 2024-09-19 42/week @ 2024-09-26 15/week @ 2024-10-03

160 downloads per month

MIT license

53KB
1.5K SLoC

Rust vim-plugin-metadata

Parse and analyze your vim plugins, from Rust!

WARNING: This library is early alpha, still missing tons of functionality, and probably has serious bugs. Use at your own risk.

Usage

cargo add it to your project, point it at a file, get metadata:

use vim_plugin_metadata::VimParser;

fn main() {
    let mut parser = VimParser::new().unwrap();
    let plugin = parser.parse_plugin_dir(".vim/plugged/someplugin").unwrap();
    println!("{plugin:#?}");
}
VimPlugin {
    content: [
        VimModule {
            path: Some("plugin/somefile.vim"),
            doc: Some("File header comment"),
            nodes: [],
        },
        VimModule {
            path: Some("autoload/someplugin.vim"),
            doc: None,
            nodes: [
                Function {
                    name: "someplugin#DoThing",
                    args: [],
                    modifiers: [],
                    doc: "Does something cool.",
                },
            ],
        },
    ],
}
const VIMSCRIPT_CODE: &str = r#"
""
" File header comment

""
" Does something cool.
func MyFunc() abort
  …
endfunc
"#;

let module = parser.parse_module_str(VIMSCRIPT_CODE).unwrap();
println!("{module:#?}");
VimModule {
    path: None,
    doc: Some("File header comment"),
    nodes: [
        Function {
            name: "MyFunc",
            args: [],
            modifiers: [],
            doc: Some(
                "Does something cool.",
            ),
        },
    ]
}

See tests in src/lib.rs for more usage examples.

Dependencies

~9–17MB
~293K SLoC