Xcode 4 plugin development

As far as I know there is no official way to create Xcode 4 plugins (just like there wasn't one for v3.x).

Here is an openradar on Xcode's lack of plugin support:

Please support the ability for 3rd parties to extend Xcode via a public plugin API. Aperture, Visual Studio, Eclipse, TextMate and other applications benefit from this ability. I would like to see more advanced refactorings, code analysis (think Resharper by Jetbrains) and modeling.

Provide plugin API for Xcode 4 (rdar://8622025)

Please dupe this if you want plugins!


Edit: Just stumbled upon this:

Cédric Luthi: "Xcode 4 does support user-defined plugins, see CLITool-InfoPlist for an example of a working Xcode 4 plugin. You just have to add XC4Compatible (true) in the Info.plist."

https://github.com/0xced/CLITool-InfoPlist


That being said these GitHub repos might be handy, too:

  • Xcode4 Plugin-API Documentation (link dead)

  • Xcode Plugin Template (link updated)


Further more mogenerator's Xmod plugin might be a good starting point.
(Wasn't Xcode-4 compatible yet, last time I checked, though)


Best way to learn is to look at github plugin code (see long list below):

  • Basically its a plugin bundle.
  • No main.m No MainMenu.xib
  • First class loaded by setting NSPrincipalClass in info.plist
  • in its init: you register for AppKit notifications
  • See the code samples
  • some check the mainBundle app id to make sure this is XCode
  • The XCode Editor window class is DVTSourceTextView
  • Its a subclass of DVTSourceTextView :NSTextView : NSText
  • so you can register to listen for its notifications for NSTextView or NSText
  • such as NSTextViewWillChangeNotifyingTextViewNotification

Because its not an official standard I noticed each sample loads in different ways.

XCODE PLUGIN SAMPLES

compiled by either searching github/web for

'DVTSourceTextView'

This is the Xcode Editor window class name

or

Info-list key

'XC4Compatible'


https://github.com/omz/ColorSense-for-Xcode

https://github.com/ciaran/xcode-bracket-matcher
- uses a ruby parser run as pipe!

https://github.com/joshaber/WTFXcode
https://github.com/0xced/NoLastUpgradeCheck
http://code.google.com/p/google-toolbox-for-mac/downloads/list
    see GTMXcode4Plugin
https://github.com/DeepIT/XcodeColors
https://github.com/0xced/CLITool-InfoPlist
https://github.com/sap-production/xcode-ide-maven-integration
https://github.com/ciaran/xcode-bracket-matcher

TO GET TO THE NSTextView that is the console

https://github.com/sap-production/xcode-ide-maven-integration

- (NSTextView *)findConsoleAndActivate {
    Class consoleTextViewClass = objc_getClass("IDEConsoleTextView");
    NSTextView *console = (NSTextView *)[self findView:consoleTextViewClass inView:NSApplication.sharedApplication.mainWindow.contentView];

    if (console) {
        NSWindow *window = NSApplication.sharedApplication.keyWindow;
        if ([window isKindOfClass:objc_getClass("IDEWorkspaceWindow")]) {
            if ([window.windowController isKindOfClass:NSClassFromString(@"IDEWorkspaceWindowController")]) {
                id editorArea = [window.windowController valueForKey:@"editorArea"];
                [editorArea performSelector:@selector(activateConsole:) withObject:self];
            }
        }
    }

    return console;
}

Have a look at this new plugin: https://github.com/sap-production/xcode-ide-maven-integration. Maybe you can derive some concepts for your plugin.


Yesterday ColorSense for Xcode 4 was released on Github. Since the code is really compact spread over just 3 classes, I think you should take a look over there.