Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It infers the wrong file path from json error msg #234

Closed
Boscop opened this issue Jan 10, 2018 · 5 comments
Closed

It infers the wrong file path from json error msg #234

Boscop opened this issue Jan 10, 2018 · 5 comments

Comments

@Boscop
Copy link

Boscop commented Jan 10, 2018

When I get an error like:

error: server\src\controllers\driver.rs:241: cannot find struct, variant or union type `Location` in this scope

When I click on it, it opens a non-existing file <project_root>\server\server\src\controllers\driver.rs
but it should instead open the right file at <project_root>\server\src\controllers\driver.rs.
(Btw, this project is in a workspace, of which server is one crate.)

@ehuss
Copy link

ehuss commented Jan 10, 2018

Hm, I can't seem to recreate this. Sorry, I may need a bunch of information from you to figure it out:

  • I assume you have the folders added as a Sublime project? Is it just the top-level Rust workspace folder, or do you have multiple ones?
  • Are you using one of the build variants, or just the regular Build command?
  • Are you building just one workspace member, or are you building them all at once?
  • Does it matter which file currently has focus? The build command uses the directory of the current file with focus, so that may change things.
  • Do you have any of the cargo_build settings set (like default_path)?
  • Which OS are you using?
  • Which version of Rust?

@Boscop
Copy link
Author

Boscop commented Jan 10, 2018

I did "Open Folder" on the workspace folder.
I'm using Ctrl-B (cargo build).
I'm just building the server workspace member.
It happens no matter which file of the server I'm in, when I press F4 (go to next error) or click on it, it will open the non-existing file.
Which cargo_build settings?
OS: Win 8.1
rustc 1.25.0-nightly (b5392f545 2018-01-08)

@ehuss
Copy link

ehuss commented Jan 10, 2018

OK, I have reproduced it. This seems to be a change on Rust nightly. I will need to investigate more to figure out a fix.

@Boscop
Copy link
Author

Boscop commented Jan 15, 2018

I'm curious, what was the actual change to the json msg format?
Btw, do you know where the json msg format is documented?
The reason I'm asking is because I'm writing a "proxy" for cargo/rustc (compiling another lang to Rust) and the proxy also maps error lines back to lines in the original source using source maps.
I got it working but I couldn't find any doc about the format, and no serde structs.
Are there any serde structs somewhere?
Btw, I ended up with these (sorry, it's in my pythonic Rust dialect):

#[allow(non_camel_case_types)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Level
	error
	warning
	note
	help

#[serde(tag = "reason")]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Msg
	#[serde(rename = "compiler-message")]
	CompilerMessage
		message: Message
		package_id: String
		target: Target
	#[serde(rename = "compiler-artifact")]
	CompilerArtifact
		features: Vec<::serde_json::Value>
		filenames: Vec<String>
		fresh: bool
		package_id: String
		profile: Profile
		target: Target
	#[serde(rename = "build-script-executed")]
	BuildScriptExecuted
		cfgs: Vec<::serde_json::Value>
		env: Vec<::serde_json::Value>
		linked_libs: Vec<String>
		linked_paths: Vec<::serde_json::Value>
		package_id: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Message
	pub children: Vec<Message>
	pub code: Option<Code>
	pub level: Level
	pub message: String
	pub rendered: ::serde_json::Value
	pub spans: Vec<Span>

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Code
	pub code: String
	pub explanation: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Span
	pub byte_end: usize
	pub byte_start: usize
	pub column_end: usize
	pub column_start: usize
	pub expansion: ::serde_json::Value
	pub file_name: String
	pub is_primary: bool
	pub label: ::serde_json::Value
	pub line_end: usize
	pub line_start: usize
	pub suggested_replacement: ::serde_json::Value
	pub text: Vec<Text>

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Text
	pub highlight_end: usize
	pub highlight_start: usize
	pub text: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Target
	pub crate_types: Vec<String>
	pub kind: Vec<String>
	pub name: String
	pub src_path: String

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Profile
	pub debug_assertions: bool
	pub debuginfo: i64
	pub opt_level: String
	pub overflow_checks: bool
	pub test: bool

@ehuss
Copy link

ehuss commented Jan 15, 2018

what was the actual change to the json msg format

rust-lang/cargo#4788 changed it so that all packages are compiled relative to the workspace root instead of the directory where cargo is run. This means that all paths and symbols are now relative to the workspace root. I have updated cargo metadata (rust-lang/cargo#4938) in order to determine where the workspace root is. I have a PR waiting to merge this into beta which should go through soon. Once that is done, I'll open a PR for Rust Enhanced to use this.

do you know where the json msg format is documented

AFAIK, it is not explicitly documented. I have just been reading the rust source code to figure things out. My notes on the format are here. The JSON structures are defined in libsyntax/json.rs, and there are some comments in there. The code that formats compiler messages into ASCII art is in librustc_errors/emitter.rs. There is not an exact 1:1 relationship between the internal Rust data structures and the JSON format, but it is usually close enough. Let me know if you have any specific questions, since I've had to look at this a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants