Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure SublimeLinter-contrib-rustc to find the "piston" crate?

I'm building a Rust game with Piston and I'm trying to use the SublimeLinter Rust package. When I open my .rs game files, I get this linter error:

extern crate piston; // linter error: "can't find crate for 'piston'"

If I check the Sublime console, I can see that the linter is finding rustc:

SublimeLinter: rust activated: /usr/local/bin/rustc

I don't see any obvious error messages in the console. I have piston listed as a dependency in my Cargo.toml and I'm able to cargo run successfully.

I'm a complete Rust & SublimeLinter newbie.

I get a similar error for whichever import I put first; for example if I move extern crate graphics; to be the first line in the file I get the error "can't find crate for 'graphics'".

EDIT: turns out enabling the "use-cargo" setting fixed the issue. I added a ".sublimelinterrc" file to my project root with these contents:

{
  "linters": {
    "rust": {
      "use-crate-root": true,
      "use-cargo": true
    }
  }
}
like image 744
Daryl Avatar asked Jul 12 '15 23:07

Daryl


1 Answers

I have not been able to reproduce your error. However, I'll list what I did that seemed to work. Perhaps you will see a step where we diverged, and that will give you a hint of where to look.

I installed Sublime Text 3. I chose the stable channel, build 3083. I installed Package Control, and then three packages:

  1. SublimeLinter (3.5.1)
  2. Sublime​Linter-contrib-rustc (1.3.5)
  3. Rust (2015.05.28.16.43.21)

I restarted Sublime Text and opened a project of mine that uses Cargo and depends on other packages. I opened the console (ctrl-`) and enabled debug mode, which takes effect at the next Sublime restart.

Because I have non-standard install of Rust, I saw that Sublime was unable to run rustc due to missing dynamic libraries. I then closed Sublime, and opened it from my terminal: open /Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text. This uses my environment variables set by my shell.

I saw that the linter was complaining that my library had no main method, so I enabled the use-cargo option.

SublimeLinter: rust output:
error: main function not found
error: aborting due to previous error 

After changing the use-cargo setting, I caused a deliberate syntax error in my code and saw that it was highlighted. I then misnamed the crate in the extern crate line, and saw it was highlighted.

At no point did there seem to be a problem with finding crates. I could tell that cargo was being used via the console:

SublimeLinter: rust output:
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading rand v0.3.9
...
like image 153
Shepmaster Avatar answered Oct 21 '22 03:10

Shepmaster