Skip to content
Merged
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
7 changes: 5 additions & 2 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,11 @@ the folder inside them, so a chain takes one level whatever its length. The head
ignored. A selection or `top` on a
folder of a chain goes to the chain's row, and `selectionMoved` says so. A folder
not listed yet ends a chain, so hosts list the row's folder when its head opens.
Without `compact`, `folder` and `listed` are ignored and `heads` and `depths` are
absent.
A folder with `alone: true` keeps a row of its own: it shares its row with no
folder above or inside it, so hosts set it on folders whose row shows something
of their own, such as a module root or a marked source root, as IntelliJ IDEA
keeps them out of compact chains. Without `compact`, `folder`, `listed` and
`alone` are ignored and `heads` and `depths` are absent.

`workspace.repositories.repositories` is ordered with the containing workspace
repository first when present, then repositories under the opened workspace by
Expand Down
15 changes: 12 additions & 3 deletions rust/crates/project-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
//! whether the row is open, and `heads` says each row's head so the host can name the row
//! after the chain and keep every folder of the chain open or closed with it; `depths` says how
//! deep each row is indented, since a chain takes one level whatever its length. A folder that
//! is not listed yet ends a chain, since nothing says what is in it.
//! is not listed yet ends a chain, since nothing says what is in it, and a folder the host
//! says is `alone` (a module root, a marked source root) is never part of one, so what marks
//! it stays on a row of its own, as IntelliJ IDEA keeps them.

use std::collections::HashMap;

Expand Down Expand Up @@ -67,6 +69,11 @@ struct Node {
/// that is in it. Only `compact` reads it.
#[serde(default)]
listed: bool,
/// The node is a folder that keeps a row of its own, such as one the host shows as a
/// module root or marks as a source root: it shares its row with no folder above it or
/// inside it. Only `compact` reads it.
#[serde(default)]
alone: bool,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -236,7 +243,7 @@ pub fn command(payload: Value) -> Result<Value, CoreError> {
}

/// Which nodes share their row with the one folder inside them: a folder other than the root
/// that is listed and holds exactly one node, a folder.
/// that is listed and holds exactly one node, a folder, when neither keeps a row of its own.
fn joined_folders(nodes: &[Node], parent: &[Option<usize>]) -> Vec<bool> {
let mut inside = vec![0usize; nodes.len()];
for above in parent.iter().flatten() {
Expand All @@ -250,9 +257,11 @@ fn joined_folders(nodes: &[Node], parent: &[Option<usize>]) -> Vec<bool> {
joins[above] = above != 0
&& folder.folder
&& folder.listed
&& !folder.alone
&& inside[above] == 1
&& index == above + 1
&& nodes[index].folder;
&& nodes[index].folder
&& !nodes[index].alone;
}
}
joins
Expand Down
103 changes: 103 additions & 0 deletions rust/fixtures/workspace/project-tree-rows-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,109 @@
]
}
},
{
"name": "a folder that keeps a row of its own is in no chain",
"request": {
"nodes": [
{
"path": "",
"depth": 0,
"open": true,
"folder": true,
"listed": true
},
{
"path": "common",
"depth": 1,
"open": true,
"folder": true,
"listed": true,
"alone": true
},
{
"path": "common/src",
"depth": 2,
"open": true,
"folder": true,
"listed": true
},
{
"path": "common/src/main",
"depth": 3,
"open": true,
"folder": true,
"listed": true
},
{
"path": "common/src/main/java",
"depth": 4,
"open": true,
"folder": true,
"listed": true,
"alone": true
},
{
"path": "common/src/main/java/A.java",
"depth": 5
},
{
"path": "lib",
"depth": 1,
"open": true,
"folder": true,
"listed": true
},
{
"path": "lib/x",
"depth": 2,
"open": true,
"folder": true,
"listed": true
},
{
"path": "lib/x/y.txt",
"depth": 3
}
],
"compact": true
},
"response": {
"rows": [
0,
1,
3,
4,
5,
7,
8
],
"selection": {
"selected": null,
"marked": []
},
"selectionMoved": false,
"topRow": null,
"targets": [],
"heads": [
0,
1,
2,
4,
5,
6,
8
],
"depths": [
0,
1,
2,
3,
4,
1,
2
]
}
},
{
"name": "without compact a folder that holds one folder keeps its own row",
"request": {
Expand Down
Loading