mapbox / mapbox/XcodeClangFormat

Format On Save with Xcode behaviors.

Đang mở
#57 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Objective-C++
Star
807
Fork
102
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi, in order to allow "Format on Save" I avoid using extensions, but rather set new Xcode behavior hat run the following script upon "Command+S" (which replace the original file save):

My script extract the current file name presented by xcode, and perform clang-format on this file (see below), and it works just fine.

However, when the file is modified, I sometimes get the following message from xcode.

the file for the document at “/Users/me/file.cpp” has been modified by another application. There are also unsaved changes in Xcode. Do you want to keep the Xcode version or revert to the version on disk?

This happens because the file changed outside xcode ... and xcode probably cache the currently file being edited, so I'd like to avoid this message box and always take the newer file version from disk (select the "Revert" option instead of the other option of "Keep Xcode Version") . is it possible to avoid this message box ?

Thanks

#!/bin/sh

CDP=$(osascript -e 'tell application "Xcode"
    activate
    set current_document to last source document
    set current_document_path to path of current_document
end tell ' )

if [[ $CDP == *.cpp ]]
then
    /usr/local/bin/clang-format -i ${CDP}
    touch ${CDP}
fi

P.S I'm aware this option doesn't related directly to the plugin, but if the plugin can somehow run clang-format from within the xcode, it may solve my problem and avoid this messagebox...

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện hành vi của Xcode từ script Command+S của issue, bao gồm các lệnh clang-format -i và touch trên một tệp .cpp. Điều tra xem plugin có thể gọi việc định dạng bên trong Xcode thay vì sửa đổi tệp ở bên ngoài hay không. Được xem là hoàn tất khi việc định dạng diễn ra lúc lưu mà không hiển thị hộp thoại sửa đổi bên ngoài, đồng thời vẫn giữ phiên bản mới hơn trên đĩa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
cpp, shell
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.