Skip to content

Commit f7dcb32

Browse files
AndreaAndrea
authored andcommitted
Merge remote-tracking branch 'upstream/master'
2 parents 415fe7c + f929c3f commit f7dcb32

File tree

5 files changed

+129
-18
lines changed

5 files changed

+129
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SCXcodeSwitchExpander is a small Xcode plugin that expands switch statements by
3838

3939
- Download SCXcodeSwitchExpander.xcplugin.zip from the releases tab, unzip and move it to the Xcode plugins folder ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/SCXcodeSwitchExpander.xcplugin and restart Xcode or ...
4040

41-
- Get it through [Alcatraz](https://github.com/supermarin/Alcatraz)
41+
- Get it through [Alcatraz](https://github.com/alcatraz/Alcatraz)
4242

4343
- If you encounter any issues you can uninstall it by removing the ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/SCXcodeSwitchExpander.xcplugin folder
4444

SCXcodeSwitchExpander.xcodeproj/project.pbxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
18990B1718D25239007A8756 /* Project object */ = {
156156
isa = PBXProject;
157157
attributes = {
158-
LastUpgradeCheck = 0510;
158+
LastUpgradeCheck = 0700;
159159
ORGANIZATIONNAME = "Stefan Ceriu";
160160
};
161161
buildConfigurationList = 18990B1A18D25239007A8756 /* Build configuration list for PBXProject "SCXcodeSwitchExpander" */;
@@ -215,6 +215,7 @@
215215
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
216216
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
217217
COPY_PHASE_STRIP = NO;
218+
ENABLE_TESTABILITY = YES;
218219
GCC_C_LANGUAGE_STANDARD = gnu99;
219220
GCC_DYNAMIC_NO_PIC = NO;
220221
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
@@ -285,6 +286,7 @@
285286
GCC_PREFIX_HEADER = "SCXcodeSwitchExpander/SCXcodeSwitchExpander-Prefix.pch";
286287
INFOPLIST_FILE = "SCXcodeSwitchExpander/SCXcodeSwitchExpander-Info.plist";
287288
INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins";
289+
PRODUCT_BUNDLE_IDENTIFIER = "com.stefanceriu.${PRODUCT_NAME:rfc1034identifier}";
288290
PRODUCT_NAME = "$(TARGET_NAME)";
289291
WRAPPER_EXTENSION = xcplugin;
290292
};
@@ -307,6 +309,7 @@
307309
GCC_PREFIX_HEADER = "SCXcodeSwitchExpander/SCXcodeSwitchExpander-Prefix.pch";
308310
INFOPLIST_FILE = "SCXcodeSwitchExpander/SCXcodeSwitchExpander-Info.plist";
309311
INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins";
312+
PRODUCT_BUNDLE_IDENTIFIER = "com.stefanceriu.${PRODUCT_NAME:rfc1034identifier}";
310313
PRODUCT_NAME = "$(TARGET_NAME)";
311314
WRAPPER_EXTENSION = xcplugin;
312315
};
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0700"
4+
version = "2.0">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "18990B1E18D25239007A8756"
18+
BuildableName = "SCXcodeSwitchExpander.xcplugin"
19+
BlueprintName = "SCXcodeSwitchExpander"
20+
ReferencedContainer = "container:SCXcodeSwitchExpander.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
34+
</TestAction>
35+
<LaunchAction
36+
buildConfiguration = "Debug"
37+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
38+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
39+
launchStyle = "0"
40+
useCustomWorkingDirectory = "NO"
41+
ignoresPersistentStateOnLaunch = "NO"
42+
debugDocumentVersioning = "NO"
43+
debugXPCServices = "NO"
44+
debugServiceExtension = "internal"
45+
allowLocationSimulation = "NO"
46+
viewDebuggingEnabled = "No">
47+
<PathRunnable
48+
runnableDebuggingMode = "0"
49+
FilePath = "/Applications/Xcode.app">
50+
</PathRunnable>
51+
<MacroExpansion>
52+
<BuildableReference
53+
BuildableIdentifier = "primary"
54+
BlueprintIdentifier = "18990B1E18D25239007A8756"
55+
BuildableName = "SCXcodeSwitchExpander.xcplugin"
56+
BlueprintName = "SCXcodeSwitchExpander"
57+
ReferencedContainer = "container:SCXcodeSwitchExpander.xcodeproj">
58+
</BuildableReference>
59+
</MacroExpansion>
60+
<AdditionalOptions>
61+
</AdditionalOptions>
62+
</LaunchAction>
63+
<ProfileAction
64+
buildConfiguration = "Release"
65+
shouldUseLaunchSchemeArgsEnv = "YES"
66+
savedToolIdentifier = ""
67+
useCustomWorkingDirectory = "NO"
68+
debugDocumentVersioning = "YES">
69+
<MacroExpansion>
70+
<BuildableReference
71+
BuildableIdentifier = "primary"
72+
BlueprintIdentifier = "18990B1E18D25239007A8756"
73+
BuildableName = "SCXcodeSwitchExpander.xcplugin"
74+
BlueprintName = "SCXcodeSwitchExpander"
75+
ReferencedContainer = "container:SCXcodeSwitchExpander.xcodeproj">
76+
</BuildableReference>
77+
</MacroExpansion>
78+
</ProfileAction>
79+
<AnalyzeAction
80+
buildConfiguration = "Debug">
81+
</AnalyzeAction>
82+
<ArchiveAction
83+
buildConfiguration = "Release"
84+
revealArchiveInOrganizer = "YES">
85+
</ArchiveAction>
86+
</Scheme>

SCXcodeSwitchExpander/DVTTextCompletionController+SCXcodeSwitchExpander.m

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ - (BOOL)tryExpandingSwitchStatement
9898
}
9999

100100
// See if the current line has a switch statement
101-
NSRange switchRange = [textView.string rangeOfString:@"\\s+switch\\s*\\\(" options:NSRegularExpressionSearch range:NSMakeRange(newLineRange.location, self.session.wordStartLocation - newLineRange.location)];
101+
NSString *regPattern = [[SCXcodeSwitchExpander sharedSwitchExpander] isSwift] ? @"\\s+switch\\s*" : @"\\s+switch\\s*\\\(";
102+
NSRange switchRange = [textView.string rangeOfString:regPattern options:NSRegularExpressionSearch range:NSMakeRange(newLineRange.location, self.session.wordStartLocation - newLineRange.location)];
102103
if(switchRange.location == NSNotFound) {
103104
return NO;
104105
}
@@ -109,6 +110,12 @@ - (BOOL)tryExpandingSwitchStatement
109110
return NO;
110111
}
111112

113+
// Check if it's the opening bracket for the switch statement or something else
114+
NSString *remainingText = [textView.string substringWithRange:NSMakeRange(switchRange.location + switchRange.length, openingBracketLocation - switchRange.location - switchRange.length)];
115+
if([remainingText rangeOfString:@"}"].location != NSNotFound) {
116+
return NO;
117+
}
118+
112119
// Insert the selected autocomplete item
113120
[self.session insertCurrentCompletion];
114121

@@ -140,15 +147,28 @@ - (BOOL)tryExpandingSwitchStatement
140147
// Generate the items to insert and insert them at the end
141148
NSMutableString *replacementString = [NSMutableString string];
142149

143-
if([switchContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length == 0) {
144-
[replacementString appendString:@"\n"];
150+
NSString *trimmedContent = [switchContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
151+
152+
if(trimmedContent.length == 0) {
153+
// remove extraneous empty lines if existing content is only whitespace
154+
if (switchContent.length > 0) {
155+
[textView insertText:@"" replacementRange:switchContentRange];
156+
closingBracketLocation -= switchContent.length;
157+
switchContentRange.length = 0;
158+
[replacementString appendString:@"\n"];
159+
} else {
160+
// keep Swift code compact
161+
if (![[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
162+
[replacementString appendString:@"\n"];
163+
}
164+
}
145165
}
146166

147167
for(IDEIndexSymbol *child in [((IDEIndexContainerSymbol*)symbol).children allObjects]) {
148168
if([switchContent rangeOfString:child.displayName].location == NSNotFound) {
149169
if ([[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
150170
NSString *childDisplayName = [self correctEnumConstantIfFromCocoa:[NSString stringWithFormat:@"%@",symbol] symbolName:symbolName cocoaEnumName:child.displayName];
151-
[replacementString appendString:[NSString stringWithFormat:@"case .%@: \n<#statement#>\nbreak\n\n", childDisplayName]];
171+
[replacementString appendString:[NSString stringWithFormat:@"case .%@: \n<#statement#>\n", childDisplayName]];
152172
} else {
153173
[replacementString appendString:[NSString stringWithFormat:@"case %@: {\n<#statement#>\nbreak;\n}\n", child.displayName]];
154174
}
@@ -161,16 +181,17 @@ - (BOOL)tryExpandingSwitchStatement
161181
switchContentRange = NSMakeRange(openingBracketLocation + 1, closingBracketLocation - openingBracketLocation - 1);
162182
switchContent = [textView.string substringWithRange:switchContentRange];
163183

164-
// Insert the default case if necessary
165-
if([switchContent rangeOfString:@"default"].location == NSNotFound) {
166-
if ([[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
167-
replacementString = [NSMutableString stringWithString:@"default: \nbreak\n\n"];
168-
} else {
169-
replacementString = [NSMutableString stringWithString:@"default: {\nbreak;\n}\n"];
170-
}
171-
[textView insertText:replacementString replacementRange:NSMakeRange(switchContentRange.location + switchContentRange.length, 0)];
172-
closingBracketLocation += replacementString.length;
173-
}
184+
// // Insert the default case if necessary
185+
// if([switchContent rangeOfString:@"default"].location == NSNotFound) {
186+
// if ([[SCXcodeSwitchExpander sharedSwitchExpander] isSwift]) {
187+
// replacementString = [NSMutableString stringWithString:@"default: \nbreak\n\n"];
188+
// } else {
189+
// replacementString = [NSMutableString stringWithString:@"default: {\nbreak;\n}\n"];
190+
// }
191+
// [textView insertText:replacementString replacementRange:NSMakeRange(switchContentRange.location + switchContentRange.length, 0)];
192+
// closingBracketLocation += replacementString.length;
193+
// }
194+
174195
// Re-indent everything
175196
NSRange reindentRange = NSMakeRange(openingBracketLocation, closingBracketLocation - openingBracketLocation + 2);
176197
[textView _indentInsertedTextIfNecessaryAtRange:reindentRange];

SCXcodeSwitchExpander/SCXcodeSwitchExpander-Info.plist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<key>CFBundleIconFile</key>
1010
<string></string>
1111
<key>CFBundleIdentifier</key>
12-
<string>com.stefanceriu.${PRODUCT_NAME:rfc1034identifier}</string>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
1313
<key>CFBundleInfoDictionaryVersion</key>
1414
<string>6.0</string>
1515
<key>CFBundleName</key>
@@ -39,8 +39,9 @@
3939
<string>8DC44374-2B35-4C57-A6FE-2AD66A36AAD9</string>
4040
<string>7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90</string>
4141
<string>AABB7188-E14E-4433-AD3B-5CD791EAD9A3</string>
42-
<string>0420B86A-AA43-4792-9ED0-6FE0F2B16A13</string>
42+
<string>0420B86A-AA43-4792-9ED0-6FE0F2B16A13</string>
4343
<string>CC0D0F4F-05B3-431A-8F33-F84AFCB2C651</string>
44+
<string>7265231C-39B4-402C-89E1-16167C4CC990</string>
4445
<string>F41BD31E-2683-44B8-AE7F-5F09E919790E</string>
4546
</array>
4647
<key>NSHumanReadableCopyright</key>

0 commit comments

Comments
 (0)