Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Updated project to support macOS 13.3 and Xcode 14.3 by IhorShevchuk · Pull Request #62 · mapbox/XcodeClangFormat · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions XcodeClangFormat.xcodeproj/project.pbxproj
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */; };
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; };
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 01A2120E29F1C40400639A2B /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
559B23E31D7EBDA300937AB3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E21D7EBDA300937AB3 /* AppDelegate.m */; };
559B23E61D7EBDA300937AB3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 559B23E51D7EBDA300937AB3 /* main.m */; };
559B23E81D7EBDA300937AB3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 559B23E71D7EBDA300937AB3 /* Assets.xcassets */; };
Expand All@@ -29,6 +32,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
01A2121C29F1D47E00639A2B /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
01A2121B29F1D47D00639A2B /* XcodeKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
559B240A1D7EBDB700937AB3 /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand All@@ -43,6 +57,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
01A2120E29F1C40400639A2B /* XcodeKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XcodeKit.framework; path = Library/Frameworks/XcodeKit.framework; sourceTree = DEVELOPER_DIR; };
01A2121229F1C4D900639A2B /* configure */ = {isa = PBXFileReference; lastKnownFileType = text; path = configure; sourceTree = "<group>"; };
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
552396A22473BCCB002F4098 /* ClangFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClangFormat.h; sourceTree = "<group>"; };
556DCDEF1D7EF694005956C8 /* XcodeClangFormat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = XcodeClangFormat.entitlements; sourceTree = "<group>"; };
557D38B71D7F270E00708269 /* libcurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurses.tbd; path = usr/lib/libcurses.tbd; sourceTree = SDKROOT; };
Expand DownExpand Up@@ -77,6 +94,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
01A2121929F1D46000639A2B /* UniformTypeIdentifiers.framework in Frameworks */,
01A2121A29F1D47D00639A2B /* XcodeKit.framework in Frameworks */,
55BCFFFA1D80170F000EDB05 /* libcurses.tbd in Frameworks */,
559B24101D7EBDC400937AB3 /* Cocoa.framework in Frameworks */,
);
Expand All@@ -90,6 +109,7 @@
children = (
55BCFFF71D801362000EDB05 /* config.xcconfig */,
55C8203F1D87F81300006D07 /* LICENSE.md */,
01A2121229F1C4D900639A2B /* configure */,
559B23E01D7EBDA300937AB3 /* XcodeClangFormat */,
559B24111D7EBDC400937AB3 /* clang-format */,
559B23F71D7EBDB700937AB3 /* Frameworks */,
Expand DownExpand Up@@ -131,6 +151,8 @@
559B23F71D7EBDB700937AB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
01A2121829F1D46000639A2B /* UniformTypeIdentifiers.framework */,
01A2120E29F1C40400639A2B /* XcodeKit.framework */,
557D38B71D7F270E00708269 /* libcurses.tbd */,
559B23F81D7EBDB700937AB3 /* Cocoa.framework */,
);
Expand DownExpand Up@@ -188,6 +210,7 @@
559B240B1D7EBDC400937AB3 /* Sources */,
559B240C1D7EBDC400937AB3 /* Frameworks */,
559B240D1D7EBDC400937AB3 /* Resources */,
01A2121C29F1D47E00639A2B /* Embed Frameworks */,
);
buildRules = (
);
Expand DownExpand Up@@ -311,11 +334,12 @@
/* Begin XCBuildConfiguration section */
559B23ED1D7EBDA300937AB3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -345,7 +369,6 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
Expand All@@ -359,7 +382,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand All@@ -368,11 +391,12 @@
};
559B23EE1D7EBDA300937AB3 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 55BCFFF71D801362000EDB05 /* config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand DownExpand Up@@ -402,15 +426,14 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
Expand DownExpand Up@@ -469,7 +492,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand DownExpand Up@@ -514,7 +536,6 @@
GCC_SYMBOLS_PRIVATE_EXTERN = YES;
INFOPLIST_FILE = "clang-format/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @executable_path/../../../../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 1.2.1;
OTHER_CPLUSPLUSFLAGS = (
"--system-header-prefix=$(LLVM_INCLUDE_DIR)",
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1140"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "1.3">
<BuildAction
Expand Down
16 changes: 8 additions & 8 deletions XcodeClangFormat/AppDelegate.m
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,17 +26,17 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
}

if ([style isEqualToString:@"custom"]) {
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"google"]) {
self.googleStyle.state = NSOnState;
self.googleStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"chromium"]) {
self.chromiumStyle.state = NSOnState;
self.chromiumStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"mozilla"]) {
self.mozillaStyle.state = NSOnState;
self.mozillaStyle.state = NSControlStateValueOn;
} else if ([style isEqualToString:@"webkit"]) {
self.webkitStyle.state = NSOnState;
self.webkitStyle.state = NSControlStateValueOn;
} else {
self.llvmStyle.state = NSOnState;
self.llvmStyle.state = NSControlStateValueOn;
}

NSData* bookmark = [defaults dataForKey:@"file"];
Expand DownExpand Up@@ -65,7 +65,7 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
self.secondaryPathControl.URL = url;
} else {
// Remove the bookmark value from the storage
[defaults setNilValueForKey:@"regularBookmark"];
[defaults removeObjectForKey:@"regularBookmark"];
}
[defaults synchronize];
}
Expand DownExpand Up@@ -149,7 +149,7 @@ - (BOOL)selectURL:(NSURL*)url {
} else {
self.primaryPathControl.URL = url;
self.secondaryPathControl.URL = url;
self.customStyle.state = NSOnState;
self.customStyle.state = NSControlStateValueOn;

[defaults setValue:@"custom" forKey:@"style"];
[defaults setObject:bookmark forKey:@"file"];
Expand Down
21 changes: 11 additions & 10 deletions clang-format/ClangFormatCommand.mm
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
#import "ClangFormatCommand.h"

#import <AppKit/AppKit.h>
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#include "ClangFormat.h"

Expand All@@ -17,8 +18,8 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}

clang::format::FormatStyle::LanguageKind getLanguageKind(XCSourceTextBuffer* buffer) {
CFStringRef uti = (__bridge CFStringRef)buffer.contentUTI;
if (UTTypeEqual(uti, kUTTypeCHeader)) {
NSString *uti = buffer.contentUTI;
if ([UTTypeCHeader.identifier isEqualToString:uti]) {
// C header files could also be Objective-C. We attempt to detect typical Objective-C keywords.
for (NSString* line in buffer.lines) {
if ([line hasPrefix:@"#import"] || [line hasPrefix:@"@interface"] || [line hasPrefix:@"@protocol"] ||
Expand All@@ -27,15 +28,15 @@ void updateOffsets(std::vector<size_t>& offsets, NSMutableArray<NSString*>* line
}
}
}
if (UTTypeEqual(uti, kUTTypeCPlusPlusHeader) || UTTypeEqual(uti, kUTTypeCPlusPlusSource) ||
UTTypeEqual(uti, kUTTypeCHeader) || UTTypeEqual(uti, kUTTypeCSource)) {
if ([UTTypeCPlusPlusHeader.identifier isEqualToString:uti] ||
[UTTypeCPlusPlusSource.identifier isEqualToString:uti] ||
[UTTypeCHeader.identifier isEqualToString:uti] ||
[UTTypeCSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_Cpp;
} else if (UTTypeEqual(uti, kUTTypeObjectiveCSource) ||
UTTypeEqual(uti, kUTTypeObjectiveCPlusPlusSource)) {
} else if ([UTTypeObjectiveCSource.identifier isEqualToString:uti] ||
[UTTypeObjectiveCPlusPlusSource.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_ObjC;
} else if (UTTypeEqual(uti, kUTTypeJavaSource)) {
return clang::format::FormatStyle::LK_Java;
} else if (UTTypeEqual(uti, kUTTypeJavaScript)) {
} else if ([UTTypeJavaScript.identifier isEqualToString:uti]) {
return clang::format::FormatStyle::LK_JavaScript;
}

Expand DownExpand Up@@ -202,7 +203,7 @@ - (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation*)invocatio
// Calculated replacements and apply them to the input buffer.
const llvm::StringRef filename("<stdin>");
clang::format::FormattingAttemptStatus status;
auto replaces = clang::format::reformat(format.GetLanguageStyle(language).getValueOr(format), code, ranges, filename, &status);
auto replaces = clang::format::reformat(*format.GetLanguageStyle(language), code, ranges, filename, &status);

if (!status.FormatComplete) {
// We could not apply the calculated replacements.
Expand Down
28 changes: 25 additions & 3 deletions configure
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,29 @@ set -e
set -o pipefail
set -u

LLVM_VERSION=10.0.0
LLVM_HASH=70a7d5ed3bb16a5b5310ea4bfe95a74894022a43abb96d28ef8e30ab1f41d47a
LLVM_VERSION=15.0.0

function llvmHash() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "76fbc61512e0d8002e2a127d932d02bc49722fecca4ebf71ec6230e3aff65356"
else
echo "21f964fe2ff70847d704cac98fa4dd19bd2bd5b126c9a9bca3bad9855e4a413e"
fi
}

function llvmURL() {
arch=$1
if [ "$arch" = "arm64" ]; then
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin21.0.tar.xz"
else
echo "https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-${MAC_OS_ARCH}-apple-darwin.tar.xz"
fi
}

#architecture should be passed as parameter or script will use host Mac architecture
MAC_OS_ARCH=${1:-$(uname -m)}
LLVM_HASH=$(llvmHash $MAC_OS_ARCH)
LLVM_CONFIG=${LLVM_CONFIG:-llvm-config}

command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
Expand All@@ -14,7 +35,7 @@ command -v "${LLVM_CONFIG}" >/dev/null 2>&1 || {
mkdir -p "deps"
FILE="deps/clang-${LLVM_VERSION}.tar.xz"
if [ ! -f "${FILE}" ]; then
URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
URL=$(llvmURL $MAC_OS_ARCH)
echo "Downloading ${URL}..."
curl --retry 3 -# -S -L "${URL}" -o "${FILE}.tmp" && mv "${FILE}.tmp" "${FILE}"
fi
Expand All@@ -38,6 +59,7 @@ echo "// Do not modify this file. Instead, rerun ./configure" > config.xcconfig
echo "LLVM_LIBDIR=$(${LLVM_CONFIG} --libdir)" >> config.xcconfig
echo "LLVM_INCLUDE_DIR=$(${LLVM_CONFIG} --includedir)" >> config.xcconfig
echo "LLVM_CXXFLAGS=$(${LLVM_CONFIG} --cxxflags)" >> config.xcconfig
echo "ARCHS=$MAC_OS_ARCH" >> config.xcconfig

echo "Wrote config.xcconfig."

Expand Down