Skip to content

Commit

Permalink
Add a question
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderpann committed Nov 7, 2023
1 parent 2b40851 commit 7c29a31
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/doc/docs/aspects/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ The inherited scope is often used for references that inherit the referenced con

[Pseudo-references: emulating references](https://specificlanguages.com/posts/2022-02/02-pseudoreferences/){{ blog('sl') }}

!!! question "How do you check for an unresolved reference programmatically?"

```java
private static boolean isValidReference(reference ref) {
if (ref == null ) return false; }
SNode target = SNodeOperations.getTargetNodeSilently(ref);
target != null && target.getModel() != null;
}
```

{{ answer_by('kbirken') }}

## [Scopes](https://www.jetbrains.com/help/mps/scopes.html)

!!! question "How do you filter scopes? Which scopes are available?"
Expand Down
49 changes: 31 additions & 18 deletions src/doc/docs/aspects/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ This section contains some more advanced topics and questions when defining edit
[Use empty text for empty cells](https://specificlanguages.com/posts/basic-editors/use-empty-text-for-empty-cells/){{ blog('sl') }}


!!! hint "How can you set editor hints?"

- You can set hints via `#!java editorContext.getEditorComponent().getUpdater()`
- Set explicit hints for nodes.
- Set initial hints globally. They behave similarly to pushed hints.
- Via right-click: Push editor hints and select a specific one.

- Via an {{ mps_url("@mpsutil.EditorHintToggleAction") }} (e.g., in action declarations)
- They are not visible in the push Editor hints menu.
- If you need the same behavior, for example, in intentions, you can use code from there (via [ConceptEditorHintSettingsComponent.HintsState](http://127.0.0.1:63320/node?ref=1ed103c3-3aa6-49b7-9c21-6765ee11f224%2Fjava%3Ajetbrains.mps.nodeEditor.hintsSettings%28MPS.Editor%2F%29%2F%7EConceptEditorHintSettingsComponent))
- Set explicit hints for nodes and hints via {{ mps_url("@mpsutil.EditorHintToggleAction") }}.
The usage of [ConceptEditorHintSettingsComponent.HintsState](http://127.0.0.1:63320/node?ref=1ed103c3-3aa6-49b7-9c21-6765ee11f224%2Fjava%3Ajetbrains.mps.nodeEditor.hintsSettings%28MPS.Editor%2F%29%2F%7EConceptEditorHintSettingsComponent%24HintsState) is not so obvious.


??? question "How do you set the cursor to the first editable cell?"

> ![editable cell and error_cell](images/editor/editable_cell_error_cell.png)
Expand Down Expand Up @@ -244,6 +230,37 @@ This section contains some more advanced topics and questions when defining edit

You can implement a cell similar to the cell [EditorCell_MathEnd](http://127.0.0.1:63320/node?ref=r%3A34f40b74-cb38-46ba-8e5b-13b443c803c4%28de.itemis.mps.editor.math.runtime%29%2F9204702729138147058) in {{ mps_extensions() }}.

### Editor Hints

!!! question "Is there a utility class related to editor hints?"

Yes, there is in {{ mbeddr() }}: {{ mps_url("@mbeddr.EditorHintHelper") }}.

!!! hint "How can you set editor hints?"

- You can set hints via `#!java editorContext.getEditorComponent().getUpdater()`
- Set explicit hints for nodes.
- Set initial hints globally. They behave similarly to pushed hints.
- Via right-click: Push editor hints and select a specific one.

- Via an {{ mps_url("@mpsutil.EditorHintToggleAction") }} (e.g., in action declarations)
- They are not visible in the push Editor hints menu.
- If you need the same behavior, for example, in intentions, you can use code from there (via [ConceptEditorHintSettingsComponent.HintsState](http://127.0.0.1:63320/node?ref=1ed103c3-3aa6-49b7-9c21-6765ee11f224%2Fjava%3Ajetbrains.mps.nodeEditor.hintsSettings%28MPS.Editor%2F%29%2F%7EConceptEditorHintSettingsComponent))
- Set explicit hints for nodes and hints via {{ mps_url("@mpsutil.EditorHintToggleAction") }}.
The usage of [ConceptEditorHintSettingsComponent.HintsState](http://127.0.0.1:63320/node?ref=1ed103c3-3aa6-49b7-9c21-6765ee11f224%2Fjava%3Ajetbrains.mps.nodeEditor.hintsSettings%28MPS.Editor%2F%29%2F%7EConceptEditorHintSettingsComponent%24HintsState) is not so obvious.

!!! question "Can I push editor hints with a node attribute?"

Create a *custom factory cell* (available in {{ mps_extensions() }}) with a factory method similar to the following:

```java
factory method(editorContext, node, cell)->EditorCell {
node<> n = node;
editorContext.getEditorComponent().getUpdater().addExplicitEditorHintsForNode(n.parent/.getReference(), concept editor hint/HintA/);
cell
}
```

## [Inspector](https://www.jetbrains.com/help/mps/mps-inspector.html)

As a language developer, you often use the inspector in the editor aspect to set styles, or change macros in the editor aspect.
Expand Down Expand Up @@ -362,10 +379,6 @@ This section contains answers to code-related questions.

To override this behavior, you can specify the action `NEXT` in an [action map](https://www.jetbrains.com/help/mps/editor.html#actionmaps) ([MPS source reference](https://github.com/JetBrains/MPS/blob/dac7f125fdaae7739110073cd8b8bb7ade8fc49e/editor/editor-runtime/source/jetbrains/mps/nodeEditor/EditorComponent.java#L1809)). The default action is declared [here](https://github.com/JetBrains/MPS/blob/master/editor/editor-runtime/source/jetbrains/mps/nodeEditor/EditorComponentActions.java#L57) with its default implementation in [NodeEditorActions](https://github.com/JetBrains/MPS/blob/dac7f125fdaae7739110073cd8b8bb7ade8fc49e/editor/editor-runtime/source/jetbrains/mps/nodeEditor/NodeEditorActions.java#L401)(it jumps to the next editable leaf of the editor cell tree).

!!! question "Is there a utility class related to editor hints?"

Yes, there is in {{ mbeddr() }}: {{ mps_url("@mbeddr.EditorHintHelper") }}.


!!! question "I am using `NodeHighlightManager.mark()` to highlight AST nodes. MPS then uses the provided color for the cell's background and a slightly darker shade for an additional border. Can we change this, i.e., only paint the background, but not the border?"

Expand Down
8 changes: 8 additions & 0 deletions src/doc/docs/aspects/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ generator configurations, the generator of this language will be invoked by defa
#print cls:BaseConcept.getLanguage().getQualifiedName();
```

!!! question "Can I get the ConceptEditorDeclaration for a given concept?"

```java
concept<> concept = myNode/.getConcept();
model editorModel = LanguageAspect.EDITOR.get((Language) concept.getLanguage().getSourceModule());
#print editorModel.roots(ConceptEditorDeclaration).findFirst({~it => it.conceptDeclaration :eq: concept.asNode; });
```

## [Interfaces](https://www.jetbrains.com/help/mps/structure.html#conceptsandconceptinterfaces)

Interfaces work the same way as Java interfaces. They can be used to mark common classes, contain common methods and support the same aspects as
Expand Down

0 comments on commit 7c29a31

Please sign in to comment.