Skip to content

Commit

Permalink
[#1731] Updating the Eclipse Support webpage.
Browse files Browse the repository at this point in the history
- Add Mark Occurrences and Find References section.
- Improve Folding section to break the long lines of the embedded
code snippets properly.

Signed-off-by: Tamas Miklossy <miklossy@itemis.de>
  • Loading branch information
miklossy committed May 4, 2020
1 parent c765d13 commit 2dbe0c4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
89 changes: 64 additions & 25 deletions xtext-website/documentation/310_eclipse_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,42 +502,51 @@ In order to make `events`, `resetEvents` and `commands` foldable too, a custom i
```java
public class StatemachineFoldingRegionProvider extends DefaultFoldingRegionProvider {

@Override
protected void computeObjectFolding(EObject o, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
if (o instanceof Statemachine) {
XtextResource res = (XtextResource) o.eResource();
computeEventsFolding(res, foldingRegionAcceptor);
computeResetEventsFolding(res, foldingRegionAcceptor);
computeCommandsFolding(res, foldingRegionAcceptor);
} else {
super.computeObjectFolding(o, foldingRegionAcceptor);
}
}
@Override
protected void computeObjectFolding(
EObject o,
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {

if (o instanceof Statemachine) {
XtextResource res = (XtextResource) o.eResource();
computeEventsFolding(res, foldingRegionAcceptor);
computeResetEventsFolding(res, foldingRegionAcceptor);
computeCommandsFolding(res, foldingRegionAcceptor);
} else {
super.computeObjectFolding(o, foldingRegionAcceptor);
}
}

private void computeEventsFolding(XtextResource res, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}
private void computeEventsFolding(
XtextResource res,
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}

private void computeResetEventsFolding(XtextResource res, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}
private void computeResetEventsFolding(
XtextResource res,
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}

private void computeCommandsFolding(XtextResource res, IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}
...
private void computeCommandsFolding(
XtextResource res,
IFoldingRegionAcceptor<ITextRegion> foldingRegionAcceptor) {
...
}
...
}
```

Additionally, the [StatemachineFoldingRegionProvider]({{site.src.xtext_eclipse}}/org.eclipse.xtext.xtext.ui.examples/projects/fowlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/src/org/eclipse/xtext/example/fowlerdsl/ui/folding/StatemachineFoldingRegionProvider.java) class has to be bound in the [StatemachineUiModule]({{site.src.xtext_eclipse}}/org.eclipse.xtext.xtext.ui.examples/projects/fowlerdsl/org.eclipse.xtext.example.fowlerdsl.ui/src/org/eclipse/xtext/example/fowlerdsl/ui/StatemachineUiModule.java):
```java
public class StatemachineUiModule extends AbstractStatemachineUiModule {

...
...

public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
return StatemachineFoldingRegionProvider.class;
}
public Class<? extends IFoldingRegionProvider> bindIFoldingRegionProvider() {
return StatemachineFoldingRegionProvider.class;
}
}
```

Expand Down Expand Up @@ -604,6 +613,36 @@ public class MyDslUiModule extends AbstractMyDslUiModule {
}
```

## Mark Occurrences {#maroccurrences}
Xtext-based editors are able to highlight all occurrences of a certain element in the opened DSL file. Once the user selects an element while the `Toggle Mark Occurrences` button is enabled, all occurrences are highlighted with corresponding markers on the right side of the editor.

![](images/mark_occurrences.png)

Customization can happen by either extending the [DefaultOccurrenceComputer]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/occurrences/DefaultOccurrenceComputer.java) class or even providing a complete implementation of the [IOccurrenceComputer]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/occurrences/IOccurrenceComputer.java) interface.

```java
public class MyDslOccurrenceComputer extends DefaultOccurrenceComputer {
...
}
```

```java
public class MyDslUiModule extends AbstractMyDslUiModule {

public Class<? extends IOccurrenceComputer> bindIOccurrenceComputer() {
return MyDslOccurrenceComputer.class;
}

}
```

## Find References {#findreferences}
Xtext-based editors are able to locate all references in the entire workspace where a certain element is referred to. Invoking the `Find References` context menu or using the keyboard shortcut `Ctlr+Shift+G` (`Cmd+Shift+G` on Mac) on the selected element lists all the references in the `Search` view.

![](images/find_references.gif)

The [org.eclipse.xtext.findReferences.IReferenceFinder]({{site.src.xtext_core}}/org.eclipse.xtext/src/org/eclipse/xtext/findReferences/IReferenceFinder.java) and the [org.eclipse.xtext.ui.editor.findrefs.IReferenceFinder]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/findrefs/IReferenceFinder.java) interfaces are responsible for this functionality. These interfaces are implemented by the [ReferenceFinder]({{site.src.xtext_core}}/org.eclipse.xtext/src/org/eclipse/xtext/findReferences/ReferenceFinder.java) and the [DelegatingReferenceFinder]({{site.src.xtext_eclipse}}/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/findrefs/DelegatingReferenceFinder.java) classes. As almost everything in the Xtext framework, these components can also be customized if the default implementations do not satisfy your needs.

## Syntax Coloring {#highlighting}

Besides the already mentioned advanced features like [content assist](#content-assist) and [code formatting](303_runtime_concepts.html#formatting) the powerful editor for your DSL is capable to mark up your model-code to improve the overall readability. It is possible to use different colors and fonts according to the meaning of the different parts of your input file. One may want to use some unintrusive colors for large blocks of comments while identifiers, keywords and strings should be colored differently to make it easier to distinguish between them. This kind of text decorating markup does not influence the semantics of the various sections but helps to understand the meaning and to find errors in the source code.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2dbe0c4

Please sign in to comment.