benoitsan / bbuncrustifyplugin-xcode Goto Github PK
View Code? Open in Web Editor NEWXcode plugin to format source code using ClangFormat or Uncrustify
License: MIT License
Xcode plugin to format source code using ClangFormat or Uncrustify
License: MIT License
Nothing happens when I try to open the BBUncrustifyPlugin Pref window using the appropriate xcode menu. The following in the console line appears in the console:
9/23/14 8:03:06.125 PM Xcode[69435]: -[XCFPreferencesWindowController loadWindow]: failed to load window nib file '(null)'.
I have tried to remove and reinstall, but no luck. This used to work just fine in the various Xcode beta.
Thx
I hope the config file for all user, not per user! So I hope it is not in ~
.
and
I hope the config file can be under a dir, for example : ~/.uncrustify/
.
Because I use git to update my config file, it will bad for git if the config file in root of user path.
Hi,
I've noticed that
#define WEAK_VAR(name)
__unsafe_unretained typeof(self) w##name = name
is turned into
#define WEAK_VAR(name)
__unsafe_unretained typeof(self) w ## name = name
in an ObjC header file.
When you run the command Edit->Uncrustify Active File in XCode all file breakpoints are removed (not so for e.g. exception breakpoints, however). They should of course stay.
Finally finished working on my fork which is compatible with Xcode 3 (3.2.6). Maybe you can add a link to my fork for those who are still using Xcode 3.
While I was porting, I noticed a couple of things:
BBUncrustify.m
+ (NSString *)uncrustifyCodeFragment:(NSString *)codeFragment options:(NSDictionary *)options
There is no Release build, only Debug build. Why? If you add a Release build, you could wrap NSLog(@"uncrustify configuration file: %@", configurationFileURL); that is included in the above method inside a preprocessor DEBUG for no logging for a Release build.
BBXcode.m
+ (BOOL)uncrustifyCodeOfDocument:(PBXSourceFileDocument *)document inWorkspace:(IDEWorkspace *)workspace
There is no [textStorage beginEditing] and corresponding [textStorage endEditing] included in above method. Basically to improve performance, you could make sure that [textStorage replaceCharactersInRange:NSMakeRange(0, textStorage.string.length) withString:uncrustifiedCode withUndoManager:[document undoManager]] & [BBXcode normalizeCodeAtRange:NSMakeRange(0, textStorage.string.length) document:document] are included within the beginEditing & endEditing calls.
I also stumbled on something strange, NSString *originalString = textStorage.string; was returning a pointer reference, not a copy of the string. BOOL codeHasChanged was always returning NO. I solved the issue by changing textStorage.string to [NSString stringWithString:textStorage.string].
Works fine with XCode 4.6.3, but running XCode 5.0.1 menu items do not show up for plugin.
The plugin doesn't activate if using Xcode 5.1.
Solution to the problem is to download source code and rebuild using Xcode 5.1
2014-07-04 20:39:31.615 Xcode[32330:303] [MT] DVTPlugInManager: Required plug-in compatibility UUID A2E4D43F-41F4-4FB9-BB94-7177011C9AED for DebuggerUI.ideplugin (com.apple.dt.dbg.DebuggerUI) not present
2014-07-04 20:39:31.864 Xcode[32330:303] [MT] DVTAssertions: Warning in /SourceCache/DVTFrameworks/DVTFrameworks-5074/DVTFoundation/PlugInArchitecture/PlugInManager/DVTPlugInManager.m:246
Details: Requested but did not find extension point with identifier Xcode.IDEDebugger.VariablesViewQuickLookProvider
Object: <DVTPlugInManager: 0x600000341b80>
Method: -extensionPointWithIdentifier:
Thread: <NSThread: 0x600000067380>{name = (null), num = 1}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
2014-07-04 20:39:31.902 Xcode[32330:303] [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-5085/IDEFoundation/Initialization/IDEInitialization.m:312
Details: Xcode failed its initial plug-in scan, error = Error Domain=DVTPlugInErrorDomain Code=7 "Missing required components." UserInfo=0x6080002e1480 {NSLocalizedFailureReason=Components required by Xcode are missing or damaged., NSLocalizedRecoverySuggestion=Reinstall the Xcode Tools., DVTAffectedPlugInsErrorKey=(
{
DVTPlugInIdentifierErrorKey = "com.apple.dt.dbg.DebuggerUI";
}
), NSLocalizedDescription=Missing required components.}
Function: BOOL _IDEInitializePlugInManager(IDEInitializationOptions, NSError *__autoreleasing *)
Thread: <NSThread: 0x600000067380>{name = (null), num = 1}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
Format on save is a nice feature. I no longer need to remember when to format the files or dedicate a shortcut for it. However, since I use XCode for more than C-like languages, the format on save sometimes garbles the files I write. For example, when format-on-save is on, I cannot use XCode to edit Makefiles in my project.
Because of this, I currently disable format-on-save. I wish that a filetype filter can be added such that only C/C++/Objective C files are formatted on save.
Hi @benoitsan
Just udpated to dfbadf5
Action is greyed out all the time.
Any idea why ?
Thanks,
Hubert
There is an error as blew when I'm trying to format a large .mm file(about 1700 lines).
Clang Formatter error:
Task was terminated because the time-out was reached.
And I select some lines to format(just a few lines), the same error appear.
The setting is:
Formatter : Clang
ClangStyle: Chromium
Hi, the preferences only give me the option of creating a new config.
but it is not used / no config is found
I cannot edit any configFile either
The commit fa691eb may cause this issue. I had left a comment in that commit days ago.
Loading the project into Xcode 4.6.2, I get the warning:
Garbage Collection is deprecated; use the "Convert to Objective-C ARC" menu command to switch to Automatic Reference Counting
If you do as suggested
“Edit” -> “Refactor” -> “Convert to Objective-C ARC”
we reveal the real underlying problem of converting to ARC: that is,
Linked dylibs built for GC-only but object files built for retain/release for architecture x86_64
Can we realistically get rid of the warning, or is this something that cannot be changed because of the frameworks this project depends on?
Hi
I have a switch case on my Objective-C code like this one:
switch (pCode) {
case 0:
{
// My code here
}
break;
case 1:
{
// My code here
}
break;
default:
break;
}
I want to align case block like this:
switch (pCode) {
case 0:
{
// My code here
}
break;
case 1:
{
// My code here
}
break;
default:
break;
}
I tried to use indent_switch_case = 2 to align the case but it doesn't work
I use Xcode 5.1.1 and the plugin BBUncrustifyPlugin install with Alcatraz a package manager for Xcode
Problem:
Undo formatting will cause the content be 'select all' and jump to top
Repeat:
Expected:
Changes from formatting could be undo.
The cursor/focus stay on the same position.
Results:
Changes from formatting could be undo, which is good.
But the file content will be all selected, and jump to the top.
Environment:
Xcode 5.0.2
BBUncrustifyPlugin-Xcode 2.0.1
An error occurred during import cfg file with "indent_oc_block_msg_xcode_style = true".
Keep getting errors in those places where it is used: @() @{} @[]
Uncrustify Formatter error:
Parsing: MCSRPhoto.m as language OC
MCSRPhoto.m:62 Garbage in col 24: 40
MCSRPhoto.m:78 Garbage in col 50: 40
For God's sake do not cancel formatting! Just ignore this type of error.
In older versions worked well.
I cannot select a custom editor in the drop down. Its as if the dropdown is disabled
XCode: 5.1.1
Mac OS: 10.9.3
I have the latest code - cleaned project - compile and it's crashing. any ideas on how to fix?
2014-09-15 09:21:43.010 Xcode[36790:4928625] [MT] DVTAssertions: UNCAUGHT EXCEPTION (NSInternalInconsistencyException): Extension Xcode.IDEKit.CmdHandler.ShowViewDrawing class 'DBGMenuController' not found for required key 'handlerClass'
UserInfo: {
DVTExtensionClassNameErrorKey = DBGMenuController;
DVTExtensionIdentifierErrorKey = "Xcode.IDEKit.CmdHandler.ShowViewDrawing";
DVTPlugInExecutablePathErrorKey = "/Applications/Xcode.app/Contents/PlugIns/DebuggerUI.ideplugin";
DVTPlugInIdentifierErrorKey = "com.apple.dt.dbg.DebuggerUI";
}
Hints: None
2014-09-15 09:21:43.824 Xcode[36790:4928625] [MT] DVTAssertions:
Backtrace:
0 0x00007fff8e438bd4 exceptionPreprocess (in CoreFoundation)
1 0x00000001001e6184 DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 0x00007fff8d6886de objc_exception_throw (in libobjc.A.dylib)
3 0x000000010004ebd7 -[DVTExtension _adjustClassAttribute:forKey:inParameterData:](in DVTFoundation)
4 0x000000010004e633 -[DVTExtension _adjustClassReferencesInParameterData:usingSchema:](in DVTFoundation)
5 0x00000001000d210c -[DVTExtension _fireExtensionFault:](in DVTFoundation)
6 0x00000001000d1a75 __63-[DVTExtension _valueForKey:inParameterData:usingSchema:error:]_block_invoke (in DVTFoundation)
7 0x0000000101fa7e53 _dispatch_client_callout (in libdispatch.dylib)
8 0x0000000101fa91c1 _dispatch_barrier_sync_f_invoke (in libdispatch.dylib)
9 0x000000010021cdfd DVTDispatchBarrierSync (in DVTFoundation)
10 0x000000010001fbc4 -[DVTDispatchLock performLockedBlock:](in DVTFoundation)
11 0x00000001000d1851 -[DVTExtension _valueForKey:inParameterData:usingSchema:error:](in DVTFoundation)
12 0x00000001000d1c44 -[DVTExtension valueForKey:error:](in DVTFoundation)
13 0x00000001014163de __55+[IDECommandManager cacheCommandDefinitionsAndHandlers]_block_invoke (in IDEKit)
14 0x0000000101fa7e53 _dispatch_client_callout (in libdispatch.dylib)
15 0x0000000101fa7e3e dispatch_once_f (in libdispatch.dylib)
16 0x00000001011cfa60 +[IDECommandManager cacheCommandDefinitionsAndHandlers](in IDEKit)
17 0x00000001011cf054 -[IDEApplicationController applicationWillFinishLaunching:](in IDEKit)
18 0x00007fff8e3f50dc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER (in CoreFoundation)
19 0x00007fff8e2e6634 _CFXNotificationPost (in CoreFoundation)
20 0x00007fff8cee29b1 -[NSNotificationCenter postNotificationName:object:userInfo:](in Foundation)
21 0x00000001001c6e6e -[NSNotificationCenter(DVTNSNotificationCenterAdditions) _dvt_postNotificationName:object:userInfo:](in DVTFoundation)
22 0x00007fff83c32797 -[NSApplication finishLaunching](in AppKit)
23 0x000000010074a665 -[DVTApplication finishLaunching](in DVTKit)
24 0x00007fff83c32261 -[NSApplication run](in AppKit)
25 0x00007fff83c1d834 NSApplicationMain (in AppKit)
26 0x00007fff88fe45c9 start (in libdyld.dylib)
27 0x0000000000000003
Would be very practical. I'll try to look into it if I have time!
BBUncrustifyPlugin.xcodeproj Garbage Collection is deprecated; use the "Convert to Objective-C ARC" menu command to switch to Automatic Reference Counting
If I only put a “uncrustify.cfg” file with the XCode workspace file, and when I click “Open with UncrustifyX” ,and alert that "Custom Configuration File Not Found"
First of all, sorry for not providing a test case.
When I save this file (thus triggering uncrustify) I always get a crash:
//
// WSTest.h
// Test
//
// Created by Nicolas Goles on 3/13/14.
// Copyright (c) 2014 Goles. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface WSTest : NSObject
{
}
@end
I have a crash.log for you though... hoping it helps.
I used this plugin every day and it saves me a lot of time. But after updating Xcode to 5.1 - plugin settings missed from Xcode Edit bar. I used 1.0.5 version & want to continue to using it.
Please add support for Xcode 5.1. Please!
In the current version, the file is marked modified even if Uncrustify did modified file. This behavior occurs with "Uncrustify Selected Files" and "Uncrustify Active File".
For some reason ability to format active file or selected files doesn't work. If I highlight lines and highlight selected lines it does work.
Not sure what I changed that made this happen. I tried removing and reinstalling plugin but it did not fix the problem.
Any help appreciated!
When I try to format using an enum declared this way the semicolon is removed. I use uncrustify as formatter and my config file is https://gist.github.com/orlandoaleman/5705746. I've tested formatting with UncrustifyX gui and it goes right.
typedef NS_ENUM (NSUInteger, InvaderType) {
InvaderTypeA,
InvaderTypeB,
InvaderTypeC
};
Environment:
Xcode 5.0.2
BBUncrustifyPlugin-Xcode 2.0.1
Has anyone made this work in Xcode 6.0b2?
Hi. I would like to have an option to format all open files, alongside the ones to format the active or the selected ones.
Xcode 5.1 seems to have broken the plug-in for me. Is this just me?
Frankly, I know little about the plug-in architecture of Xcode but I figured it would be worth creating an issue just to verify if this was a known issue.
Hi
With the modern objective-c specifiy by Apple an enum must be declare like this:
typedef NS_ENUM (NSUInteger, ArrowSide) {
ArrowSideNone,
ArrowSideTop,
ArrowSideBottom,
ArrowSideRight,
ArrowSideLeft
};
typedef NS_ENUM (NSUInteger, ArrowPosition) {
ArrowPositionMiddle,
ArrowPositionTop,
ArrowPositionBottom
};
But uncrustify apply a wrong format it must be like this:
typedef NS_ENUM(NSUInteger, ArrowSide) {
ArrowSideNone,
ArrowSideTop,
ArrowSideBottom,
ArrowSideRight,
ArrowSideLeft
};
typedef NS_ENUM(NSUInteger, ArrowPosition) {
ArrowPositionMiddle,
ArrowPositionTop,
ArrowPositionBottom
};
It's like uncrustify doesn't recognize the new enum format specify by Apple.
I use Xcode 5.1.1 and the plugin BBUncrustifyPlugin install with Alcatraz a package manager for Xcode
Whenever I format a file, it removes the breakpoints for that file.
Uncrustify 2.0.2
With version 1.0.4 C/C++ header files are formatted with the -l OC flag because they have a .h extension.
Here is the responsible line:
785cde9#commitcomment-3912998
A solution would be to only include the -l OC flag if a corresponding .m file is also present.
It is currently not possible to assign key bindings to the uncrustify commands as they do not appear in the keybindings preferences.
Note: there's no possibility in 10.8 system preferences to add application specific bindings, nor does any of the uncrustify commands appear in the existing list.
If one uses filename expansion, $(filename) in header & footer files, see uncrustify configuration attributes: cmt_insert_file_header, cmt_insert_file_footer, cmt_insert_func_header, cmt_insert_class_header, and cmt_insert_oc_msg_header the file name appears to be a unique identifier instead of the filename.
I tried it on XCode 5.0.2,But no shortcut can be founded on KeyBorad Preference or XCode Preference.How to?
I am currently working on a fork which is compatible with Xcode 3 (3.2.6) capable of running under 10.6 (10.6.8). It is almost done except for one function:
The function "NSArray * BBMergeContinuousRanges(NSArray *ranges", uses enumerateRangesUsingBlock which isn't available under 10.6. Although I have been coding for a while I can't seem to write an alternative function compilable on 10.6, can you help me out?
Can you provide me with an alternative "NSArray * BBMergeContinuousRanges(NSArray *ranges" that compiles on 10.6?
Like option indent_align_assign
Align continued statements at the '='.
If FALSE or the '=' is followed by a newline, the next line is indent one tab.
Turn it off and uncrustify this code
CFUUIDRef uuid =
CFUUIDCreate(NULL);
should become
CFUUIDRef uuid =
CFUUIDCreate(NULL);
but with this syntax-aware indenting
option, it become
CFUUIDRef uuid =
CFUUIDCreate(NULL);
Because the code had been re-indented again by Xcode.
It's wrong, because it break the uncrustify rule.
In fact if the user like to use Xcode's indenting, just use it simply with Ctrl + I
, it's not a part of job of this plugin.
@benoitsan Please consider dopping this feature.
It appears things stopped working with Xcode 5.0 Beta 3, was working fine in Beta 2. Anyone else seeing this?
I noticed you are setting the language override function to always do Objective-C. There is not reason for this. For my configuration file it causes C++ files in my Xcode project to be formatted incorrectly and introduces syntax errors. I removed this flag and everything is perfect! :)
When build the project, also saves it, but it not formatting.
Might you add a configuration to format the project when it is generated?
Tanks
Well, is not working for Xcode 5.1 T_T
It's possible to have an update for this plugin for the new version of Xcode?
Thanks
Hi
This my case:
[self myMethodWithBlock1:^(NSString *pParam1,NSString *pParam2) {
// My code here
}
Block2:^(NSString *pParam1,NSString *pParam2) {
// My code here
}
What is the setting to align the blocks like this:
[self myMethodWithBlock1:^(NSString *pParam1,NSString *pParam2) {
// My code here
}
Block2:^(NSString *pParam1,NSString *pParam2) {
// My code here
}
I use Xcode 5.1.1 and the plugin BBUncrustifyPlugin install with Alcatraz a package manager for Xcode
The the following code uncrusifies differently:
- (void)foo
{
NSString *bar = @"hello";
NSLog(@"%@", bar);
}
(apparently the 4 space indent for the blank line is being eaten by the md)
The plugin's uncrustification keeps the 4 space indent for the blank line, while running uncrustify from the command line removes the 4 space indent for the blank line.
To make sure I am using the same uncrustify command and config file, I cd to ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin/Contents/Resources
and ran ./uncrustify -c ./uncrustify.cfg /pathToFile/foo.m
The diff was
26c26
<
---
>
The uncrustify config file I used can be found here: https://gist.github.com/m2orris/5297267
I found this because my git pre-commit hooks puked on me during check in, all blank lines had issues.
Note to anyone who uses the plugin and git pre-commit hooks to uncrustify code. Make sure you are using the same uncrustify binary and configuration file or the uncrustify results could be inconsistent.
I achieve this by a post build step that creates symbolic links in the ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin/Contents/Resources
to the the uncrustify binary and config file used in the git pre-commit hooks.
cd ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin/Contents/Resources
mv uncrustify uncrustify.orig
ln -s /usr/local/bin/uncrustify uncrustify
mv uncrustify.cfg uncrustify.cfg.orig
ln -s ~/dist/Xcode/uncrustify/config/uncrustify_obj_c.cfg uncrustify.cfg
I know this one has been raised before but I think there still might be an issue here. I'm using xcode 5.1 with BBUncrustifyPlugin-Xcode 2.0.3 and I have found that UncrustifyX will happily find my configuration file in the root of the project directory (or the various home directory options) if it's named .uncrustifyconfig or uncrustify.cfg but my source files are in a sub directory and never get formatted unless I put a configuration file in every directory. This seems to contradict the instructions.
Seems to me that the logic in UncrustifyX for finding config files might be different from the plugin, dunno.
It would be very handy if the preferences page stated which configuration files it had found and which it was going to use on a given project.
FYI If I use Clang instead of uncrustify it all works nicely.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.