diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index c8b5fc32..0b9f6921 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -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 diff --git a/rust/crates/project-tree/src/lib.rs b/rust/crates/project-tree/src/lib.rs index 73dc6bd7..08fca353 100644 --- a/rust/crates/project-tree/src/lib.rs +++ b/rust/crates/project-tree/src/lib.rs @@ -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; @@ -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)] @@ -236,7 +243,7 @@ pub fn command(payload: Value) -> Result { } /// 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]) -> Vec { let mut inside = vec![0usize; nodes.len()]; for above in parent.iter().flatten() { @@ -250,9 +257,11 @@ fn joined_folders(nodes: &[Node], parent: &[Option]) -> Vec { 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 diff --git a/rust/fixtures/workspace/project-tree-rows-v1.json b/rust/fixtures/workspace/project-tree-rows-v1.json index 5b364d91..f5c5a64c 100644 --- a/rust/fixtures/workspace/project-tree-rows-v1.json +++ b/rust/fixtures/workspace/project-tree-rows-v1.json @@ -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": {