Git Product home page Git Product logo

clangformat-xcode's Introduction

I'm a Canadian software maker that's hacked on open source projects like Jocko, Timecop, and Mocha; and built several startups from the ground up, including Segment and Confluent.

I've mostly worked at new startups, working on many problems: distributed systems, infrastructure, back-end, front-end, mobile, tooling. I prefer distributed systems, infrastructure and back-end applied to big data problems.

I authored a book on building distributed systems using Go, published by Pragmatic Bookshelf. The book walks you through building a distributed commit log from scratch, step-by-step, from nothing to deployment.

Find me on the web:

clangformat-xcode's People

Contributors

antons avatar chachi avatar cojoj avatar florianbuerger avatar gwynjudd avatar juhagman avatar kuglee avatar mahboud avatar masonmark avatar mkl-ableton avatar neonichu avatar ni0ki avatar prestonj avatar skomik avatar tonyarnold avatar travisjeffery avatar v01dzer0 avatar yeahphil avatar yixiang avatar zizicici avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clangformat-xcode's Issues

Xcode 5.02 and Xcode 5.1 beta5

It appears that a fresh install of the plugin causes Xcode to crash on launch with the following report:

Process: Xcode [2781]
Path: /Applications/Xcode51-Beta5.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 5.1 (5076)
Build Info: IDEFrameworks-5076000000000000~17
Code Type: X86-64 (Native)
Parent Process: launchd [383]
User ID: 506

Date/Time: 2014-03-07 11:29:21.380 +0000
OS Version: Mac OS X 10.8.5 (12F45)
Report Version: 10

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000018

VM Regions Near 0x18:
-->
__TEXT 0000000103fba000-0000000103fbb000 [ 4K] r-x/rwx SM=COW /Applications/Xcode51-Beta5.app/Contents/MacOS/Xcode

Application Specific Information:
ProductBuildVersion: 5B103i

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff91b6b498 objc_msgSend_vtable3 + 24
1 com.apple.Foundation 0x00007fff933ae2e7 -[NSBundle loadAndReturnError:] + 646
2 com.apple.Foundation 0x00007fff933ae05c -[NSBundle load] + 19
3 com.apple.Xcode.DevToolsCore 0x000000010a8e8ec0 -[XCPluginManager loadPluginBundle:] + 479
4 com.apple.Xcode.DevToolsCore 0x000000010a8e88c7 -[XCPluginManager findAndLoadPluginsInDomain:] + 4302
5 com.apple.Xcode.DevToolsCore 0x000000010a8abce8 XCInitializeCoreIfNeeded + 4247
6 com.apple.dt.IDE.Xcode3Core 0x000000010a76b260 +[Xcode3CoreInitializer ide_initializeWithOptions:error:] + 16
7 com.apple.dt.IDEFoundation 0x0000000104b6a6f9 _IDEInitializeOnePlugInAndPrerequisites + 1359
8 com.apple.dt.IDEFoundation 0x0000000104b69dd6 _IDEInitializePlugIns + 980
9 com.apple.dt.IDEFoundation 0x0000000104b698c5 __IDEInitialize_block_invoke + 42
10 com.apple.dt.IDEFoundation 0x0000000104b69fe0 IDESetSafeToLoadMobileDevice + 203
11 com.apple.dt.IDEKit 0x00000001050f3844 -[IDEWelcomeWindowController _showFirstLaunchExperienceIfAppropriate] + 316
12 com.apple.dt.IDEKit 0x00000001050f36eb -[IDEWelcomeWindowController openWelcomeWindowAfterFirstLaunchExperienceIfAppropriate:] + 29
13 com.apple.dt.IDEKit 0x00000001050f3617 -[IDEApplicationController applicationOpenUntitledFile:] + 230
14 com.apple.AppKit 0x00007fff8fc97c34 -[NSApplication _doOpenUntitled] + 482
15 com.apple.AppKit 0x00007fff8fc976cf __58-[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:]_block_invoke_0 + 233
16 com.apple.AppKit 0x00007fff8ffd96c1 __78-[NSDocumentController(NSInternal) _autoreopenDocumentsWithCompletionHandler:]_block_invoke_01437 + 143
17 com.apple.AppKit 0x00007fff8fc9717b -[NSDocumentController(NSInternal) _autoreopenDocumentsWithCompletionHandler:] + 760
18 com.apple.AppKit 0x00007fff8fc9566e -[NSApplication reopenWindowsAsNecessaryIncludingRestorableState:registeringAsReady:completionHandler:] + 298
19 com.apple.AppKit 0x00007fff8fc95445 -[NSApplication(NSAppleEventHandling) handleAEOpenEvent:] + 553
20 com.apple.AppKit 0x00007fff8fc9504c -[NSApplication(NSAppleEventHandling) handleCoreEvent:withReplyEvent:] + 351
21 com.apple.Foundation 0x00007fff9339c05b -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
22 com.apple.Foundation 0x00007fff9339bebd NSAppleEventManagerGenericHandler + 106
23 com.apple.AE 0x00007fff91d80078 aeDispatchAppleEvent(AEDesc const
, AEDesc
, unsigned int, unsigned char
) + 307
24 com.apple.AE 0x00007fff91d7fed9 dispatchEventAndSendReply(AEDesc const
, AEDesc*) + 37
25 com.apple.AE 0x00007fff91d7fd99 aeProcessAppleEvent + 318
26 com.apple.HIToolbox 0x00007fff8e2af709 AEProcessAppleEvent + 100
27 com.apple.AppKit 0x00007fff8fc91836 _DPSNextEvent + 1456
28 com.apple.AppKit 0x00007fff8fc90df2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
29 com.apple.dt.DVTKit 0x00000001046b30f1 -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 84
30 com.apple.AppKit 0x00007fff8fc881a3 -[NSApplication run] + 517
31 com.apple.AppKit 0x00007fff8fc2cbd6 NSApplicationMain + 869
32 libdyld.dylib 0x00007fff9198d7e1 start + 1

Thread 1:: Dispatch queue: com.apple.root.default-priority
0 libsystem_kernel.dylib 0x00007fff92da5ffa read + 10
1 com.apple.CoreFoundation 0x00007fff8a781410 CFReadBytesFromPathAndGetFD + 480
2 com.apple.CoreFoundation 0x00007fff8a6bbcc8 CFReadBytesFromFile + 136
3 com.apple.CoreFoundation 0x00007fff8a6ba8aa CFURLCreateDataAndPropertiesFromResource + 314
4 com.apple.CoreFoundation 0x00007fff8a6b79e7 CFBundleCopyInfoDictionaryInDirectoryWithVersion + 1303
5 com.apple.CoreFoundation 0x00007fff8a6d3299 CFBundleCreate + 889
6 com.apple.audio.CoreAudio 0x00007fff91fb0ce3 HALC_ShellDriverPlugIn::Open(CFString const) + 197
7 com.apple.audio.CoreAudio 0x00007fff91fb0512 HALC_ShellDevice::InitializeDriverPlugIn() + 382
8 com.apple.audio.CoreAudio 0x00007fff91fb024d HALC_ShellDevice::HasProperty(unsigned int, AudioObjectPropertyAddress const&, bool&, unsigned int&, AudioObjectPropertyAddress&, bool&) const + 87
9 com.apple.audio.CoreAudio 0x00007fff91fb01e3 HasProperty_block_invoke_0 + 77
10 com.apple.audio.CoreAudio 0x00007fff91fa9073 HALB_CommandGate::ExecuteCommand(void ()() block_pointer) const + 33
11 com.apple.audio.CoreAudio 0x00007fff91fb004c HALC_ShellDevice::HasProperty(unsigned int, AudioObjectPropertyAddress const&, bool&) const + 400
12 com.apple.audio.CoreAudio 0x00007fff91fafea2 HAL_HardwarePlugIn_ObjectHasProperty(AudioHardwarePlugInInterface
, unsigned int, AudioObjectPropertyAddress const
) + 94
13 com.apple.audio.CoreAudio 0x00007fff91fafdc4 HALPlugIn::ObjectHasProperty(HALObject const&, AudioObjectPropertyAddress const&) const + 36
14 com.apple.audio.CoreAudio 0x00007fff91f9d0c1 HALObject::HasProperty(AudioObjectPropertyAddress const&) const + 77
15 com.apple.audio.CoreAudio 0x00007fff91fafd76 HALDevice::HasProperty(AudioObjectPropertyAddress const&) const + 620
16 com.apple.audio.CoreAudio 0x00007fff91fafac6 HALDevice::IsHidden(bool
) const + 80
17 com.apple.audio.CoreAudio 0x00007fff91faeab0 HALSystem::ObjectsPublishedAndDied(unsigned int, unsigned int const
, unsigned int, unsigned int const
) + 688
18 com.apple.audio.CoreAudio 0x00007fff91fa79c3 HALSystem::AudioObjectsPublishedAndDied(AudioHardwarePlugInInterface
, unsigned int, unsigned int, unsigned int const
, unsigned int, unsigned int const_) + 387
19 com.apple.audio.CoreAudio 0x00007fff91fa4578 HALC_ShellPlugIn::ReconcileDeviceList(bool, bool) + 3670
20 com.apple.audio.CoreAudio 0x00007fff91f9e06b HALC_ShellPlugIn::ConnectToServer() + 231
21 com.apple.audio.CoreAudio 0x00007fff91f9c195 HAL_HardwarePlugIn_InitializeWithObjectID(AudioHardwarePlugInInterface
_, unsigned int) + 132
22 com.apple.audio.CoreAudio 0x00007fff91f9b122 HALPlugInManagement::CreateHALPlugIn(HALCFPlugIn const_) + 1512
23 com.apple.audio.CoreAudio 0x00007fff91f99cba HALPlugInManagement::Initialize() + 312
24 com.apple.audio.CoreAudio 0x00007fff91f99b75 HALSystem::InitializeDevices() + 9
25 com.apple.audio.CoreAudio 0x00007fff91f9758e HALSystem::CheckOutInstance() + 146
26 com.apple.audio.CoreAudio 0x00007fff91fbe050 AudioObjectAddPropertyListenerInternal + 226
27 com.apple.audio.units.Components 0x000000010bf93efd AUHAL::AUHAL(ComponentInstanceRecord_, unsigned int, bool) + 699
28 com.apple.audio.units.Components 0x000000010bfb5ded ComponentEntryPoint::Dispatch(ComponentParameters_, DefaultOutputAU*) + 107
29 com.apple.CoreServices.CarbonCore 0x00007fff88686fd2 CallComponentOpen + 46
30 com.apple.CoreServices.CarbonCore 0x00007fff88613cef OpenAComponent + 395
31 com.apple.CoreServices.CarbonCore 0x00007fff88613b5a OpenComponent + 17
32 com.apple.AppKit 0x00007fff9014328d _initializeCA + 994
33 com.apple.AppKit 0x00007fff90142e46 -[NSSound _postInitialization] + 390
34 com.apple.AppKit 0x00007fff90144252 -[NSSound initWithContentsOfURL:byReference:] + 252
35 com.apple.dt.IDE.IDEInterfaceBuilderCocoaIntegration 0x000000010f19925c __21-[IBCocoaPlugin init]_block_invoke + 53
36 libdispatch.dylib 0x00007fff92b7ef01 _dispatch_call_block_and_release + 15
37 libdispatch.dylib 0x00007fff92b7b0b6 _dispatch_client_callout + 8
38 libdispatch.dylib 0x00007fff92b7c1fa _dispatch_worker_thread2 + 304
39 libsystem_c.dylib 0x00007fff88fc3cdb _pthread_wqthread + 404
40 libsystem_c.dylib 0x00007fff88fae191 start_wqthread + 13

Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x00007fff92da5d16 kevent + 10
1 libdispatch.dylib 0x00007fff92b7ddea _dispatch_mgr_invoke + 883
2 libdispatch.dylib 0x00007fff92b7d9ee _dispatch_mgr_thread + 54

...

External Modification Summary:
Calls made by other processes targeting this process:
task_for_pid: 2
thread_create: 0
thread_set_state: 0
Calls made by this process:
task_for_pid: 0
thread_create: 0
thread_set_state: 0
Calls made by all processes on this machine:
task_for_pid: 789
thread_create: 0
thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=293.8M resident=148.2M(50%) swapped_out_or_unallocated=145.6M(50%)
Writable regions: Total=1.2G written=34.3M(3%) resident=57.1M(5%) swapped_out=40K(0%) unallocated=1.1G(95%)

REGION TYPE VIRTUAL
=========== =======
CG backing stores 536K
CG image 4K
CG shared images 1216K
CoreServices 2292K
JS JIT generated code 8K
JS JIT generated code (reserved) 1.0G reserved VM address space (unallocated)
MALLOC 130.0M
MALLOC guard page 48K
Memory tag=240 4K
Memory tag=242 12K
Memory tag=249 156K
Memory tag=251 44K
SQLite page cache 2688K
STACK GUARD 56.0M
Stack 12.1M
VM_ALLOCATE 16.2M
__DATA 30.9M
__IMAGE 528K
__LINKEDIT 71.1M
__TEXT 222.8M
__UNICODE 544K
mapped file 45.4M
shared memory 308K
=========== =======
TOTAL 1.6G
TOTAL, minus reserved VM space 592.7M

Let me know if you would like a full log (too large to paste in)

Add License

I'm not sure if I can use this project as there's no specific license stated.

Here's a list of open source licenses to choose from:
http://opensource.org/licenses

For re-use in commercial software MIT, BSD 2-clause, or Apache licenses are preferred, but it's your project 😄

Invalid boolean for attribute that takes enum

YAML:11:35: error: invalid boolean
AllowShortFunctionsOnASingleLine: Inline
^~~~~~

According to
http://clang.llvm.org/docs/ClangFormatStyleOptions.html#clang-format-style-options
AllowShortFunctionsOnASingleLine is defined as:

AllowShortFunctionsOnASingleLine (ShortFunctionStyle)
Dependent on the value, int f() { return 0; } can be put on a single line.

Possible values:

SFS_None (in configuration: None) Never merge functions into a single line.
SFS_Inline (in configuration: Inline) Only merge functions defined inside a class.
SFS_All (in configuration: All) Merge all functions fitting on a single line.

Seems to be some change in format maybe. Clang error says bool, but documentation says its an enum. Can't seem to find changelog, but might be the case the clang format binary has been updated?

Notify user if provided .clang-format is rejected

If clang-format is unable to parse the .clang-format file it falls back to the LLVM style. On the command line this is obvious to the user as a helpful error message like the following is printed:

YAML:20:23: error: unknown enumerated scalar
NamespaceIndentation: Never
                      ^~~~~

Users of ClangFormat-Xcode don't get to see this message. They just notice that their code is formatted in a weird way without any indication why this happend.

ClangFormat-Xcode should present the user with the error message so that the user can fix the .clang-format file.

Xcode 6 GM support

Looks like Xcode 6 GM has a new DVTPlugInCompatibilityUUID: C4A681B0-4A26-480E-93EC-1218098B9AA0

Crashes on single-line conditionals without braces

No crash

if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) {
    return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  }

Crash

if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)])
    return [UIFont preferredFontForTextStyle:UIFontTextStyleBody];

HotKey/KeyCombination

How about hotkey or key combination for formatting selected text or entire file?
Would be so good! Unfortunatelly, I don't know how to develop it =/

Can't find usable .clang-format

I put the following .clang-format file in both the project root directory and parent of that folder too.

BasedOnStyle: LLVM

When I try to format, I get the error: Can't find usable .clang-format, using LLVM style.

Using XCode 6.1.1 and latest ClangFormat from Alcatraz.

No format in blocks

[sendOperation start:^(NSError* error) {
if(error) {//this code won't be formatted on save
} else {
}
}];

build fails if Xcode is not /Applications/Xcode.app

The build assumes /Applications/Xcode.app to link against IDE framework(s), which is usually true but not always--Xcode.app is completely self-contained so it works fine if it's renamed or in another location.

You can get the path to the currently running Xcode through various build environment variables.

Thanks for making this very nice plugin!

Exclude Files from 'Format on Save'

As a feature request:

It would be nice to be able to define a list of excluded file extensions for Format on Save. Editing a raw .plist or a podfile is a pain with the Format on Save enabled. Otherwise the Format on Save does a great job but I tend to forget about when quickly making changes in raw files.

Or a whitelist? Just parse .h/.m/.c files when using Format on Save?

Cheers,
Frederik

ClangFormat incorrectly splits Objective-C string literals

I cloned and pulled the latest release of ClangFormat, which still exhibits this bug.
An NSArray literal containing NSString literals before running ClangFormat:

  NSArray *testInputStrings = @[
    @"abcdefg",
    @"*^&I*BEI*BDI C# RG#RC#YJGR #",
    @"那隻敏捷的棕色狐狸跳線懶狗。",
    @"1",
    @"12",
    @"123",
    @"1234",
    @"12345",
    @"123456",
    @"1234567",
    @"12345678",
    @"123456789",
    @"1234567890",
 @"kljsadgflkuyaerkuqhfbdsalkfbalkshdeklahdskjbfaskljhraslkrhuwbdbhsCKJhbasjkhfawkjhgrkjaebfdjkahsbdfjkhawkjfegkqrwjygr3uy24764587321rgj32hvr4jkh2vrkj2vfqrfqwjkh*&^*^&*RIBIEBKHBDJHABJEHBjqdbwjy3egjwybdehjbdfjsdhbfjsehbfjhsbfsjhbfdjshbfsmdbfshfbejw3jbfdsmhbdmshbfs"
  ];

The same NSArray literal after running ClangFormat:

  NSArray *testInputStrings = @[
    @"abcdefg",
    @"*^&I*BEI*BDI C# RG#RC#YJGR #",
    @"那隻敏捷的棕色狐狸跳線懶狗。",
    @"1",
    @"12",
    @"123",
    @"1234",
    @"12345",
    @"123456",
    @"1234567",
    @"12345678",
    @"123456789",
    @"1234567890",
    @"kljsadgflkuyaerkuqhfbdsalkfbalkshdeklahdskjbfaskljhraslkrhuwbdbhsCKJhbasj"
    @"khfawkjhgrkjaebfdjkahsbdfjkhawkjfegkqrwjygr3uy24764587321rgj32hvr4jkh2vr"
    @"kj2vfqrfqwjkh*&^*^&*"
    @"RIBIEBKHBDJHABJEHBjqdbwjy3egjwybdehjbdfjsdhbfjsehbfjhsbfsjhbfdjshbfsmdbf"
    @"shfbejw3jbfdsmhbdmshbfs"
  ];

Allow the user to manually specify the .clang-format file to use.

This can lead to a lot of confusion, right now I don't even have a .clang_format file in my project, and if I choose Edit > Clang Format > File and then apply clang format to my file, it's still getting formatted somehow.

I don't have the minor idea of what file is Clang Format using to do this, so a way to manually specifying a File would be fantastic.

Where should I put .clang-format?

I have used ./clang-format -style=llvm -dump-config > .clang-format to extract a config file and made some modifications, then I have tried to put the .clang-format file in ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ClangFormat.xcplugin/Contents/Resources and XCode project root directry, but it seems take no effect.

Where should I put the config file?

format file with non-ascii characters

Formatting files with non-ascii characters doesn't work.
It's easier to show than describe whats wrong.
input file:

#import "Example.h"
// ń
@implementation Example
-(void) doSomethingWithString:(NSString*) string{
}
@end

expected result with WebKit style

#import "Example.h"
// ń
@implementation Example
- (void)doSomethingWithString:(NSString*)string
{
}
@end

actual result

#import "Example.h"
// ń
@implementation Example
-( void) oSomethingWithString:(NSString*) tring{

}
@end

when i remove ń letter from comment everything works as expected.
Formatting this file with command line clang-fomat works.

How to align colons

How can we ask the formatter to align the colons vertically for the method calls with multiple parameters, just like the Xcode "re-indent" function does?

Thanks in advance.

Crashing...not sure why

Was working flawlessly. Feel like it goofed on one save and now has had problems ever since.

  Thread 0x3885     DispatchQueue 1          priority 47         cpu time   0.009s
  10 start + 1 (libdyld.dylib) [0x7fff86dc35fd]
    10 NSApplicationMain + 940 (AppKit) [0x7fff8c5cf783]
      10 -[NSApplication run] + 646 (AppKit) [0x7fff8c5e49f9]
        10 -[IDEApplication sendEvent:] + 456 (IDEKit) [0x104140600]
          10 -[NSApplication sendEvent:] + 3293 (AppKit) [0x7fff8c794acc]
            10 -[NSApplication _handleKeyEquivalent:] + 822 (AppKit) [0x7fff8c8258e1]
              10 -[NSMenu performKeyEquivalent:] + 289 (AppKit) [0x7fff8c82907c]
                10 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117 (AppKit) [0x7fff8c829f04]
                  10 -[NSMenuItem _corePerformAction] + 394 (AppKit) [0x7fff8c82a1c8]
                    10 -[DVTApplication sendAction:to:from:] + 377 (DVTKit) [0x1035c6b38]
                      10 __37-[DVTApplication sendAction:to:from:]_block_invoke + 352 (DVTKit) [0x1036f8f85]
                        10 -[NSApplication sendAction:to:from:] + 327 (AppKit) [0x7fff8c80f260]
                          10 -[IDEEditorDocument saveDocument:] + 682 (IDEKit) [0x1041fdb4b]
                            10 -[IDEEditorDocument _unlockIfNeededCompletionBlock:] + 622 (IDEKit) [0x1041fa2ca]
                              10 __34-[IDEEditorDocument saveDocument:]_block_invoke + 56 (IDEKit) [0x1043ae488]
                                10 -[NSDocument(TRVSClangFormat) trvs_saveDocumentWithDelegate:didSaveSelector:contextInfo:] + 165 (ClangFormat) [0x109426be5]
                                  10 -[TRVSFormatter formatDocument:] + 527 (ClangFormat) [0x109424d1f]
                                    10 -[TRVSFormatter formatRanges:inDocument:] + 245 (ClangFormat) [0x1094250e5]
                                      10 -[TRVSFormatter fragmentsOfContinuousLineRanges:usingTextStorage:withDocument:] + 389 (ClangFormat) [0x109425b85]
                                        10 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 319 (CoreFoundation) [0x7fff8b186a9f]
                                          10 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 137 (CoreFoundation) [0x7fff8b1872f9]
                                            10 __79-[TRVSFormatter fragmentsOfContinuousLineRanges:usingTextStorage:withDocument:]_block_invoke + 719 (ClangFormat) [0x109425f2f]
                                              10 -[TRVSCodeFragment formatWithStyle:usingClangFormatAtLaunchPath:] + 783 (ClangFormat) [0x109423e6f]
                                                10 -[NSConcreteTask waitUntilExit] + 205 (Foundation) [0x7fff868867f8]
                                                  10 CFRunLoopRunSpecific + 309 (CoreFoundation) [0x7fff8b174e75]
                                                    10 __CFRunLoopRun + 1161 (CoreFoundation) [0x7fff8b175539]
                                                      10 __CFRunLoopServiceMachPort + 181 (CoreFoundation) [0x7fff8b175f15]
                                                        10 mach_msg_trap + 10 (libsystem_kernel.dylib) [0x7fff90bd6a1a]
                                                         *10 ipc_mqueue_receive_continue + 0 (mach_kernel) [0xffffff80002167d0]

Bundled clang-format issue with long Objecttive-C lines

I'm using a custom clang_format equivalent to -style="{BasedOnStyle: google, ContinuationIndentWidth: 4, ColumnLimit: 100, DerivePointerAlignment: false, PointerAlignment: Right, UseTab: Never}"

Using ClangFormat-Xcode with the bundled clang-format turns

-(BOOL)reallyLongFunctionName012345678901234567890123456789012345678:(ReallyLongTypeName012345678901234 *)vc{return NO;}

into

- (BOOL)reallyLongFunctionName012345678901234567890123456789012345678:
        (ReallyLongTypeName012345678901234 *)vc{
    return NO;
}

(there's an 4 extra spaces in front of (ReallyLongTypeName012345678901234 *)) Using the system version of clang-format (version 3.7.0) installed from homebrew does the right spacing:

echo "-(BOOL)reallyLongFunctionName012345678901234567890123456789012345678:(ReallyLongTypeName012345678901234 *)vc{return NO;}" | clang-format -style="{BasedOnStyle: google, ContinuationIndentWidth: 4, ColumnLimit: 100, DerivePointerAlignment: false, PointerAlignment: Right, UseTab: Never}"

returns

- (BOOL)reallyLongFunctionName012345678901234567890123456789012345678:
    (ReallyLongTypeName012345678901234 *)vc {
  return NO;
}

Which format used on example ?

Which clang format has been used on main example?

 - (NSArray *)returnImages {
   return @[@"First", @"Second", @"Hello", @"Jello1" ];
 }

Haven't translated to

- (NSArray *)returnImages
{
  return @[
           @"First",
           @"Last",
           @"Hello",
           @"Jello1"
           ];
}

clangformat-xcode-demo

Xcode scrolling on format.

For those of us who use format on save, the fact that Xcode will scroll around the file when we save is a big distraction and problem. Don't know much about Xcode plugins, but could there be a conceivable way of preventing Xcode from scrolling around to a random place in the code when formatting? Or at least a hack-ish way where Xcode scrolls back to where your viewport was before it scrolled?

Format on save does not format when building

If you modify a file then build the project (⌘B) without saving, Xcode will save the file by itself.
In this case you end up with files that appear modified on your SCM, but that have not been formatted.

I don't know if this should be added as a new option or integrated in the same feature, but it would be nice to be able to do this.

swift support?

Is there any plan to support swift source code formating?

Wrong formatting with @weakify and @strongify

// Result
@weakify(self)
    NSUInteger index = [self.array indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL* stop) {
    @strongify(self)
    // TODO:
    return *stop;
    }];

// Expected result
@weakify(self)
NSUInteger index = [self.array indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL* stop) {
    @strongify(self)
    // TODO:
    return *stop;
}];

The Info.plist should specify a principal class (TRVSClangFormat).

The ClangFormat-Info.plist file should specify the principal class as TRVSClangFormat. This would help people who fork it to hack on it to avoid the case that Xcode seemingly-randomly silently fails to load the plug-in.

If the principal class is not specified, then the plug-in bundle load process will just use whatever class it first encounters as the principal class. But if somebody working on a fork adds a new class to the project in the usual way within Xcode, it has a high chance of being added to the Compile Sources build phase before the TRVSClangFormat class.

If that happens, then the plugin will build fine, but Xcode will just silently fail to load it (because whatever class was selected as the principal class does not implement the required plug-in interface).

In the Xcode build settings editor for the target "ClangFormat", in the Info tab, the plist contents are shown in human-readable form. Using this editor, you can add a value to the list for "Principal class" and set it to "TRVSClangFormat".

This will have the effect of adding the following to the ClangFormat-Info.plist file (and hence the built bundle's Info.plist file):

<key>NSPrincipalClass</key>
<string>TRVSClangFormat</string>

Once that is done, forkers can add classes to the project willy-nilly, without affecting the Xcode plugin load process.

where is the clang-format binary located?

I can't find it anywhere on my system, therefore I am unable generate and customise the standard .clang-format format file. I'm running Xcode 6.1, os x 10.9.4 and have Alcatraz and the ClangFormat plugin installed.

Errors when using AllowShortFunctionsOnASingleLine

Getting some errors trying to use the new options:

AllowShortFunctionsOnASingleLine: SFS_None

screen shot 2014-07-18 at 12 52 16

AllowShortFunctionsOnASingleLine (ShortFunctionStyle)
Dependent on the value, int f() { return 0; } can be put on a single line.

Possible values:

SFS_None (in configuration: None) Never merge functions into a single line.
SFS_Inline (in configuration: Inline) Only merge functions defined inside a class.
SFS_All (in configuration: All) Merge all functions fitting on a single line.

Build fails with "ld: Linked dylibs built for GC-only but object files built for retain/release for architecture x86_64" error

I am trying to build the plugin on my machine but I'm stuck with a link error:

ld: Linked dylibs built for GC-only but object files built for retain/release for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't know wich library is GC-Only (I guess this is one of the Xcode frameworks to which the plugin is linked but I am not sure).

My environment:
OS X Mavericks (10.9.1)
Xcode 5.0.2

"Use System ClangFormat" crashes Xcode

I'm using the clang-format that comes bundled with LLVM 3.4.1.
Here's the code that leads to the crash.

Edit: Just to be clear. Any code leads to a crash. The code below is just the smallest example I could think of to reproduce the error.

// Foo.h
class Foo {
public:
void foo();
};

xCode Key Bindings

How to add key bindings for Clang Format? For example i wanna bind "Format Selected Text" on Shift-Cmd-F. How to achieve that?
Thanks!

Occasional crash on save with all text selected

I've had a second crash now using this plugin when I've had all the text in my current file selected (⌘A) and I've saved my Objective-C implementation file (⌘S). It doesn't happen every time, but it definitely happens sometimes. And I'm using Format on Save, with a custom local format file. I'll post more information here as I get it.

Here's the relevant bit from the top of my crash log. I think I can see roughly where in the backtrace it's happening.

Process:         Xcode [86062]
Path:            /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier:      com.apple.dt.Xcode
Version:         5.0.2 (3335.32)
Build Info:      IDEApplication-3335032000000000~4
App Item ID:     497799835
App External ID: 106632651
Code Type:       X86-64 (Native)
Parent Process:  launchd [281]
Responsible:     Xcode [86062]
User ID:         501

PlugIn Path:       /Users/USER/Library/Application Support/Developer/*/ClangFormat
PlugIn Identifier: com.travisjeffery.ClangFormat
PlugIn Version:    1.0 (1)

Date/Time:       2014-01-17 11:51:17.388 -0600
OS Version:      Mac OS X 10.9.1 (13B3116)
Report Version:  11
Anonymous UUID:  C2C45827-B501-3F46-1486-D5BE4E0284EA

Sleep/Wake UUID: 3A28DA5D-A700-4708-BA5F-39E6D47A50C3

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
ProductBuildVersion: 5A3005
ASSERTION FAILURE in /SourceCache/DVTKit/DVTKit-3553/Framework/Classes/TextCompletion/DVTCompletingTextView.m:1335
Details:  Attempt to select an invalid range of text: {18446744073709551610, 0}. Text length: 2026. (Please file a Radar. OK to Continue from here.)
Object:   <DVTSourceTextView: 0x7ff9178a8810>
Method:   -setSelectedRange:
Thread:   <NSThread: 0x7ff910e15130>{name = (null), num = 1}
Hints:   None
Backtrace:
  0  0x0000000108ed8ea8 -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
  1  0x0000000107c677a5 _DVTAssertionHandler (in DVTFoundation)
  2  0x0000000107c67ad4 _DVTAssertionFailureHandler (in DVTFoundation)
  3  0x000000010818f1df -[DVTCompletingTextView setSelectedRange:] (in DVTKit)
  4  0x00000001081b86a4 -[DVTSourceTextView setSelectedRange:] (in DVTKit)
  5  0x00007fff9348b07b _NSSetRangeValueAndNotify (in Foundation)
  6  0x00000001103b343e -[TRVSFormatter formatDocument:] at /Users/ben/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/ClangFormat/TRVSFormatter.m:76 (in ClangFormat)
  7  0x00000001103b4313 -[NSDocument(TRVSClangFormat) trvs_saveDocumentWithDelegate:didSaveSelector:contextInfo:] at /Users/ben/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/ClangFormat/NSDocument+TRVSClangFormat.m:18 (in ClangFormat)
  8  0x0000000108f0a90b __34-[IDEEditorDocument saveDocument:]_block_invoke (in IDEKit)
  9  0x0000000108d94494 -[IDEEditorDocument _unlockIfNeededCompletionBlock:] (in IDEKit)
 10  0x0000000108d97c3c -[IDEEditorDocument saveDocument:] (in IDEKit)
 11  0x00007fff9007d3d0 -[NSApplication sendAction:to:from:] (in AppKit)
 12  0x0000000108348aff __37-[DVTApplication sendAction:to:from:]_block_invoke (in DVTKit)
 13  0x000000010817a544 -[DVTApplication sendAction:to:from:] (in DVTKit)
 14  0x00007fff90098348 -[NSMenuItem _corePerformAction] (in AppKit)
 15  0x00007fff90098084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] (in AppKit)
 16  0x00007fff900971fc -[NSMenu performKeyEquivalent:] (in AppKit)
 17  0x00007fff90093a61 -[NSApplication _handleKeyEquivalent:] (in AppKit)
 18  0x00007fff90002c3c -[NSApplication sendEvent:] (in AppKit)
 19  0x0000000108cdb83b -[IDEApplication sendEvent:] (in IDEKit)
 20  0x00007fff8fe52a29 -[NSApplication run] (in AppKit)
 21  0x00007fff8fe3d803 NSApplicationMain (in AppKit)
 22  0x00007fff975945fd start (in libdyld.dylib)
 23  0x0000000000000001

Performing @selector(ide_saveDocument:) from sender NSMenuItem 0x7ff913550e90
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff8c236866 __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff8c15035c pthread_kill + 92
2   libsystem_c.dylib               0x00007fff9540dbba abort + 125
3   com.apple.dt.IDEKit             0x0000000108ed87af +[IDEAssertionHandler _handleAssertionWithLogString:reason:] + 775
4   com.apple.dt.IDEKit             0x0000000108ed900e -[IDEAssertionHandler handleFailureInMethod:object:fileName:lineNumber:messageFormat:arguments:] + 1117
5   com.apple.dt.DVTFoundation      0x0000000107c677a5 _DVTAssertionHandler + 421
6   com.apple.dt.DVTFoundation      0x0000000107c67ad4 _DVTAssertionFailureHandler + 322
7   com.apple.dt.DVTKit             0x000000010818f1df -[DVTCompletingTextView setSelectedRange:] + 181
8   com.apple.dt.DVTKit             0x00000001081b86a4 -[DVTSourceTextView setSelectedRange:] + 52
9   com.apple.Foundation            0x00007fff9348b07b _NSSetRangeValueAndNotify + 277
10  com.travisjeffery.ClangFormat   0x00000001103b343e -[TRVSFormatter formatDocument:] + 463 (TRVSFormatter.m:92)
11  com.travisjeffery.ClangFormat   0x00000001103b4313 -[NSDocument(TRVSClangFormat) trvs_saveDocumentWithDelegate:didSaveSelector:contextInfo:] + 107 (NSDocument+TRVSClangFormat.m:22)
12  com.apple.dt.IDEKit             0x0000000108f0a90b __34-[IDEEditorDocument saveDocument:]_block_invoke + 56
13  com.apple.dt.IDEKit             0x0000000108d94494 -[IDEEditorDocument _unlockIfNeededCompletionBlock:] + 638
14  com.apple.dt.IDEKit             0x0000000108d97c3c -[IDEEditorDocument saveDocument:] + 674
15  com.apple.AppKit                0x00007fff9007d3d0 -[NSApplication sendAction:to:from:] + 327
16  com.apple.dt.DVTKit             0x0000000108348aff __37-[DVTApplication sendAction:to:from:]_block_invoke + 351
17  com.apple.dt.DVTKit             0x000000010817a544 -[DVTApplication sendAction:to:from:] + 226
18  com.apple.AppKit                0x00007fff90098348 -[NSMenuItem _corePerformAction] + 394
19  com.apple.AppKit                0x00007fff90098084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
20  com.apple.AppKit                0x00007fff900971fc -[NSMenu performKeyEquivalent:] + 289
21  com.apple.AppKit                0x00007fff90093a61 -[NSApplication _handleKeyEquivalent:] + 822
22  com.apple.AppKit                0x00007fff90002c3c -[NSApplication sendEvent:] + 3293
23  com.apple.dt.IDEKit             0x0000000108cdb83b -[IDEApplication sendEvent:] + 444
24  com.apple.AppKit                0x00007fff8fe52a29 -[NSApplication run] + 646
25  com.apple.AppKit                0x00007fff8fe3d803 NSApplicationMain + 940
26  libdyld.dylib                   0x00007fff975945fd start + 1

Here's my .clang-format file for reference.

AccessModifierOffset: 1
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
BinPackParameters: false
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentCaseLabels: true
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 1
ObjCSpaceBeforeProtocolList: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
Standard: Cpp11
TabWidth: 4
UseTab: Never

global .clang-format.cfg

Hi, great plugin, thanks for your contribution.

Apologies for abusing the issues system, as this may not be an issue with your plugin.

Is there a way (or can you add) to use a global .clang-format file (i.e. in user home directory) instead of the user having to copy the .clang-format into each of many projects he may be working on?

Thanks.

Clang format > File does not support key BinPackArguments

YAML:10:19: error: unknown key 'BinPackArguments'
BinPackArguments: true
^~~~
Error reading /Users/ajgopala/workplace/SpaceNeedle4/src/SpaceNeedleCubeTree/_clang-format: Invalid argument
Can't find usable .clang-format, using LLVM style

"One liner"

Hi Travis,

is there any way to configure, that this sequence

[request setValue:_authentication forHTTPHeaderField:@"Authorization"];

appears as shown above after WebKit formatting? I can only achieve this:

[request setValue:_authentication
    forHTTPHeaderField:@"Authorization"];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.