From 0be2cb2c4db7f6f7635c99809c9c934c2101a0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Tue, 13 Aug 2024 13:10:06 +0200 Subject: [PATCH] Expand root outline view in outline view by default (#1048) Before this commit, the outline view is drawn with all elements collapsed by default. This often results in plenty of wasted space in the UI and low information density. Instead, as discussed in #693, it would be preferable to draw the outline view with its first level expanded by default (i.e., displaying the root node and its immediate children by default). Issue: #693 --- .../lsp4e/outline/LSSymbolsContentProvider.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java index 68a1ec119..4648166c6 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/LSSymbolsContentProvider.java @@ -333,16 +333,22 @@ protected void refreshTreeContentFromLS() { return; } + final int EXPAND_ROOT_LEVEL = 2; // Expansion level that displays root node and its children if (isQuickOutline) { viewer.refresh(); + viewer.expandToLevel(EXPAND_ROOT_LEVEL); } else { TreePath[] expandedElements = viewer.getExpandedTreePaths(); TreePath[] initialSelection = ((ITreeSelection) viewer.getSelection()).getPaths(); viewer.refresh(); - viewer.setExpandedTreePaths(Arrays.stream(expandedElements).map(symbolsModel::toUpdatedSymbol) + if (expandedElements.length > 0) { + viewer.setExpandedTreePaths(Arrays.stream(expandedElements).map(symbolsModel::toUpdatedSymbol) .filter(Objects::nonNull).toArray(TreePath[]::new)); - viewer.setSelection(new TreeSelection(Arrays.stream(initialSelection) - .map(symbolsModel::toUpdatedSymbol).filter(Objects::nonNull).toArray(TreePath[]::new))); + viewer.setSelection(new TreeSelection(Arrays.stream(initialSelection) + .map(symbolsModel::toUpdatedSymbol).filter(Objects::nonNull).toArray(TreePath[]::new))); + } else { + viewer.expandToLevel(EXPAND_ROOT_LEVEL); + } } if (linkWithEditor) {