This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Support new file formatting with vim
ClosedPublic

Authored by jsji on Nov 17 2022, 1:04 PM.

Details

Summary

The vim Formatonsave integration is not working if we create a new file directly using vim.
eg: vi -V9t.log t.cpp

It will not able to format the buffer.

Traceback (most recent call last):

File "<string>", line 1, in <module>
File "...clang/tools/clang-format/clang-format.py", line 156, in <module>
  main()
File "...clang/tools/clang-format/clang-format.py", line 80, in main
  with open(vim.current.buffer.name, 'r') as f:

FileNotFoundError: [Errno 2] No such file or directory: '...t.cpp'

This patch check the file before we try to open it.

Diff Detail

Event Timeline

jsji created this revision.Nov 17 2022, 1:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 1:04 PM
jsji requested review of this revision.Nov 17 2022, 1:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 1:04 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jsji added a reviewer: Restricted Project.Nov 17 2022, 1:05 PM
jsji edited the summary of this revision. (Show Details)
owenpan edited reviewers, added: MyDeveloperDay, HazardyKnusperkeks, rymiel, owenpan; removed: Restricted Project.Nov 17 2022, 9:24 PM
owenpan added a project: Restricted Project.
owenpan added inline comments.Nov 17 2022, 10:49 PM
clang/tools/clang-format/clang-format.py
49

Can you move it up to keep the module names sorted?

80–81
jsji updated this revision to Diff 476905.Nov 21 2022, 7:55 AM

Address comments.

This revision is now accepted and ready to land.Nov 21 2022, 12:24 PM
This revision was landed with ongoing or failed builds.Nov 21 2022, 1:19 PM
This revision was automatically updated to reflect the committed changes.