nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.77k stars 630 forks source link

Not seeing SwiftFormat in Xcode 12.1/Big Sur #808

Open ahwulf opened 3 years ago

ahwulf commented 3 years ago

I installed SwiftFormat and SwiftFormat For Xcode and followed the instructions. But no matter what I do Xcode never shows it in the Edit menu. The extension is clearly checked in Preferences. I even ran the whole thing multiple times, but Xcode never changes. Is this some limitation in 12.X or Big Sur?

ahwulf commented 3 years ago

Appears to require this: https://developer.apple.com/forums/thread/666434

ahwulf commented 3 years ago

Comment in Xcode 12 release notes: "A new Xcode Source Editor Extension target doesn’t automatically set up embedding XcodeKit.framework in the extension. (59274389) Workaround: Embed XcodeKit.framework in the extension manually." No mention of fixing this in 12.1 or 12.2

nicklockwood commented 3 years ago

@ahwulf I don't have Bug Sur to test with yet - would you mind trying to fix this and open a PR if you get it working?

ahwulf commented 3 years ago

Never dealt with an extension before. Does it work for you in Xcode 12.X on Catalina? The release notes for Xcode were not very clear as to whether it was a 12 bug or an OS bug (maybe some kind of security thing).

nicklockwood commented 3 years ago

@ahwulf it works on Catalina.

ahwulf commented 3 years ago

OK I see XCodekit is Embed & Sign in your extension, which seems to be what is required, yet it does not work. Not a clue what else to try. Maybe someone else out there has some idea? The only thing I see in console at the end of the process is swift format reporting Invalidating assertion 215-35016-20762 (target:[xpcservice<com.charcoaldesign.SwiftFormat-for-Xcode.SourceEditorExtension([app<application.com.apple.dt.Xcode.8655004951.8655170801(501)>:35016])(501)>:35026]) from originator [app<application.com.apple.dt.Xcode.8655004951.8655170801(501)>:35016]

Cyberbeni commented 3 years ago

I downloaded it from the release assets and it works for me for both macOS 10.15 and 11.0 with Xcode 12.2

imWildCat commented 3 years ago

Interesting, I am not seeing any Xcode extensions anymore, even for those downloaded from the App Store.

Looks like a system bug. I build this project again and signed it. However, it does not show.

nicklockwood commented 3 years ago

@imWildCat do you have multiple copies of Xcode installed? That might explain it. Also, try moving Xcode out of the applications folder and then moving it back again.

imWildCat commented 3 years ago

@nicklockwood I have Xcode 12.0 in the Downloads folder. After removing it completely, Xcode extensions are still now shown in the Preferences window. I am rebooting my laptop now.

imWildCat commented 3 years ago

No luck.

Found a potential issue:

default --:--:--.796921+0800    Xcode   [MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-17535/IDEKit/NavigableItems/IDENavigableItem.m:1248
Details:  No match from <IDEKeyDrivenNavigableItem 0x7f962fdc3d50: (supports Any NSObject, represents: <Xcode3EditingGroup: 0x7f964870d3a0>)> to <Xcode3Target:0x7f969ffe1420:SwiftFormat for Xcode>. Iterating the whole tree might have taken a significant amount of time.
Object:   <IDEKeyDrivenNavigableItem_Xcode3EditingGroup_Any: 0x7f962fdc3d50>
Method:   -_descendantItemForRepresentedObject:stopAtClass:
Thread:   <NSThread: 0x7f96efc19e70>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.
nicklockwood commented 3 years ago

@imWildCat did you try this?

try moving Xcode out of the applications folder and then moving it back again.

imWildCat commented 3 years ago

@imWildCat did you try this?

try moving Xcode out of the applications folder and then moving it back again.

Sorry, I missed this one. It works, thank you!

ahwulf commented 3 years ago

I will try that later today too.

On Tue, Dec 1, 2020 at 6:40 AM Daohan Chong notifications@github.com wrote:

@imWildCat https://github.com/imWildCat did you try this?

try moving Xcode out of the applications folder and then moving it back again.

Sorry, I missed this one. It works, thank you!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nicklockwood/SwiftFormat/issues/808#issuecomment-736480295, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUAZTAASTT4FB3UVUE576LSSTIZBANCNFSM4T6RT63Q .

puls commented 3 years ago

I also had this issue today, and I also solved it by moving Xcode out of /Applications and then moving it back.

vvit commented 3 years ago

@imWildCat do you have multiple copies of Xcode installed? That might explain it. Also, try moving Xcode out of the applications folder and then moving it back again.

Helped me too! I haven't seen the plugin in the System Preferences > Extensions at all until I did this.

VinceBurn commented 3 years ago

Have you check this: https://nshipster.com/xcode-source-extensions/

Section Using pluginkit start with this:

During development, Xcode can become confused as to which extensions it sees. It can be useful to get an overview of installed extensions using the pluginkit tool. This allows us to query the private PluginKit framework that manages all system extensions.

I have used the instruction in that section in the past when I was not able to see the extension from Xcode after an upgrade.

stidch commented 3 years ago

Hi @VinceBurn

Thanks for the link above. Looked promising, but unfortunately it has not changed anything. I've run

PATH=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support:"$PATH"
lsregister -f /Applications/Xcode-12.3.app

I've restarted both Xcode and the Extensions dialog, but still Xcode is not showing up in the list :(

When I again run

pluginkit -m -p com.apple.dt.Xcode.extension.source-editor

it still does not print anything.

I guess this is not what should happen, right?

By the way, I'm using xcode-install, resp. xcversion for managing my Xcode installations (https://github.com/xcpretty/xcode-install).

imWildCat commented 3 years ago

Linking #804 for cross referencing...