Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use code formatter tool directly #1009

Closed
4 tasks done
per1234 opened this issue May 27, 2022 · 3 comments · Fixed by #1019
Closed
4 tasks done

Use code formatter tool directly #1009

per1234 opened this issue May 27, 2022 · 3 comments · Fixed by #1019
Assignees
Labels
conclusion: resolved Issue was resolved criticality: medium Of moderate impact topic: code Related to content of the project itself topic: language server Related to the Arduino Language Server type: enhancement Proposed improvement

Comments

@per1234
Copy link
Contributor

per1234 commented May 27, 2022

Describe the request

Use the code formatting tool directly for the IDE's "Auto Format" capability.

🙂 This will ensure the fastest possible response when the user triggers a code formatting operation.

Describe the current behavior

The Arduino IDE provides a sketch code formatter (e.g., Tools > Auto Format).

Formatting is currently done via the "Arduino Language Server", which also provides the code aware features such as autocompletion, problem detection, "Go to definition". This approach is convenient because a high quality code formatting capability is already available is the "clangd" C++ language server used by Arduino Language Server.

The language server features require the complete program to be known, which includes far more than the code in the sketch itself (i.e., toolchain, core, libraries). The amount of processing involved is significant, which means that there will always be some latency in the language server results.

Code formatting is different in that it only requires passing the text of the current sketch editor tab through the formatter tool, with no program processing needed.

🙁 The auto format process is unnecessarily subject to program processing latency, which causes significant delays between the user triggering an "Auto Format" operation and getting the result.

Arduino IDE version

2.0.0-rc6-snapshot-522a5c6

Operating system

Windows, Linux, macOS

Operating system version

Any

Additional context

Build infrastructure for the standalone ClangFormat code formatter tool is already in place at https://github.com/arduino/clang-static-binaries


Please let's start with a PoC and see how tricky this is


  • @per1234 to provide .clang-format configuration file

Unfortunately the main limitation is that clang-format will not accept stdin as input but requires a file, so when formatting a Tab's content we'll need to use a temp file and run it as follows

clang-format --style=/path/to/style-config.clang-format /path/to/source-file.ino

This proposal is equivalent to the approach taken by Arduino IDE 1.x


Related:

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the latest nightly build
  • My request contains all necessary details
@per1234 per1234 added criticality: medium Of moderate impact topic: code Related to content of the project itself type: enhancement Proposed improvement labels May 27, 2022
@per1234
Copy link
Contributor Author

per1234 commented May 27, 2022

@per1234 to provide .clang-format configuration file

The ClangFormat configuration is here in the config variable (you can just copy/paste the content of that string):

https://github.com/arduino/arduino-language-server/blob/main/ls/ls_formatter.go

@per1234 per1234 added the topic: language server Related to the Arduino Language Server label May 27, 2022
kittaakos pushed a commit to kittaakos/arduino-ide that referenced this issue Jun 2, 2022
Closes arduino#1009

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit to kittaakos/arduino-ide that referenced this issue Jun 2, 2022
 - Bumped `clangd` to `14.0.0`,
 - Can use `.clang-format` from:
   - current sketch folder,
   - `~/.arduinoIDE/.clang-format`,
   - `directories#data/.clang-format`, or
   - falls back to default formatter styles.

Closes arduino#1009
Closes arduino#566

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
@kittaakos
Copy link
Contributor

PR: #1019. Please review. Thank you!

kittaakos pushed a commit that referenced this issue Jun 2, 2022
 - Bumped `clangd` to `14.0.0`,
 - Can use `.clang-format` from:
   - current sketch folder,
   - `~/.arduinoIDE/.clang-format`,
   - `directories#data/.clang-format`, or
   - falls back to default formatter styles.

Closes #1009
Closes #566

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
@ubidefeo
Copy link

ubidefeo commented Jun 6, 2022

LGTM

kittaakos pushed a commit that referenced this issue Jun 7, 2022
 - Bumped `clangd` to `14.0.0`,
 - Can use `.clang-format` from:
   - current sketch folder,
   - `~/.arduinoIDE/.clang-format`,
   - `directories#data/.clang-format`, or
   - falls back to default formatter styles.

Closes #1009
Closes #566

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
kittaakos pushed a commit that referenced this issue Jun 7, 2022
 - Bumped `clangd` to `14.0.0`,
 - Can use `.clang-format` from:
   - current sketch folder,
   - `~/.arduinoIDE/.clang-format`,
   - `directories#data/.clang-format`, or
   - falls back to default formatter styles.

Closes #1009
Closes #566

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
@per1234 per1234 added the conclusion: resolved Issue was resolved label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved criticality: medium Of moderate impact topic: code Related to content of the project itself topic: language server Related to the Arduino Language Server type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants