Skip to content

Commit 95feec8

Browse files
author
蔡士林
committed
Fix the command make bugs
1 parent 4912b02 commit 95feec8

File tree

10 files changed

+112
-84
lines changed

10 files changed

+112
-84
lines changed

.DS_Store

0 Bytes
Binary file not shown.

BZCodeX/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>$(MARKETING_VERSION)</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>

Fly/SourceEditorCommand.swift

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,79 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
1414

1515
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void ) -> Void {
1616

17-
defer {completionHandler(nil)}
17+
defer { completionHandler(nil) }
18+
1819
// Swift or Objective-C ?
1920
let codeType = InputHandle.analyzeCodeType(codeLines: invocation.buffer.lines)
20-
if let lines = invocation.buffer.selections as? [XCSourceTextRange],
21+
22+
guard let lines = invocation.buffer.selections as? [XCSourceTextRange],
2123
let codeRange = lines.first,
22-
let codes = invocation.buffer.lines as? [String] {
24+
let codes = invocation.buffer.lines as? [String]
25+
else { return }
2326

24-
// The start line number
25-
var lineCount = codeRange.start.line
26-
// The command code
27-
var code = codes[lineCount]
28-
if code.isEmpty {return}
29-
// @do command system
30-
if let codeContext = Preprocessor.preprocess(codes: invocation.buffer.lines, commandRow: lineCount) {
31-
Processor.process(codeContext: codeContext, codes: invocation.buffer.lines)
27+
// The starting line
28+
var lineCount = codeRange.start.line
29+
// The command code
30+
var code = codes[lineCount]
31+
if code.isEmpty {return}
32+
33+
// @do command system
34+
if let codeContext = Preprocessor.preprocess(codes: invocation.buffer.lines, commandRow: lineCount) {
35+
Processor.process(codeContext: codeContext, codes: invocation.buffer.lines)
36+
} else {
37+
// Code indentation
38+
let colCount = InputHandle.indentationLength(code: code)
39+
// Clear whitespace
40+
code = code.trimmingCharacters(in: .whitespacesAndNewlines)
41+
// Command model
42+
if code.hasPrefix("#") || (code.hasPrefix("@") && codeType == .oc) {
43+
code = String(code[code.index(after: code.startIndex)...])
44+
code = regularReplace(text: code, expression: "[\\s]+", with: "")
45+
var snipLabels = (NSString(string: code).components(separatedBy: ")+") as [String]).map {$0+")"}
46+
if let lastCode = snipLabels.last {
47+
snipLabels[snipLabels.count-1] = String(lastCode[..<lastCode.index(before: lastCode.endIndex)])
48+
}
49+
let snips = snipLabels.compactMap {BaseSnip.init(label: String($0), spaceCount: colCount, codeType: codeType)}
50+
invocation.buffer.lines.removeObject(at: lineCount)
51+
for snip in snips {
52+
invocation.buffer.lines.insert(snip.code, at: lineCount)
53+
lineCount += snip.lineCount
54+
}
3255
} else {
33-
// Code indentation
34-
let colCount = InputHandle.indentationLength(code: code)
35-
// Clear whitespace
36-
code = code.trimmingCharacters(in: .whitespacesAndNewlines)
37-
// Command model
38-
if code.hasPrefix("#") || (code.hasPrefix("@") && codeType == .oc) {
39-
code = String(code[code.index(after: code.startIndex)...])
40-
code = regularReplace(text: code, expression: "[\\s]+", with: "")
41-
var snipLabels = (NSString(string: code).components(separatedBy: ")+") as [String]).map {$0+")"}
42-
if let lastCode = snipLabels.last {
43-
snipLabels[snipLabels.count-1] = String(lastCode[..<lastCode.index(before: lastCode.endIndex)])
44-
}
45-
let snips = snipLabels.compactMap {BaseSnip.init(label: String($0), spaceCount: colCount, codeType: codeType)}
46-
invocation.buffer.lines.removeObject(at: lineCount)
47-
for snip in snips {
48-
invocation.buffer.lines.insert(snip.code, at: lineCount)
49-
lineCount += snip.lineCount
56+
// Property mode
57+
let properties = decoderPropertyCode(code: code, codeType: codeType)
58+
invocation.buffer.lines.removeObject(at: lineCount)
59+
// 默认让鼠标光标选中第一个变量;
60+
var autoSelectFirstPlaceholder: XCSourceTextRange? = nil
61+
// 当生成的代码没有变量时,则将光标移动到最后一个字符后面,方便换行以及后续的操作
62+
var autoMoveCursorBehindLastChar: XCSourceTextRange? = nil
63+
for property in properties {
64+
var propertyCode: String = ""
65+
if codeType == .swift {
66+
propertyCode = generatePropertyCode(property: property, spaceCount: colCount)
5067
}
51-
} else {
52-
// Property mode
53-
let properties = decoderPropertyCode(code: code, codeType: codeType)
54-
invocation.buffer.lines.removeObject(at: lineCount)
55-
// 默认让鼠标光标选中第一个变量
56-
var autoSelectFirstPlaceholder: XCSourceTextRange? = nil
57-
// 当生成的代码没有变量时,则将光标移动到最后一个字符后面,方便换行以及后续的操作
58-
var autoMoveCursorBehindLastChar: XCSourceTextRange? = nil
59-
for property in properties {
60-
var propertyCode: String = ""
61-
if codeType == .swift {
62-
propertyCode = generatePropertyCode(property: property, spaceCount: colCount)
63-
}
64-
if codeType == .oc {
65-
propertyCode = generateOCPropertyCode(property: property, spaceCount: colCount)
66-
}
67-
if autoSelectFirstPlaceholder == nil, let range = regularMatchRange(text: propertyCode, expression: "<#(.*)?#>").first {
68-
autoSelectFirstPlaceholder = XCSourceTextRange(start: XCSourceTextPosition(line: lineCount,
69-
column: range.location),
70-
end: XCSourceTextPosition(line: lineCount,
71-
column: range.location + range.length))
72-
}
73-
invocation.buffer.lines.insert(propertyCode, at: lineCount)
74-
autoMoveCursorBehindLastChar = XCSourceTextRange(start: XCSourceTextPosition(line: lineCount,
75-
column: propertyCode.count),
76-
end: XCSourceTextPosition(line: lineCount,
77-
column: propertyCode.count))
78-
lineCount += property.lineCount
68+
if codeType == .oc {
69+
propertyCode = generateOCPropertyCode(property: property, spaceCount: colCount)
7970
}
80-
if let selectedRange = autoSelectFirstPlaceholder {
81-
invocation.buffer.selections.removeAllObjects()
82-
invocation.buffer.selections.add(selectedRange)
83-
} else if let selectedRange = autoMoveCursorBehindLastChar {
84-
invocation.buffer.selections.removeAllObjects()
85-
invocation.buffer.selections.add(selectedRange)
71+
if autoSelectFirstPlaceholder == nil, let range = regularMatchRange(text: propertyCode, expression: "<#(.*)?#>").first {
72+
autoSelectFirstPlaceholder = XCSourceTextRange(start: XCSourceTextPosition(line: lineCount,
73+
column: range.location),
74+
end: XCSourceTextPosition(line: lineCount,
75+
column: range.location + range.length))
8676
}
77+
invocation.buffer.lines.insert(propertyCode, at: lineCount)
78+
autoMoveCursorBehindLastChar = XCSourceTextRange(start: XCSourceTextPosition(line: lineCount,
79+
column: propertyCode.count),
80+
end: XCSourceTextPosition(line: lineCount,
81+
column: propertyCode.count))
82+
lineCount += property.lineCount
83+
}
84+
if let selectedRange = autoSelectFirstPlaceholder {
85+
invocation.buffer.selections.removeAllObjects()
86+
invocation.buffer.selections.add(selectedRange)
87+
} else if let selectedRange = autoMoveCursorBehindLastChar {
88+
invocation.buffer.selections.removeAllObjects()
89+
invocation.buffer.selections.add(selectedRange)
8790
}
8891
}
8992
}

FlyCoding.xcodeproj/project.pbxproj

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@
8080
8EAC3B0322EAD8BC00A1B896 /* FCCore.swift in Headers */ = {isa = PBXBuildFile; fileRef = 8EAC3AA822EAD66900A1B896 /* FCCore.swift */; settings = {ATTRIBUTES = (Public, ); }; };
8181
8EAC3B0422EAD8DC00A1B896 /* BZCodeX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EAC3A2322EAD40500A1B896 /* BZCodeX.framework */; };
8282
C47CB61D23D1531800187DCB /* GenerateViewTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C47CB61C23D1531800187DCB /* GenerateViewTest.swift */; };
83-
C47CB62523D159DE00187DCB /* ui_swift.plist in Resources */ = {isa = PBXBuildFile; fileRef = C47CB62223D159DE00187DCB /* ui_swift.plist */; };
84-
C47CB62623D159DE00187DCB /* ui_universal.plist in Resources */ = {isa = PBXBuildFile; fileRef = C47CB62323D159DE00187DCB /* ui_universal.plist */; };
85-
C47CB62723D159DE00187DCB /* ui_oc.plist in Resources */ = {isa = PBXBuildFile; fileRef = C47CB62423D159DE00187DCB /* ui_oc.plist */; };
83+
C4E7D45323D1A19A0021EC4F /* ui_universal.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45023D1A19A0021EC4F /* ui_universal.plist */; };
84+
C4E7D45423D1A19A0021EC4F /* ui_oc.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45123D1A19A0021EC4F /* ui_oc.plist */; };
85+
C4E7D45523D1A19A0021EC4F /* ui_swift.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45223D1A19A0021EC4F /* ui_swift.plist */; };
86+
C4E7D45F23D1A3C60021EC4F /* ui_universal.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45C23D1A3C60021EC4F /* ui_universal.plist */; };
87+
C4E7D46023D1A3C60021EC4F /* ui_oc.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45D23D1A3C60021EC4F /* ui_oc.plist */; };
88+
C4E7D46123D1A3C60021EC4F /* ui_swift.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4E7D45E23D1A3C60021EC4F /* ui_swift.plist */; };
8689
/* End PBXBuildFile section */
8790

8891
/* Begin PBXContainerItemProxy section */
@@ -194,9 +197,12 @@
194197
8EEAA80022DC983400335A60 /* FlyCoding.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FlyCoding.entitlements; sourceTree = "<group>"; };
195198
8EEAA80122DC983C00335A60 /* Fly.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Fly.entitlements; sourceTree = "<group>"; };
196199
C47CB61C23D1531800187DCB /* GenerateViewTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateViewTest.swift; sourceTree = "<group>"; };
197-
C47CB62223D159DE00187DCB /* ui_swift.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_swift.plist; sourceTree = "<group>"; };
198-
C47CB62323D159DE00187DCB /* ui_universal.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_universal.plist; sourceTree = "<group>"; };
199-
C47CB62423D159DE00187DCB /* ui_oc.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_oc.plist; sourceTree = "<group>"; };
200+
C4E7D45023D1A19A0021EC4F /* ui_universal.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_universal.plist; sourceTree = "<group>"; };
201+
C4E7D45123D1A19A0021EC4F /* ui_oc.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_oc.plist; sourceTree = "<group>"; };
202+
C4E7D45223D1A19A0021EC4F /* ui_swift.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_swift.plist; sourceTree = "<group>"; };
203+
C4E7D45C23D1A3C60021EC4F /* ui_universal.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_universal.plist; sourceTree = "<group>"; };
204+
C4E7D45D23D1A3C60021EC4F /* ui_oc.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_oc.plist; sourceTree = "<group>"; };
205+
C4E7D45E23D1A3C60021EC4F /* ui_swift.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ui_swift.plist; sourceTree = "<group>"; };
200206
/* End PBXFileReference section */
201207

202208
/* Begin PBXFrameworksBuildPhase section */
@@ -267,8 +273,8 @@
267273
8E8B8D5D1F710DC1002EBF80 /* ViewController.swift */,
268274
8E8B8D5F1F710DC1002EBF80 /* Assets.xcassets */,
269275
8E8B8D611F710DC1002EBF80 /* Main.storyboard */,
276+
C4E7D45B23D1A3C60021EC4F /* Resources */,
270277
8E8B8D641F710DC1002EBF80 /* Info.plist */,
271-
C47CB62923D159FB00187DCB /* Resources */,
272278
);
273279
path = FlyCoding;
274280
sourceTree = "<group>";
@@ -288,6 +294,7 @@
288294
8E8B8D751F710DEA002EBF80 /* SourceEditorExtension.swift */,
289295
8E8B8D771F710DEA002EBF80 /* SourceEditorCommand.swift */,
290296
8E8B8D791F710DEA002EBF80 /* Info.plist */,
297+
C4E7D44F23D1A19A0021EC4F /* Resources */,
291298
8E8B8D731F710DEA002EBF80 /* Supporting Files */,
292299
);
293300
path = Fly;
@@ -438,16 +445,27 @@
438445
path = RegularExpression;
439446
sourceTree = "<group>";
440447
};
441-
C47CB62923D159FB00187DCB /* Resources */ = {
448+
C4E7D44F23D1A19A0021EC4F /* Resources */ = {
442449
isa = PBXGroup;
443450
children = (
444-
C47CB62423D159DE00187DCB /* ui_oc.plist */,
445-
C47CB62223D159DE00187DCB /* ui_swift.plist */,
446-
C47CB62323D159DE00187DCB /* ui_universal.plist */,
451+
C4E7D45023D1A19A0021EC4F /* ui_universal.plist */,
452+
C4E7D45123D1A19A0021EC4F /* ui_oc.plist */,
453+
C4E7D45223D1A19A0021EC4F /* ui_swift.plist */,
447454
);
448455
path = Resources;
449456
sourceTree = "<group>";
450457
};
458+
C4E7D45B23D1A3C60021EC4F /* Resources */ = {
459+
isa = PBXGroup;
460+
children = (
461+
C4E7D45C23D1A3C60021EC4F /* ui_universal.plist */,
462+
C4E7D45D23D1A3C60021EC4F /* ui_oc.plist */,
463+
C4E7D45E23D1A3C60021EC4F /* ui_swift.plist */,
464+
);
465+
name = Resources;
466+
path = Fly/Resources;
467+
sourceTree = SOURCE_ROOT;
468+
};
451469
/* End PBXGroup section */
452470

453471
/* Begin PBXHeadersBuildPhase section */
@@ -636,10 +654,10 @@
636654
buildActionMask = 2147483647;
637655
files = (
638656
8E055F8A2303D872001C81F9 /* README.md in Resources */,
639-
C47CB62623D159DE00187DCB /* ui_universal.plist in Resources */,
640-
C47CB62723D159DE00187DCB /* ui_oc.plist in Resources */,
641657
8E8B8D601F710DC1002EBF80 /* Assets.xcassets in Resources */,
642-
C47CB62523D159DE00187DCB /* ui_swift.plist in Resources */,
658+
C4E7D46123D1A3C60021EC4F /* ui_swift.plist in Resources */,
659+
C4E7D46023D1A3C60021EC4F /* ui_oc.plist in Resources */,
660+
C4E7D45F23D1A3C60021EC4F /* ui_universal.plist in Resources */,
643661
8E8B8D631F710DC1002EBF80 /* Main.storyboard in Resources */,
644662
);
645663
runOnlyForDeploymentPostprocessing = 0;
@@ -648,6 +666,9 @@
648666
isa = PBXResourcesBuildPhase;
649667
buildActionMask = 2147483647;
650668
files = (
669+
C4E7D45423D1A19A0021EC4F /* ui_oc.plist in Resources */,
670+
C4E7D45323D1A19A0021EC4F /* ui_universal.plist in Resources */,
671+
C4E7D45523D1A19A0021EC4F /* ui_swift.plist in Resources */,
651672
);
652673
runOnlyForDeploymentPostprocessing = 0;
653674
};
@@ -888,13 +909,13 @@
888909
CODE_SIGN_IDENTITY = "Apple Development";
889910
CODE_SIGN_STYLE = Automatic;
890911
COMBINE_HIDPI_IMAGES = YES;
891-
CURRENT_PROJECT_VERSION = 14;
912+
CURRENT_PROJECT_VERSION = 16;
892913
DEVELOPMENT_TEAM = 7467638S34;
893914
ENABLE_HARDENED_RUNTIME = YES;
894915
INFOPLIST_FILE = FlyCoding/Info.plist;
895916
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
896917
MACOSX_DEPLOYMENT_TARGET = 10.11;
897-
MARKETING_VERSION = 2.1;
918+
MARKETING_VERSION = 2.2.1;
898919
PRODUCT_BUNDLE_IDENTIFIER = com.ssbun.www.FlyCoding;
899920
PRODUCT_NAME = "$(TARGET_NAME)";
900921
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -911,13 +932,13 @@
911932
CODE_SIGN_IDENTITY = "Apple Development";
912933
CODE_SIGN_STYLE = Automatic;
913934
COMBINE_HIDPI_IMAGES = YES;
914-
CURRENT_PROJECT_VERSION = 14;
935+
CURRENT_PROJECT_VERSION = 16;
915936
DEVELOPMENT_TEAM = 7467638S34;
916937
ENABLE_HARDENED_RUNTIME = YES;
917938
INFOPLIST_FILE = FlyCoding/Info.plist;
918939
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
919940
MACOSX_DEPLOYMENT_TARGET = 10.11;
920-
MARKETING_VERSION = 2.1;
941+
MARKETING_VERSION = 2.2.1;
921942
PRODUCT_BUNDLE_IDENTIFIER = com.ssbun.www.FlyCoding;
922943
PRODUCT_NAME = "$(TARGET_NAME)";
923944
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -972,7 +993,7 @@
972993
CODE_SIGN_IDENTITY = "";
973994
CODE_SIGN_STYLE = Automatic;
974995
COMBINE_HIDPI_IMAGES = YES;
975-
CURRENT_PROJECT_VERSION = 1;
996+
CURRENT_PROJECT_VERSION = 3;
976997
DEFINES_MODULE = YES;
977998
DEVELOPMENT_TEAM = 7467638S34;
978999
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -984,8 +1005,10 @@
9841005
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
9851006
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
9861007
MACOSX_DEPLOYMENT_TARGET = 10.11;
1008+
MARKETING_VERSION = 2.2.1;
9871009
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
9881010
MTL_FAST_MATH = YES;
1011+
OTHER_LDFLAGS = "-fprofile-instr-generate";
9891012
PRODUCT_BUNDLE_IDENTIFIER = com.ssbun.www.BZCodeX;
9901013
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
9911014
SKIP_INSTALL = YES;
@@ -1004,7 +1027,7 @@
10041027
CODE_SIGN_IDENTITY = "";
10051028
CODE_SIGN_STYLE = Automatic;
10061029
COMBINE_HIDPI_IMAGES = YES;
1007-
CURRENT_PROJECT_VERSION = 1;
1030+
CURRENT_PROJECT_VERSION = 3;
10081031
DEFINES_MODULE = YES;
10091032
DEVELOPMENT_TEAM = 7467638S34;
10101033
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -1016,7 +1039,9 @@
10161039
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
10171040
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
10181041
MACOSX_DEPLOYMENT_TARGET = 10.11;
1042+
MARKETING_VERSION = 2.2.1;
10191043
MTL_FAST_MATH = YES;
1044+
OTHER_LDFLAGS = "-fprofile-instr-generate";
10201045
PRODUCT_BUNDLE_IDENTIFIER = com.ssbun.www.BZCodeX;
10211046
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
10221047
SKIP_INSTALL = YES;

FlyCoding/.DS_Store

0 Bytes
Binary file not shown.

FlyCoding/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Cocoa
1010

1111
class ViewController: NSViewController {
12-
12+
1313
override func viewDidLoad() {
1414
super.viewDidLoad()
1515

0 commit comments

Comments
 (0)