Skip to content

Commit 412b3e3

Browse files
committed
feat: add Fold All/Unfold All commands to Generic Editor
Add handlers FoldAllHandler and UnfoldAllHandler calling ProjectionViewer collapseAll / expandAll. Contribute actions to the editor popup Source menu. Add default keybindings: CTRL+SHIFT+NUMPAD_DIVIDE (Fold All), CTRL+SHIFT+NUMPAD_MULTIPLY (Unfold All).
1 parent f1379c8 commit 412b3e3

6 files changed

Lines changed: 167 additions & 4 deletions

File tree

org.eclipse.lsp4e/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Language Server Protocol client for Eclipse IDE (Incubation)
44
Bundle-SymbolicName: org.eclipse.lsp4e;singleton:=true
5-
Bundle-Version: 0.18.30.qualifier
5+
Bundle-Version: 0.18.31.qualifier
66
Bundle-RequiredExecutionEnvironment: JavaSE-17
77
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
88
org.eclipse.equinox.common;bundle-version="3.8.0",

org.eclipse.lsp4e/plugin.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@ command.open.quick.type.hierarchy.description = Open Quick Call Hierarchy for th
4747
view.callHierarchy.name = Call Hierarchy
4848
view.typeHierarchy.name = Type Hierarchy
4949
view.languageServers.name = Language Servers
50-
viewsCategory.name = Language Servers
50+
viewsCategory.name = Language Servers
51+
52+
# Folding commands
53+
command.folding.foldAll.name = Fold All
54+
command.folding.unfoldAll.name = Unfold All
55+
menu.folding.name = Folding

org.eclipse.lsp4e/plugin.xml

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,106 @@
154154
</foldingReconcilingStrategy>
155155
</extension>
156156

157+
<!-- folding: define commands -->
158+
<extension point="org.eclipse.ui.commands">
159+
<command
160+
categoryId="org.eclipse.lsp4e.category"
161+
id="org.eclipse.lsp4e.folding.collapseAll"
162+
name="%command.folding.foldAll.name" />
163+
<command
164+
categoryId="org.eclipse.lsp4e.category"
165+
id="org.eclipse.lsp4e.folding.expandAll"
166+
name="%command.folding.unfoldAll.name" />
167+
</extension>
168+
169+
<!-- folding: register command handlers -->
170+
<extension point="org.eclipse.ui.handlers">
171+
<handler
172+
class="org.eclipse.lsp4e.operations.folding.FoldAllHandler"
173+
commandId="org.eclipse.lsp4e.folding.collapseAll">
174+
<activeWhen>
175+
<or>
176+
<reference definitionId="org.eclipse.lsp4e.textSelectionHasLanguageServer" />
177+
<reference definitionId="org.eclipse.lsp4e.editorHasLanguageServer" />
178+
</or>
179+
</activeWhen>
180+
</handler>
181+
<handler
182+
class="org.eclipse.lsp4e.operations.folding.UnfoldAllHandler"
183+
commandId="org.eclipse.lsp4e.folding.expandAll">
184+
<activeWhen>
185+
<or>
186+
<reference definitionId="org.eclipse.lsp4e.textSelectionHasLanguageServer" />
187+
<reference definitionId="org.eclipse.lsp4e.editorHasLanguageServer" />
188+
</or>
189+
</activeWhen>
190+
</handler>
191+
</extension>
192+
193+
<!-- folding: register menu entries -->
194+
<extension point="org.eclipse.ui.menus">
195+
<menuContribution
196+
allPopups="true"
197+
locationURI="popup:org.eclipse.ui.genericeditor.source.menu?after=additions">
198+
<separator name="org.eclipse.lsp4e.folding.group.start" visible="true"/>
199+
<command commandId="org.eclipse.lsp4e.folding.collapseAll" label="%command.folding.foldAll.name">
200+
<visibleWhen>
201+
<reference definitionId="org.eclipse.lsp4e.textSelectionHasLanguageServer" />
202+
</visibleWhen>
203+
</command>
204+
<command commandId="org.eclipse.lsp4e.folding.expandAll" label="%command.folding.unfoldAll.name">
205+
<visibleWhen>
206+
<reference definitionId="org.eclipse.lsp4e.textSelectionHasLanguageServer" />
207+
</visibleWhen>
208+
</command>
209+
<separator name="org.eclipse.lsp4e.folding.group.end" visible="true"/>
210+
</menuContribution>
211+
</extension>
212+
213+
<!-- folding: add commands to main Window > Source menu contributed by TM4E -->
214+
<extension point="org.eclipse.ui.menus">
215+
<menuContribution locationURI="menu:org.eclipse.tm4e.source.menu?after=additions">
216+
<separator name="org.eclipse.lsp4e.folding.main.group.start" visible="true"/>
217+
<command commandId="org.eclipse.lsp4e.folding.collapseAll" label="%command.folding.foldAll.name">
218+
<visibleWhen>
219+
<or>
220+
<with variable="activeEditorInput">
221+
<test property="org.eclipse.lsp4e.hasLanguageServer" />
222+
</with>
223+
<with variable="activeEditor">
224+
<test property="org.eclipse.lsp4e.hasLanguageServer" />
225+
</with>
226+
</or>
227+
</visibleWhen>
228+
</command>
229+
<command commandId="org.eclipse.lsp4e.folding.expandAll" label="%command.folding.unfoldAll.name">
230+
<visibleWhen>
231+
<or>
232+
<with variable="activeEditorInput">
233+
<test property="org.eclipse.lsp4e.hasLanguageServer" />
234+
</with>
235+
<with variable="activeEditor">
236+
<test property="org.eclipse.lsp4e.hasLanguageServer" />
237+
</with>
238+
</or>
239+
</visibleWhen>
240+
</command>
241+
<separator name="org.eclipse.lsp4e.folding.main.group.end" visible="true"/>
242+
</menuContribution>
243+
</extension>
244+
245+
<!-- folding: key bindings -->
246+
<extension point="org.eclipse.ui.bindings">
247+
<key sequence="M1+M2+NUMPAD_DIVIDE"
248+
commandId="org.eclipse.lsp4e.folding.collapseAll"
249+
contextId="org.eclipse.ui.genericeditor.genericEditorContext"
250+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
251+
<key sequence="M1+M2+NUMPAD_MULTIPLY"
252+
commandId="org.eclipse.lsp4e.folding.expandAll"
253+
contextId="org.eclipse.ui.genericeditor.genericEditorContext"
254+
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
255+
</extension>
256+
157257

158258
<!-- ===================================== -->
159259
<!-- Find References Support -->
@@ -464,7 +564,7 @@
464564
contentType="org.eclipse.core.runtime.text">
465565
<enabledWhen>
466566
<reference definitionId="org.eclipse.lsp4e.editorHasLanguageServer" />
467-
</enabledWhen>
567+
</enabledWhen>
468568
</reconcilingStrategy>
469569
</extension>
470570

org.eclipse.lsp4e/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<artifactId>org.eclipse.lsp4e</artifactId>
1212
<packaging>eclipse-plugin</packaging>
13-
<version>0.18.30-SNAPSHOT</version>
13+
<version>0.18.31-SNAPSHOT</version>
1414

1515
<build>
1616
<plugins>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Vegard IT GmbH and others.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Sebastian Thomschke (Vegard IT GmbH) - initial implementation.
11+
*******************************************************************************/
12+
package org.eclipse.lsp4e.operations.folding;
13+
14+
import org.eclipse.core.commands.AbstractHandler;
15+
import org.eclipse.core.commands.ExecutionEvent;
16+
import org.eclipse.jdt.annotation.Nullable;
17+
import org.eclipse.jface.text.source.projection.ProjectionViewer;
18+
import org.eclipse.lsp4e.ui.UI;
19+
20+
public class FoldAllHandler extends AbstractHandler {
21+
22+
@Override
23+
public @Nullable Object execute(final ExecutionEvent event) {
24+
if (UI.getActiveTextViewer() instanceof final ProjectionViewer viewer && viewer.isProjectionMode()) {
25+
UI.runOnUIThread(() -> viewer.doOperation(ProjectionViewer.COLLAPSE_ALL));
26+
}
27+
return null;
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Vegard IT GmbH and others.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Sebastian Thomschke (Vegard IT GmbH) - initial implementation.
11+
*******************************************************************************/
12+
package org.eclipse.lsp4e.operations.folding;
13+
14+
import org.eclipse.core.commands.AbstractHandler;
15+
import org.eclipse.core.commands.ExecutionEvent;
16+
import org.eclipse.jdt.annotation.Nullable;
17+
import org.eclipse.jface.text.source.projection.ProjectionViewer;
18+
import org.eclipse.lsp4e.ui.UI;
19+
20+
public class UnfoldAllHandler extends AbstractHandler {
21+
22+
@Override
23+
public @Nullable Object execute(final ExecutionEvent event) {
24+
if (UI.getActiveTextViewer() instanceof final ProjectionViewer viewer && viewer.isProjectionMode()) {
25+
UI.runOnUIThread(() -> viewer.doOperation(ProjectionViewer.EXPAND_ALL));
26+
}
27+
return null;
28+
}
29+
}

0 commit comments

Comments
 (0)