diff --git a/rust/contracts/rust-core-api.md b/rust/contracts/rust-core-api.md index 72528322..c8b5fc32 100644 --- a/rust/contracts/rust-core-api.md +++ b/rust/contracts/rust-core-api.md @@ -1062,8 +1062,8 @@ For `workspace.listDirectories`, `rust/fixtures/workspace/directory-listing-leav shows the difference between an unloaded child in its parent's listing and the empty `children` array returned when that same directory is listed directly. -`workspace.projectTree.rows` accepts `{ nodes, selection?, top? }` and returns -`{ rows, selection, selectionMoved, topRow, targets }`. `nodes` are the project tree +`workspace.projectTree.rows` accepts `{ nodes, selection?, top?, compact? }` and returns +`{ rows, selection, selectionMoved, topRow, targets, heads?, depths? }`. `nodes` are the project tree nodes the host loaded with `workspace.listDirectories`, in preorder, each `{ path, depth, open? }`: the first is the root `{ path: "", depth: 0 }`, and every other node is one name inside the nearest node above it at one less depth; `open` @@ -1083,6 +1083,21 @@ above it, a path listed twice, more than 2^20 nodes and the selection errors of `workspace.rowSelection.reduce` return `invalid_request`. See `rust/fixtures/workspace/project-tree-rows-v1.json`. +With `compact: true`, nodes may also say `folder: true` (the node is a folder) and +`listed: true` (the host listed its children), and a listed folder other than the +root whose only loaded child is a folder shares that folder's row, as IntelliJ IDEA +and VS Code compact folder chains. The chain's last folder is the row, and the +response adds `heads`, one per row: the position of the chain's first folder (the +row itself when it heads no chain), and `depths`, one per row: how deep the row is +indented, its node's `depth` less the folders above it that share their row with +the folder inside them, so a chain takes one level whatever its length. The head's +`open` decides whether the row is open; the `open` of the folders after it is +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. + `workspace.repositories.repositories` is ordered with the containing workspace repository first when present, then repositories under the opened workspace by workspace containment, depth, and path. Each entry contains an absolute native @@ -2092,7 +2107,7 @@ an unreferenced fragment. Requests over 100,000 commits, the largest Git Log a `rust/fixtures/git/graph-idea/` holds the pinned IntelliJ oracles. `git.changedFileGroups` groups the changed files of a commit, a stash or a shelf -by folder; it never starts Git. The request is `{ "paths": string[] }`, the +by folder; it never starts Git. The request is `{ "paths": string[], "nest"? }`, the repository-relative `/`-separated paths in the order Git listed them, at most 200,000. The response is `{ "folders": [{ "path", "files" }] }`: every path lands in the folder it names before its last `/` (`""` for the top of the repository), @@ -2102,6 +2117,15 @@ and file names compare by name, both in the project tree's natural order before the folders inside it and `v0.1.4.md` before `v0.1.12.md`; names the natural order cannot tell apart fall back to their raw text, then to request order. Hosts group once per loaded list and own expansion, rows and drawing. + +The optional `nest: { compact? }` asks for the folders as a tree: every folder +above a changed file is listed too, with empty `files`, in the same order, and +each folder adds `depth` (how many folder rows it is under, the top of the +repository and the folders right under it being 0) and `label` (what its row +shows, `""` for the top). With `compact: true`, a folder other than the top that +holds no file and exactly one folder is left out and its row goes to that folder, +whose `label` joins the chain's names with `/`, as IntelliJ IDEA and VS Code +compact folder chains. Without `nest`, `depth` and `label` are absent. `rust/fixtures/git/changed-file-groups-v1.json` defines the rules. `git.worktreeCreationPreview` derives what the worktree creation dialog shows; diff --git a/rust/crates/git/src/changed_file_groups.rs b/rust/crates/git/src/changed_file_groups.rs index 0c0818c3..2953bb73 100644 --- a/rust/crates/git/src/changed_file_groups.rs +++ b/rust/crates/git/src/changed_file_groups.rs @@ -7,9 +7,16 @@ //! project tree's natural order (`lithe_core_rules::file_names`), so `v0.1.4` comes before //! `v0.1.12` and a folder comes right before its subfolders. Which folders are open, the rows //! they make and how they draw stay in the views. +//! +//! With `nest`, the folders form the tree a folder view shows: every folder above a changed +//! file is listed, those without files of their own too, each with its depth under the top of +//! the repository and the label its row shows. With `nest.compact`, a folder other than the +//! top that holds no file and one folder shares its row with that folder, as IntelliJ IDEA and +//! VS Code compact such chains: the row is the last folder of the chain and its label the names +//! of the chain joined by `/`. use std::cmp::Ordering; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use lithe_core_rules::file_names::FileNameKey; use lithe_protocol::{CoreError, ErrorCode}; @@ -24,6 +31,18 @@ const MAX_PATHS: usize = 200_000; struct Request { /// Repository-relative paths with `/` separators, in the order Git listed them. paths: Vec, + /// Lists the folders as a tree with depths and labels; absent keeps the flat grouping. + #[serde(default)] + nest: Option, +} + +/// How the folders of a nested grouping are laid out. +#[derive(Debug, Default, Deserialize)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +struct Nest { + /// A folder that holds no file and one folder shares its row with that folder. + #[serde(default)] + compact: bool, } /// One folder and the files directly in it. @@ -34,6 +53,14 @@ struct Folder { path: String, /// Indices into the request's `paths` of the files in the folder, in name order. files: Vec, + /// With `nest`, how many rows of folders the folder's row is under: 0 for the top of the + /// repository and for the folders right under it. + #[serde(skip_serializing_if = "Option::is_none")] + depth: Option, + /// With `nest`, what the folder's row shows: its name, or the names of the compact chain + /// it ends joined by `/`; `""` for the top of the repository. + #[serde(skip_serializing_if = "Option::is_none")] + label: Option, } #[derive(Debug, Serialize)] @@ -95,14 +122,89 @@ pub fn command(payload: Value) -> Result { keyed.sort_by(|(left_key, left, _), (right_key, right, _)| { compare_segments(left_key, right_key).then_with(|| left.cmp(right)) }); - let folders = keyed - .into_iter() - .map(|(_, folder, files)| Folder { - path: folder.to_string(), - files, + let folders = match &request.nest { + None => keyed + .into_iter() + .map(|(_, folder, files)| Folder { + path: folder.to_string(), + files, + depth: None, + label: None, + }) + .collect(), + Some(nest) => nested(keyed, nest.compact), + }; + Ok(serde_json::to_value(Response { folders }).expect("changed file groups encode")) +} + +/// The folders of `keyed`, in its order, as a tree: the folders above them without files of +/// their own are added, each folder gets its depth and label, and with `compact` a folder that +/// holds no file and one folder gives its row to that folder. +fn nested(keyed: Vec<(Vec, &str, Vec)>, compact: bool) -> Vec { + let mut files: HashMap<&str, Vec> = HashMap::new(); + let mut all: Vec<(Vec, &str)> = Vec::new(); + for (key, folder, indices) in keyed { + let mut above = folder; + while !above.is_empty() { + above = folder_of(above); + if above.is_empty() || files.contains_key(above) { + break; + } + files.insert(above, Vec::new()); + let segments = above.split('/').map(FileNameKey::new).collect(); + all.push((segments, above)); + } + files.insert(folder, indices); + all.push((key, folder)); + } + all.sort_by(|(left_key, left), (right_key, right)| { + compare_segments(left_key, right_key).then_with(|| left.cmp(right)) + }); + let mut inside: HashMap<&str, usize> = HashMap::new(); + for (_, folder) in &all { + if !folder.is_empty() { + *inside.entry(folder_of(folder)).or_default() += 1; + } + } + let joined: HashSet<&str> = all + .iter() + .map(|(_, folder)| *folder) + .filter(|folder| { + compact + && !folder.is_empty() + && files[folder].is_empty() + && inside.get(folder).copied() == Some(1) }) .collect(); - Ok(serde_json::to_value(Response { folders }).expect("changed file groups encode")) + let joins = |folder: &str| joined.contains(folder); + // The depth and label of each folder's row; a folder that joins the one inside it hands its + // label on to that folder. + let mut rows: HashMap<&str, (usize, String)> = HashMap::new(); + let mut out = Vec::new(); + for (_, folder) in all { + let (depth, label) = if folder.is_empty() { + (0, String::new()) + } else { + let above = folder_of(folder); + let name = name_of(folder); + match rows.get(above) { + Some((depth, label)) if joins(above) => (*depth, format!("{label}/{name}")), + Some((depth, _)) if !above.is_empty() => (depth + 1, name.to_string()), + _ => (0, name.to_string()), + } + }; + rows.insert(folder, (depth, label.clone())); + if joins(folder) { + continue; + } + out.push(Folder { + path: folder.to_string(), + files: files.remove(folder).unwrap_or_default(), + depth: Some(depth), + label: Some(label), + }); + } + out } /// The folder `path` names before its last `/`, or `""` for a file at the top. diff --git a/rust/crates/project-tree/src/lib.rs b/rust/crates/project-tree/src/lib.rs index ce339616..73dc6bd7 100644 --- a/rust/crates/project-tree/src/lib.rs +++ b/rust/crates/project-tree/src/lib.rs @@ -15,6 +15,15 @@ //! that shows, so the selection is always on a row the user sees. Marks and an anchor whose //! node went away are dropped; marks inside a closed folder stay. The selection itself follows //! `lithe-row-selection`. Fixtures live in `rust/fixtures/workspace/project-tree-rows-v1.json`. +//! +//! With `compact`, a folder other than the root that is listed and holds nothing but one folder +//! shares its row with that folder, as IntelliJ IDEA's compact middle packages and VS Code's +//! compact folders show them: the chain from its first folder (the head) down to the first +//! folder that holds anything else is one row, the last node of the chain. The head decides +//! 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. use std::collections::HashMap; @@ -36,6 +45,9 @@ struct Request { /// The path of the row at the top of the view, which should stay there. #[serde(default)] top: Option, + /// Folders that hold nothing but one folder share a row with it. + #[serde(default)] + compact: bool, } #[derive(Debug, Deserialize)] @@ -48,6 +60,13 @@ struct Node { /// The node is a folder the user opened. #[serde(default)] open: bool, + /// The node is a folder. Only `compact` reads it. + #[serde(default)] + folder: bool, + /// The node is a folder the host listed, so the nodes after it at one more depth are all + /// that is in it. Only `compact` reads it. + #[serde(default)] + listed: bool, } #[derive(Debug, Serialize)] @@ -63,6 +82,16 @@ struct Response { top_row: Option, /// What a batch acts on, as `lithe-row-selection` says. targets: Vec, + /// With `compact`, the position in `nodes` of the first folder of each row's chain, one + /// per row; the row itself when it shares its row with no folder above it. Empty without + /// `compact`. + #[serde(skip_serializing_if = "Vec::is_empty")] + heads: Vec, + /// With `compact`, how deep each row is indented, one per row: the depth of its node less + /// the folders above it that share their row with the folder inside them. Empty without + /// `compact`. + #[serde(skip_serializing_if = "Vec::is_empty")] + depths: Vec, } /// Handles `workspace.projectTree.rows`. @@ -81,50 +110,96 @@ pub fn command(payload: Value) -> Result { _ => return Err(invalid("The first project tree node must be the root")), } let mut position = HashMap::with_capacity(nodes.len()); - let mut shown = vec![false; nodes.len()]; - let mut rows = Vec::new(); - // `folders[d]` is the node at depth `d` above the current one, and `closed` the depth of - // the shallowest folder above it that is closed. + // `parent[i]` is the folder node `i` is in; the root has none. + let mut parent: Vec> = vec![None; nodes.len()]; + // `folders[d]` is the node at depth `d` above the current one. let mut folders: Vec = Vec::new(); - let mut closed: Option = None; for (index, node) in nodes.iter().enumerate() { if index > 0 { if node.depth == 0 || node.depth > folders.len() { return Err(invalid("A project tree node skips a depth")); } folders.truncate(node.depth); - let parent = &nodes[folders[node.depth - 1]].path; - if !is_child(parent, &node.path) { + let above = folders[node.depth - 1]; + if !is_child(&nodes[above].path, &node.path) { return Err(invalid("A project tree node is not in the folder above it")); } + parent[index] = Some(above); } if position.insert(node.path.as_str(), index).is_some() { return Err(invalid("A project tree path is listed twice")); } + folders.push(index); + } + let joins = if request.compact { + joined_folders(nodes, &parent) + } else { + vec![false; nodes.len()] + }; + + // `row_of[i]` is the row node `i` shows on: itself, or the last node of its chain. + let mut row_of: Vec> = vec![None; nodes.len()]; + let mut rows = Vec::new(); + let mut heads = Vec::new(); + let mut depths = Vec::new(); + // `head[i]` is the first folder of the chain node `i` is in. + let mut head: Vec = (0..nodes.len()).collect(); + // `level[i]` is how deep the row of node `i` is indented: a folder that shares its row with + // the one inside it adds no level. + let mut level = vec![0usize; nodes.len()]; + // `closed` is the depth of the shallowest row above the current node that is closed. + let mut closed: Option = None; + // `chain` is the nodes of the chain being walked, which take the row its last node makes. + let mut chain: Vec = Vec::new(); + for (index, node) in nodes.iter().enumerate() { if closed.is_some_and(|depth| node.depth <= depth) { closed = None; } - if closed.is_none() { - shown[index] = true; - rows.push(index); - if !node.open { - closed = Some(node.depth); + if closed.is_some() { + continue; + } + if let Some(above) = parent[index] { + level[index] = level[above] + usize::from(!joins[above]); + if joins[above] { + head[index] = head[above]; } } - folders.push(index); + chain.push(index); + if joins[index] { + // The one folder inside comes next in preorder and carries the row on. + continue; + } + for &member in &chain { + row_of[member] = Some(index); + } + chain.clear(); + rows.push(index); + if request.compact { + heads.push(head[index]); + depths.push(level[index]); + } + if !nodes[head[index]].open { + closed = Some(node.depth); + } } let loaded = |path: &str| position.contains_key(path); - let shows = |path: &str| position.get(path).is_some_and(|&index| shown[index]); + // The path of the row the node at `path` shows on, when it shows. + let row_path = |path: &str| { + position + .get(path) + .and_then(|&index| row_of[index]) + .map(|row| nodes[row].path.as_str()) + }; let mut selection = request.selection; let before = selection.selected.clone(); if let Some(path) = &selection.selected { - if !shows(path) { - // The root always shows, so there is always one. - let nearest = ancestors(path) - .find(|above| shows(above)) - .unwrap_or_default(); - selection.selected = Some(nearest.to_string()); + // The root always shows, so there is always one. + let row = row_path(path) + .or_else(|| ancestors(path).find_map(&row_path)) + .unwrap_or_default(); + if row != path { + selection.selected = Some(row.to_string()); } } selection.marked.retain(|path| loaded(path)); @@ -135,16 +210,17 @@ pub fn command(payload: Value) -> Result { { selection.anchor = None; } - let row_of: HashMap = rows + let line_of: HashMap = rows .iter() .enumerate() - .map(|(row, &node)| (node, row)) + .map(|(line, &node)| (node, line)) .collect(); let top_row = request .top .as_deref() .and_then(|path| position.get(path)) - .and_then(|node| row_of.get(node).copied()); + .and_then(|&node| row_of[node]) + .and_then(|row| line_of.get(&row).copied()); let targets = targets(&selection); let selection_moved = selection.selected != before; Ok(serde_json::to_value(Response { @@ -153,10 +229,35 @@ pub fn command(payload: Value) -> Result { selection_moved, top_row, targets, + heads, + depths, }) .expect("project tree response encodes")) } +/// 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. +fn joined_folders(nodes: &[Node], parent: &[Option]) -> Vec { + let mut inside = vec![0usize; nodes.len()]; + for above in parent.iter().flatten() { + inside[*above] += 1; + } + let mut joins = vec![false; nodes.len()]; + for (index, above) in parent.iter().enumerate() { + if let Some(above) = *above { + let folder = &nodes[above]; + // In preorder the only node in a folder comes right after it. + joins[above] = above != 0 + && folder.folder + && folder.listed + && inside[above] == 1 + && index == above + 1 + && nodes[index].folder; + } + } + joins +} + /// Whether `path` names an entry directly inside the folder at `parent`. fn is_child(parent: &str, path: &str) -> bool { let name = if parent.is_empty() { diff --git a/rust/crates/project/src/name_ranking.rs b/rust/crates/project/src/name_ranking.rs index ca11e93e..08aefe3c 100644 --- a/rust/crates/project/src/name_ranking.rs +++ b/rust/crates/project/src/name_ranking.rs @@ -269,9 +269,7 @@ fn match_container(qualifier: &str, container: &str, path: Option<&str>) -> Opti let tail_hit = match_name(tail, container)?; if let Some(path) = path { let normalized_prefix = prefix.replace("::", "/").replace('.', "/"); - if match_name(&normalized_prefix, path).is_none() { - return None; - } + match_name(&normalized_prefix, path)?; } Some((tail_hit.degree / (PATH_DEGREE_DIVISOR * 2)).max(1)) } diff --git a/rust/fixtures/git/changed-file-groups-v1.json b/rust/fixtures/git/changed-file-groups-v1.json index bb72a328..b2a95a87 100644 --- a/rust/fixtures/git/changed-file-groups-v1.json +++ b/rust/fixtures/git/changed-file-groups-v1.json @@ -1,6 +1,6 @@ { "version": 1, - "description": "git.changedFileGroups groups repository-relative paths by the folder before their last '/', \"\" being the top of the repository; files are indices into paths. Folder paths compare segment by segment and file names by name, both in the project tree's natural order (workspace/file-name-order-v1.json); raw text, then request order, breaks the remaining ties. Views own expansion, rows and drawing.", + "description": "git.changedFileGroups groups repository-relative paths by the folder before their last '/', \"\" being the top of the repository; files are indices into paths. Folder paths compare segment by segment and file names by name, both in the project tree's natural order (workspace/file-name-order-v1.json); raw text, then request order, breaks the remaining ties. Views own expansion, rows and drawing. With nest, every folder above a file is listed too, in the same order, with the depth of its row and its label; with nest.compact a folder other than the top that holds no file and exactly one folder shares the row of that folder, whose label joins the chain's names with '/'.", "cases": [ { "name": "rootFilesAndNestedFolders", @@ -250,6 +250,158 @@ "paths": [] }, "folders": [] + }, + { + "name": "nestedListsFoldersWithoutFilesWithDepthAndLabel", + "request": { + "paths": [ + "src/main/java/com/A.java", + "src/main/java/com/B.java", + "src/test/T.java", + "README.md", + "docs/x.md" + ], + "nest": {} + }, + "folders": [ + { + "path": "", + "files": [ + 3 + ], + "depth": 0, + "label": "" + }, + { + "path": "docs", + "files": [ + 4 + ], + "depth": 0, + "label": "docs" + }, + { + "path": "src", + "files": [], + "depth": 0, + "label": "src" + }, + { + "path": "src/main", + "files": [], + "depth": 1, + "label": "main" + }, + { + "path": "src/main/java", + "files": [], + "depth": 2, + "label": "java" + }, + { + "path": "src/main/java/com", + "files": [ + 0, + 1 + ], + "depth": 3, + "label": "com" + }, + { + "path": "src/test", + "files": [ + 2 + ], + "depth": 1, + "label": "test" + } + ] + }, + { + "name": "nestedCompactJoinsFoldersThatHoldOneFolderAndNoFile", + "request": { + "paths": [ + "src/main/java/com/A.java", + "src/main/java/com/B.java", + "src/test/T.java", + "README.md", + "docs/x.md" + ], + "nest": { + "compact": true + } + }, + "folders": [ + { + "path": "", + "files": [ + 3 + ], + "depth": 0, + "label": "" + }, + { + "path": "docs", + "files": [ + 4 + ], + "depth": 0, + "label": "docs" + }, + { + "path": "src", + "files": [], + "depth": 0, + "label": "src" + }, + { + "path": "src/main/java/com", + "files": [ + 0, + 1 + ], + "depth": 1, + "label": "main/java/com" + }, + { + "path": "src/test", + "files": [ + 2 + ], + "depth": 1, + "label": "test" + } + ] + }, + { + "name": "nestedCompactChainFromTheTop", + "request": { + "paths": [ + "a/b/c/x", + "a/b/c/d/y" + ], + "nest": { + "compact": true + } + }, + "folders": [ + { + "path": "a/b/c", + "files": [ + 0 + ], + "depth": 0, + "label": "a/b/c" + }, + { + "path": "a/b/c/d", + "files": [ + 1 + ], + "depth": 1, + "label": "d" + } + ] } ] } diff --git a/rust/fixtures/workspace/project-tree-rows-v1.json b/rust/fixtures/workspace/project-tree-rows-v1.json index f54c3fdd..5b364d91 100644 --- a/rust/fixtures/workspace/project-tree-rows-v1.json +++ b/rust/fixtures/workspace/project-tree-rows-v1.json @@ -1,5 +1,5 @@ { - "description": "workspace.projectTree.rows: the rows of the project tree from the nodes the host loaded, in preorder with their depth and whether each folder is open, and the selection kept on a row that shows. rows are positions in nodes; topRow is the row of the node named by top while it shows. Hosts list folders, keep focus, scrolling and painting, and ask once per change of shape, never per paint.", + "description": "workspace.projectTree.rows: the rows of the project tree from the nodes the host loaded, in preorder with their depth and whether each folder is open, and the selection kept on a row that shows. rows are positions in nodes; topRow is the row of the node named by top while it shows. Hosts list folders, keep focus, scrolling and painting, and ask once per change of shape, never per paint. With compact, a listed folder other than the root that holds nothing but one folder shares the row of that folder; heads gives each row's first folder, which decides whether the row is open, depths how deep each row is indented, and a selection or top on a folder of a chain goes to the chain's row.", "cases": [ { "name": "a row shows when every folder above it is open", @@ -384,6 +384,418 @@ "topRow": null, "targets": [] } + }, + { + "name": "compact folders share a row down to the first folder that holds anything else, and a selection or top on a folder of the chain goes to its row", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src", + "depth": 1, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main", + "depth": 2, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java", + "depth": 3, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java/A.java", + "depth": 4 + }, + { + "path": "src/main/java/B.java", + "depth": 4 + }, + { + "path": "README.md", + "depth": 1 + } + ], + "selection": { + "selected": "src/main" + }, + "top": "src", + "compact": true + }, + "response": { + "rows": [ + 0, + 3, + 4, + 5, + 6 + ], + "selection": { + "selected": "src/main/java", + "marked": [] + }, + "selectionMoved": true, + "topRow": 1, + "targets": [], + "heads": [ + 0, + 1, + 4, + 5, + 6 + ], + "depths": [ + 0, + 1, + 2, + 2, + 1 + ] + } + }, + { + "name": "the head of a compact chain closes its row whatever the folders inside say", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src", + "depth": 1, + "open": false, + "folder": true, + "listed": true + }, + { + "path": "src/main", + "depth": 2, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java", + "depth": 3, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java/A.java", + "depth": 4 + }, + { + "path": "src/main/java/B.java", + "depth": 4 + }, + { + "path": "README.md", + "depth": 1 + } + ], + "selection": { + "selected": "src/main/java/A.java" + }, + "compact": true + }, + "response": { + "rows": [ + 0, + 3, + 6 + ], + "selection": { + "selected": "src/main/java", + "marked": [] + }, + "selectionMoved": true, + "topRow": null, + "targets": [], + "heads": [ + 0, + 1, + 6 + ], + "depths": [ + 0, + 1, + 1 + ] + } + }, + { + "name": "a folder not listed yet ends a compact chain", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a", + "depth": 1, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a/b", + "depth": 2, + "folder": true + } + ], + "compact": true + }, + "response": { + "rows": [ + 0, + 2 + ], + "selection": { + "selected": null, + "marked": [] + }, + "selectionMoved": false, + "topRow": null, + "targets": [], + "heads": [ + 0, + 1 + ], + "depths": [ + 0, + 1 + ] + } + }, + { + "name": "a chain in the row of another chain is indented one level more, whatever the length of either", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a", + "depth": 1, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a/b", + "depth": 2, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a/b/c", + "depth": 3, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a/b/c/d", + "depth": 4, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "a/b/c/d/y.txt", + "depth": 5 + }, + { + "path": "a/b/x.txt", + "depth": 3 + } + ], + "compact": true + }, + "response": { + "rows": [ + 0, + 2, + 4, + 5, + 6 + ], + "selection": { + "selected": null, + "marked": [] + }, + "selectionMoved": false, + "topRow": null, + "targets": [], + "heads": [ + 0, + 1, + 3, + 5, + 6 + ], + "depths": [ + 0, + 1, + 2, + 3, + 2 + ] + } + }, + { + "name": "the root and a folder that holds a file never share a row", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "only", + "depth": 1, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "only/x.txt", + "depth": 2 + }, + { + "path": "only/y", + "depth": 2, + "folder": true + } + ], + "compact": true + }, + "response": { + "rows": [ + 0, + 1, + 2, + 3 + ], + "selection": { + "selected": null, + "marked": [] + }, + "selectionMoved": false, + "topRow": null, + "targets": [], + "heads": [ + 0, + 1, + 2, + 3 + ], + "depths": [ + 0, + 1, + 2, + 2 + ] + } + }, + { + "name": "without compact a folder that holds one folder keeps its own row", + "request": { + "nodes": [ + { + "path": "", + "depth": 0, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src", + "depth": 1, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main", + "depth": 2, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java", + "depth": 3, + "open": true, + "folder": true, + "listed": true + }, + { + "path": "src/main/java/A.java", + "depth": 4 + }, + { + "path": "src/main/java/B.java", + "depth": 4 + }, + { + "path": "README.md", + "depth": 1 + } + ], + "selection": { + "selected": "src/main" + } + }, + "response": { + "rows": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "selection": { + "selected": "src/main", + "marked": [] + }, + "selectionMoved": false, + "topRow": null, + "targets": [] + } } ], "invalid": [