arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.27k stars 386 forks source link

"Reveal definition aside" produces broken split editor state #2225

Open per1234 opened 1 year ago

per1234 commented 1 year ago

Describe the problem

Sketch tab management

The unit of the Arduino sketch project is a folder. Even though many of the common sketches consist of only a single file, the folder may contain multiple sketch code files. All the source files present in that folder are compiled to a single program.

In order to intuitively communicate the nature of the sketch to the user and avoid confusion that might be caused by code from files not visible to the user still being compiled, each Arduino IDE window contains a single sketch, with all primary code files of the sketch open as tabs. These tabs are not closeable as would be the case if Arduino IDE was a general purpose editor instead of a tool specifically designed for development of Arduino sketches.

Split editor feature

The Eclipse Theia IDE framework Arduino IDE is built on supports the "split editor" feature, where multiple panels can be created in the editor view so that content can be viewed side-by-side while editing. This includes having the same file open in two tabs.

Problems with split editor in Arduino IDE

Arduino IDE gained a split editor capability by chance rather than design through an update of the Theia dependency. The users discovered this new feature, but also discovered that it did not work correctly: the system for preventing primary sketch code file tabs from being closed did not allow the redundant tabs created by the split editor feature to be closed (https://github.com/arduino/arduino-ide/issues/552). Since it did not work correctly and had not been planned, Arduino IDE project managers decided the split editor feature should be disabled (https://github.com/arduino/arduino-ide/pull/940) until resources were available to implement it in a fully functional state (https://github.com/arduino/arduino-ide/issues/909).

🐛 Despite the efforts to disable the feature, the editor is still split when the "editor.action.revealDefinitionAside" command is executed. If the definition is in a root sketch file, it will not be possible to then unsplit the editor using the primary Arduino IDE interface.

To reproduce

  1. Create the following sketch:
    void foo() {}
    void setup() {
     foo();
    }
    void loop() {}
  2. Select any board with language server support.
  3. Hold Ctrl+Alt while clicking the foo call on line 3 of the sketch. A split editor pane opens: image
  4. Try to find a way to unsplit the editor via the Arduino IDE primary interface.

🐛 It is not possible to unsplit the editor.

Expected behavior

Opening primary sketch code files as tabs of a split editor panel is only possible once the split editor feature is in a fully functional state.

Arduino IDE version

2.2.1

Operating system

Windows

Operating system version

11

Additional context

In addition to the Ctrl+Alt+click trigger for editor.action.revealDefinitionAside command used in the demo above, it also has a default keyboard shortcut Ctrl+K Ctrl+F12, which should also be disabled by default in order to prevent the users from accidentally putting the IDE into the broken split editor state via that path.

Since keymaps.json is a supplemental file and thus closeable, the IDE's behavior of opening this file in a split editor is not a problem in itself. It is actually a fairly reasonable default behavior since the user might like to view the keymaps.json editor alongside the "Keyboard Shortcuts" GUI view. But the average user is unlikely to open keymaps.json, so it wouldn't be a significant loss if the behavior was changed to opening the file without splitting the editor panel.

Additional reports

Related


Originally reported at https://forum.arduino.cc/t/cant-close-tab/1143314

Workaround

The IDE editor can be recovered from its split state by performing the following instructions:

  1. Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
  2. Select the "View: Reset Workbench Layout" command from the menu.

Issue checklist

Tilation commented 6 months ago

This is still happening on 2.3.2, so annoying.