Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions crates/project-model/src/project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ pub enum RunnableKind {
/// Template for checking a target, emitting rustc JSON diagnostics.
/// May include {label} which will get the label from the `build` section of a crate.
Flycheck,

/// For forwards-compatibility, i.e. old rust-analyzer binary with newer workspace discovery tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it's not that they're newer tools, it's that they're tool that can output additional types of runnable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is implied by this comment being attached to a serde(other) variant called "Unknown"

Unknown,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
Expand All @@ -380,6 +383,8 @@ pub struct ProjectJsonData {
crates: Vec<CrateData>,
#[serde(default)]
runnables: Vec<RunnableData>,
//
// New fields should be Option or #[serde(default)]. This applies to most of this datastructure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"most of this datastructure" is ambiguous: which parts of the datastructure? How about "everything should be optional except crates, so we can add support for new fields that old rust-project.json tools aren't generating yet".

}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Default)]
Expand Down Expand Up @@ -457,32 +462,37 @@ enum EditionData {
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct BuildData {
struct BuildData {
label: String,
build_file: Utf8PathBuf,
target_kind: TargetKindData,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RunnableData {
pub program: String,
pub args: Vec<String>,
pub cwd: Utf8PathBuf,
pub kind: RunnableKindData,
struct RunnableData {
program: String,
args: Vec<String>,
cwd: Utf8PathBuf,
kind: RunnableKindData,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum RunnableKindData {
enum RunnableKindData {
Flycheck,
Check,
Run,
TestOne,

/// For forwards-compatibility, i.e. old rust-analyzer binary with newer workspace discovery tools
#[allow(unused)]
#[serde(other)]
Unknown,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum TargetKindData {
enum TargetKindData {
Bin,
/// Any kind of Cargo lib crate-type (dylib, rlib, proc-macro, ...).
Lib,
Expand Down Expand Up @@ -546,6 +556,7 @@ impl From<RunnableKindData> for RunnableKind {
RunnableKindData::Run => RunnableKind::Run,
RunnableKindData::TestOne => RunnableKind::TestOne,
RunnableKindData::Flycheck => RunnableKind::Flycheck,
RunnableKindData::Unknown => RunnableKind::Unknown,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/project-model/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ fn rust_project_hello_world_project_model() {
);
}

#[test]
fn rust_project_labeled_project_model() {
// This just needs to parse.
_ = load_rust_project("labeled-project.json");
}

#[test]
fn rust_project_cfg_groups() {
let (crate_graph, _proc_macros) = load_rust_project("cfg-groups.json");
Expand Down
37 changes: 37 additions & 0 deletions crates/project-model/test_data/labeled-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"sysroot_src": null,
"crates": [
{
"display_name": "hello_world",
"root_module": "$ROOT$src/lib.rs",
"edition": "2018",
"deps": [],
"is_workspace_member": true,
"build": {
"label": "//:hello_world",
"build_file": "$ROOT$BUILD",
"target_kind": "bin"
}
}
],
"runnables": [
{
"kind": "run",
"program": "bazel",
"args": ["run", "{label}"],
"cwd": "$ROOT$"
},
{
"kind": "flycheck",
"program": "$ROOT$custom-flychecker.sh",
"args": ["{label}"],
"cwd": "$ROOT$"
},
{
"kind": "we-ignore-unknown-runnable-kinds-for-forwards-compatibility",
"program": "abc",
"args": ["{label}"],
"cwd": "$ROOT$"
}
]
}
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,8 @@ impl GlobalState {
} => self.diagnostics.clear_check_older_than_for_package(id, package_id, generation),
FlycheckMessage::Progress { id, progress } => {
let format_with_id = |user_facing_command: String| {
// When we're running multiple flychecks, we have to include a disambiguator in
// the title, or the editor complains. Note that this is a user-facing string.
if self.flycheck.len() == 1 {
user_facing_command
} else {
Expand Down