arduino / arduino-ide

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

Added sketch tabs don't follow concatenation order #987

Open per1234 opened 2 years ago

per1234 commented 2 years ago

Describe the problem

Arduino sketches may consist of multiple files, which are shown in the Arduino IDE as tabs when that sketch is open. All the .ino files of the sketch are concatenated before compiling, starting with the file that matches the sketch name, followed by the rest in lexicographical order:

https://arduino.github.io/arduino-cli/dev/sketch-build-process/#pre-processing

The resulting program structure is conveyed to the user in an intuitive manner by the order of the .ino sketch tabs in the IDE reflecting their concatenation order.

🐛 Tabs of newly added files follow the order of addition rather than the order of sketch concatenation. The concatenation behavior for these files will not be intuitive to a user unfamiliar with the obscure low level details of sketch pre-processing.

To reproduce

  1. Click the button on the right side of the editor toolbar.
  2. Select "New Tab" from the menu.
  3. In the "Name for new file" field, type b.ino
  4. Click the OK button.
  5. Click the button on the right side of the editor toolbar.
  6. In the "Name for new file" field, type a.ino
  7. Click the OK button.

🐛 The "a.ino" tab is added to the right of the "b.ino" tab.

image

Expected behavior

The editor tabs of .ino sketch files match their concatenation order.

Arduino IDE version

Original report

2.0.0-rc6-snapshot-289f9d7

Last verified with

51f69f6a5930ed1c947ac708b2d7280ea3e0cd57

Operating system

Windows

Operating system version

10

Additional context

The bug also occurs when files are added to the sketch externally


The bug also occurs when files are renamed.


Arduino IDE 1.x handles ordering of tabs for added sketch files as expected.

Additional reports

Issue checklist

kittaakos commented 2 years ago

The editor tabs of .ino sketch files match their concatenation order.

Could you please help slightly generalize the expectation and help define the tab order for non .ino and .pde files? I want to tackle them together (also with #643).

The spec says:

No pre-processing is done to files in a sketch with any extension other than .ino or .pde.

What about the other files and their order?

IDE2 allows creating files with these extensions so that they can open up in an editor:

https://github.com/arduino/arduino-ide/blob/8a85b5c3d89f8ab2210279910cd3cb5606dc7291/arduino-ide-extension/src/common/protocol/sketches-service.ts#L164-L177

On the first sketch open, IDE2 opens the main sketch file (MainFile) and the files in the root folder (RootFolderFiles):

https://github.com/arduino/arduino-ide/blob/8a85b5c3d89f8ab2210279910cd3cb5606dc7291/arduino-ide-extension/src/common/protocol/sketches-service.ts#L137-L140

Is there any expectation of opening non-sketch-related editors in the main area? For example, when opening the Advanced Settings JSON or graphical editor?

Thank you!