rust-dev-tools / cargo-src

Semantic code navigation for Rust
Apache License 2.0
417 stars 31 forks source link

cargo src

Build Status

A Rust source browser. Explore your Rust project with semantic understanding of the code. Features:

Uses knowledge from the RLS.

This is work-in-progress, pre-release software, expect bugs and plenty of rough edges.

Contents:

Screenshots

cargo src screenshot - source view

Hover to show the type of an identifier:

cargo src screenshot - source view

Search for an identifier name (shows definitions, and all references to each definition):

cargo src screenshot - source view

Find all uses of a definition:

cargo src screenshot - source view

Right click an identifier to show more options

cargo src screenshot - source view

Installing and running

Requires a nightly version of Rust.

To install, run cargo install cargo-src.

Then, to run: cargo src in a directory where you would usually run cargo build. You can run cargo src --open to open the output of cargo src directly in your web browser.

cargo src will start a web server and build (cargo check) and index your code. This may take some time (depending on your crate, up to twice as long as a normal build). You can browse the source in whilst indexing, but you'll be missing all the good stuff like jump-to-def and search.

Customisation

Create a rustw.toml file in your project's directory. See src/config.rs or run cargo src -- -h for the options available and their defaults.

Some features need configuration in the rustw.toml before they can be used.

edit_command = "subl $file:$line"

To be able to open files in your local editor. This example works for sublime text (subl). Use the $file and $line variables as appropriate for your editor.

vcs_link = "https://github.com/nrc/rustw-test/blob/master/$file#L$line"

For links to the code in version control, GitHub, in the example.

Building

Requires a nightly version of Rust.

Get the source code from https://github.com/nrc/cargo-src.

Running

Run CARGO=cargo /<your local filepath>/rustw/target/release/cargo-src in your project's directory (i.e., the directory you would normally use cargo build from).

Running cargo src will start a web server and display a URL in the console. To terminate the server, use ctrl + c. If you point your browser at the provided URL, it will list the directories and files from your project, which you can then use to view the code. The terminal is only used to display logging, it can be ignored.

You can use --open to open the cargo src browser directly in your web browser.

Currently, cargo src has only been tested on Firefox on Linux and MacOS (issue 48).

Troubleshooting

If you get an error like error while loading shared libraries while starting up cargo src you should try the following:

On Linux:

export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH

On MacOS:

export DYLD_LIBRARY_PATH=$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH

Contributing

Cargo src is open source (dual-licensed under the Apache 2.0 and MIT licenses) and contributions are welcome! You can help by testing and reporting issues. Code, tests, and documentation are very welcome, you can browse all issues or easy issues to find something to work on.

If you'd like help or want to talk about cargo, you can find me on the rust-dev-tools irc channel (nrc), email (my irc handle @mozilla.com), or twitter (@nick_r_cameron).

The cargo src server is written in Rust and uses Hyper. It runs cargo check as a separate process and only really deals with output on stdout/stderr.

The cargo src frontend is a single page web app written in HTML and Javascript. It uses React and JQuery.