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
4 changes: 3 additions & 1 deletion io.cucumber.eclipse.editor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.5.0",
org.eclipse.ui.console,
org.eclipse.ui.workbench.texteditor,
io.cucumber.tag-expressions,
org.eclipse.unittest.ui;bundle-version="1.0.0"
org.eclipse.unittest.ui;bundle-version="1.0.0",
io.cucumber.gherkin-utils;bundle-version="9.0.0",
org.eclipse.core.expressions;bundle-version="3.9.500"
Bundle-RequiredExecutionEnvironment: JavaSE-21
Automatic-Module-Name: io.cucumber.eclipse.editor
Bundle-ActivationPolicy: lazy
Expand Down
58 changes: 58 additions & 0 deletions io.cucumber.eclipse.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,64 @@
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
</extension>

<extension point="org.eclipse.ui.bindings">
<key sequence="M1+M2+F"
commandId="io.cucumber.eclipse.editor.format"
contextId="org.eclipse.ui.textEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="popup:org.eclipse.ui.genericeditor.source.menu?after=additions">
<command commandId="io.cucumber.eclipse.editor.format">
<visibleWhen>
<with variable="activeEditorInput">
<adapt type="org.eclipse.core.resources.IResource">
<test
property="org.eclipse.core.resources.contentTypeId"
value="io.cucumber.eclipse.editor.content-type.feature">
</test>
</adapt>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>

<extension point="org.eclipse.ui.commands">
<command
categoryId="io.cucumber.eclipse.editor.category"
id="io.cucumber.eclipse.editor.format"
name="Format Feature File" />
</extension>


<extension point="org.eclipse.ui.handlers">
<handler
class="io.cucumber.eclipse.editor.format.GherkingFormatHandler"
commandId="io.cucumber.eclipse.editor.format">
<activeWhen>
<with variable="activePart">
<test property="io.cucumber.eclipse.editor.format.isGherkingDocument" value="true">
</test>
</with>
</activeWhen>
</handler>
</extension>

<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="io.cucumber.eclipse.editor.format.EditorInputPropertyTester"
id="io.cucumber.eclipse.editor.format.editorInputPropertyTester"
namespace="io.cucumber.eclipse.editor.format"
properties="isGherkingDocument"
type="org.eclipse.ui.IWorkbenchPart">
</propertyTester>
</extension>

<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.cucumber.eclipse.editor.format;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;

import io.cucumber.eclipse.editor.document.GherkinEditorDocument;

public class EditorInputPropertyTester extends PropertyTester {

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (receiver instanceof IEditorPart part) {
if ("isGherkingDocument".equals(property)) {
IEditorInput editorInput = part.getEditorInput();
if (editorInput instanceof IFileEditorInput fileInput) {
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager()
.getTextFileBuffer(fileInput.getFile().getFullPath(), LocationKind.IFILE);
if (buffer != null) {
return GherkinEditorDocument.isCompatible(buffer.getDocument());
}
}
}
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.cucumber.eclipse.editor.format;

import java.util.Optional;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;

import io.cucumber.eclipse.editor.document.GherkinEditorDocument;
import io.cucumber.gherkin.utils.pretty.Pretty;
import io.cucumber.gherkin.utils.pretty.Syntax;
import io.cucumber.messages.types.GherkinDocument;

public class GherkingFormatHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
if (part instanceof IEditorPart editor) {
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof IFileEditorInput fileInput) {
GherkinEditorDocument document = GherkinEditorDocument.get(fileInput.getFile());
if (document != null) {
formatDocument(document, fileInput.getFile());
}
}
}
return null;
}

private void formatDocument(GherkinEditorDocument document, IFile file) {
Optional<GherkinDocument> gherkinDocument = document.getGherkinDocument();
if (gherkinDocument.isEmpty()) {
return;
}
String prettyPrint = Pretty.prettyPrint(gherkinDocument.get(), Syntax.gherkin);
document.getDocument().set(prettyPrint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>33.0.0</version>
<version>33.1.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand All @@ -35,7 +35,7 @@ Export-Package: *;version="${version}";-noimport:=true
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.26.0</version>
<version>7.29.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand All @@ -53,7 +53,7 @@ Export-Package: *;version="${version}";-noimport:=true
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>7.26.0</version>
<version>7.29.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand Down Expand Up @@ -100,6 +100,24 @@ Export-Package: *;version="${version}";-noimport:=true
</dependency>
</dependencies>
</location>
<location includeDependencyDepth="infinite" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin-utils</artifactId>
<version>9.0.0</version>
<type>jar</type>
</dependency>
</dependencies>
<instructions><![CDATA[
Bundle-Name: ${mvnGroupId}:${mvnArtifactId}:${mvnVersion}
version: ${version_cleanup;${mvnVersion}}
Bundle-SymbolicName: ${mvnGroupId}.${mvnArtifactId}
Bundle-Version: ${version}
Import-Package: !sun.*,io.cucumber.messages.internal.com.google.gson*,!io.cucumber.messages.internal.*,!org.checkerframework.*,*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think cucumber.messages.internal still exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpkorstanje year this is maybe not required anymore and is a bit cumbersome to manage anyways. Because of that I would suggest adding the data in cucumber directly as with:

this is much more appropriate and consistent.

Copy link
Contributor

@mpkorstanje mpkorstanje Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with these definitions is that it they're equally cumbersome if kept with the project itself. Problems exclusively show up at runtime. In this case it is harmless, but forgetting to expose a package would break that module.

But lets keep that discussion in github.com/cucumber/gherkin-utils/pull/131. Consider this FYI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpkorstanje in this case superfluous instructions simply do not taken into account but of course to not add to the clarity. So we can see this more as no one ever noticed this has gone :-D

Export-Package: *;version="${version}";-noimport:=true
]]></instructions>
</location>
</locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
</target>