Repository: ErykMroczek/mofmt (language: python)

Issue:
Wrong indent for annotation in otherwise empty sections
With mofmt 0.4.1 annotations ~~of local class definitions~~ in empty sections (equation, algorithm, protected) are indented one level too much:

Exemplary input:
```
model M
protected
  model X
  equation
    annotation (revisionId = "c04e23a0d");
  end X;
end M;
```

Output:
```
model M

protected

  model X

  equation
      annotation (revisionId = "c04e23a0d");

  end X;

end M;
```


Discussion / hints:
Does it happen only in cases like that, ie. after `equation`, `protected` etc. keywords, without any elements/equations?
Yes, that seems to be the problem. It has nothing to do with nested classes, the problem also occurs for this code:

```
function indent
  input String u;
  output String y = "    " + u;
algorithm
  annotation (Inline = true);
end indent;
```

Fix patch:
diff --git a/src/formatting.rs b/src/formatting.rs
index 4bb72d5..d78b506 100644
--- a/src/formatting.rs
+++ b/src/formatting.rs
@@ -496,7 +496,12 @@ fn composition(f: &mut Formatter, tree: Tree) {
                 }
                 SyntaxKind::AnnotationClause => {
                     f.markers.push(Marker::Indent);
-                    let extern_element_annotation = f.prev_tok != ModelicaToken::Semicolon;
+                    let extern_element_annotation = [
+                        ModelicaToken::RParen,
+                        ModelicaToken::External,
+                        ModelicaToken::String,
+                    ]
+                    .contains(&f.prev_tok);
                     if extern_element_annotation {
                         f.markers.push(Marker::Indent);
                     }


Test patch:
diff --git a/tests/samples/code-input.mo b/tests/samples/code-input.mo
index 84a2bb4..f84fa13 100644
--- a/tests/samples/code-input.mo
+++ b/tests/samples/code-input.mo
@@ -200,6 +200,10 @@ external"C" foo[1].bar [2] = baz(x
 annotation (Library="doesn't matter");
 annotation (smoothOrder = 2);
 end Foo;
+impure function Baz "To check annotations after empty sections"
+algorithm
+annotation ();
+end Baz;
 partial function Bar "Just in case"
   initial algorithm
 
diff --git a/tests/samples/code-output.mo b/tests/samples/code-output.mo
index c071a83..2691176 100644
--- a/tests/samples/code-output.mo
+++ b/tests/samples/code-output.mo
@@ -285,6 +285,14 @@ external "C"
   annotation (smoothOrder = 2);
 
 end Foo;
+impure function Baz
+  "To check annotations after empty sections"
+
+algorithm
+
+  annotation ();
+
+end Baz;
 partial function Bar
   "Just in case"