Skip to content

Global custom formatter configuration not used if on different drive than IDE started from #1551

Open
@per1234

Description

@per1234

Describe the problem

The formatting style produced by the Arduino IDE "Auto Format" feature can be customized by the user. This customization can be done either on a per-sketch basis or else globally (#1019). The global configuration file can be placed in either of two locations:

  • Configuration folder (e.g., C:\Users\per\.arduinoIDE\.clang-format)
  • Data folder (e.g., C:\Users\per\AppData\Local\Arduino15\.clang-format)

🐛 If Arduino IDE is started from a path on a different drive than the one containing the global formatter configuration file, the file does not take effect.

To reproduce

Equipment

Extra drive (type and capacity don't matter).

Steps

  1. Select File > Quit from the Arduino IDE menus if it is running.
  2. Create a file at the following path:
    C:\Users\per\.arduinoIDE\.clang-format
    
    with the following content:
    IndentWidth: 8
  3. Open a command line terminal on a drive other than C:\.
  4. Start Arduino IDE from the command line terminal.
    The command line was only used as a convenient way to start the IDE from a different drive. The bug also occurs if the IDE is installed to a different drive and started normally.
  5. Wait for the IDE to finish starting up.
  6. Select File > New from the Arduino IDE menus.
  7. Select Edit > Auto Format from the Arduino IDE menus.

🐛 The indentation is not changed to 8 spaces according to the global formatter configuration.

Expected behavior

Global formatter configuration files are recognized regardless of which drive the IDE was started from.

Arduino IDE version

2.0.1-snapshot-bc264d1

Operating system

Windows

Operating system version

10

Additional context

The cause of the bug is the redundant URI to filesystem path conversion applied to the global configuration file paths:

return FileUri.fsPath(dataDirUri);

return FileUri.fsPath(configDirUri);

const folderPath = FileUri.fsPath(await folderUri);

This causes the paths to have this form:

  • \Users\per\.arduinoIDE\.clang-format
  • \Users\per\AppData\Local\Arduino15\.clang-format

That points to the correct place when the IDE is started from C:\, but not when it is started from another drive.

The local configuration file path is only subject to a single URI to filesystem path conversion, so it is formatted correctly, meaning the bug does not affect this configuration method:

  • C:\Users\per\Documents\Arduino\sketch_oct9a\.clang-format

Originally reported by @Willem43T at https://forum.arduino.cc/t/clang-setup-where-is-clang-format/1016866/17

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    os: windowsSpecific to Windows operating systemtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions