Repository: hannah-sten/texify-idea
Issue: Command definition without braces not shown correctly in structure

<!-- **Note**: you can discard the template below if you are requesting support or proposing a new feature. -->

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

IntelliJ IDEA 2019.3 (Ultimate Edition)
Build #IU-193.5233.102, built on November 27, 2019
Runtime version: 11.0.4+10-b520.11 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.1

#### TeXiFy IDEA version

0.7-alpha.47

#### What I did (steps to reproduce)

Add this command definition in the preamble of a LaTeX file:

```latex
\\newcommand\\widebody[1]{%
\\makebox[\\linewidth][c]{%
\\begin{minipage}{\\paperwidth}
    \\centering#1
\\end{minipage}%
}%
}
```

#### Expected behavior

The "Structure" panel shows the command definition.

#### Actual behavior

The "Structure" panel shows that there is a command definition (there is a line with the "C" icon) but it does not show the command name nor its definition: the line is empty except for the "C" icon.

#### Workaround

Actually, adding braces around the command name fixes the issue:

```latex
\\newcommand{\\widebody}[1]{%
\\makebox[\\linewidth][c]{%
\\begin{minipage}{\\paperwidth}
    \\centering#1
\\end{minipage}%
}%
}
```

However the code works without braces (with lualatex if it has any importance). I don't know enough LaTeX to tell whether braces should be enforced or not.

Changed files:
src/nl/hannahsten/texifyidea/structure/latex/LatexNewCommandPresentation.kt

diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexNewCommandPresentation.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexNewCommandPresentation.kt
index 0255df63d..3ef1ddd59 100644
--- a/src/nl/hannahsten/texifyidea/structure/latex/LatexNewCommandPresentation.kt
+++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexNewCommandPresentation.kt
@@ -3,6 +3,7 @@ package nl.hannahsten.texifyidea.structure.latex
 import com.intellij.navigation.ItemPresentation
 import nl.hannahsten.texifyidea.TexifyIcons
 import nl.hannahsten.texifyidea.psi.LatexCommands
+import nl.hannahsten.texifyidea.util.nextCommand
 
 /**
  * @author Hannah Schellekens
@@ -16,7 +17,7 @@ class LatexNewCommandPresentation(newCommand: LatexCommands) : ItemPresentation
         // Fetch parameter amount.
         val optional = newCommand.optionalParameters
         var params = -1
-        if (!optional.isEmpty()) {
+        if (optional.isNotEmpty()) {
             try {
                 params = Integer.parseInt(optional[0])
             }
@@ -27,7 +28,15 @@ class LatexNewCommandPresentation(newCommand: LatexCommands) : ItemPresentation
 
         // Get command name.
         val required = newCommand.requiredParameters
-        this.newCommandName = required.firstOrNull() ?: "" + suffix
+        val command = if (required.size > 0) {
+            required.first()
+        }
+        else {
+            // If there are no required parameters, the user may have left out the braces around the first one, so we get it manually
+            newCommand.nextCommand()?.commandToken?.text
+        }
+
+        this.newCommandName = command ?: "" + suffix
 
         // Get value.
         locationString = if (required.size > 1) {