Skip to content

Commit b95f03d

Browse files
committed
Fix Swift property and add typealias support
1 parent 830d20a commit b95f03d

6 files changed

Lines changed: 22 additions & 4 deletions

File tree

VVDocumenter-Xcode/OCCategory/NSString+VVSyntax/NSString+VVSyntax.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,15 @@ -(BOOL) vv_isSwiftFunction
7676

7777
-(BOOL) vv_isSwiftEnum
7878
{
79-
return [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?enum\\s+"];
79+
return ![self vv_isSwiftProperty] && [self vv_matchesPatternRegexPattern:@"^\\s*(.*\\s+)?enum\\s+"];
8080
}
8181

8282
-(BOOL) vv_isSwiftProperty
8383
{
8484
// `let`/`var` can be in swift func, but `(` appear before `let`/`var` only
8585
// happens when `private(set)` or `internal(set)` is used
86-
return [self vv_matchesPatternRegexPattern:@"^\\s*([^(]*?)(((\\s*let|var\\s*)\\s+)|(\\(\\s*set\\s*\\)))"];
86+
// typealias is considered to share the same comment as property.
87+
return [self vv_matchesPatternRegexPattern:@"^\\s*([^(]*?)(((\\s*let|var|typealias\\s*)\\s+)|(\\(\\s*set\\s*\\)))"];
8788
}
8889

8990
@end

VVDocumenter-Xcode/OCCategory/NSString+VVTextGetter/NSString+VVTextGetter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
-(VVTextResult *) vv_textResultMatchPartWithPairOpenString:(NSString *)open
2828
closeString:(NSString *)close
2929
currentLocation:(NSInteger)location;
30+
31+
-(VVTextResult *) vv_textResultToEndOfFileCurrentLocation:(NSInteger)location;
3032
@end

VVDocumenter-Xcode/OCCategory/NSString+VVTextGetter/NSString+VVTextGetter.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ -(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open
122122
return [self textResultWithPairOpenString:open closeString:close currentLocation:location extractMatch:NO];
123123
}
124124

125+
-(VVTextResult *) vv_textResultToEndOfFileCurrentLocation:(NSInteger)location
126+
{
127+
NSRange range = NSMakeRange(location, self.length - location);
128+
VVTextResult *result = [[VVTextResult alloc] initWithRange:range string:[self substringWithRange:range]];
129+
return result;
130+
}
131+
125132
-(VVTextResult *) textResultWithPairOpenString:(NSString *)open
126133
closeString:(NSString *)close
127134
currentLocation:(NSInteger)location

VVDocumenter-Xcode/OCCategory/NSTextView+VVTextGetter/NSTextView+VVTextGetter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323

2424
-(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open closeString:(NSString *)close;
2525

26+
-(VVTextResult *) vv_textResultToEndOfFile;
2627
@end

VVDocumenter-Xcode/OCCategory/NSTextView+VVTextGetter/NSTextView+VVTextGetter.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ -(VVTextResult *) vv_textResultUntilNextString:(NSString *)findString
3636
return [self.textStorage.string vv_textResultUntilNextString:findString currentLocation:[self vv_currentCurseLocation]];
3737
}
3838

39-
4039
-(VVTextResult *) vv_textResultWithPairOpenString:(NSString *)open closeString:(NSString *)close
4140
{
4241
return [self.textStorage.string vv_textResultWithPairOpenString:open closeString:close currentLocation:[self vv_currentCurseLocation]];
4342
}
4443

44+
-(VVTextResult *) vv_textResultToEndOfFile
45+
{
46+
return [self.textStorage.string vv_textResultToEndOfFileCurrentLocation:[self vv_currentCurseLocation]];
47+
}
48+
4549
@end

VVDocumenter-Xcode/VVDocumenterManager.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,18 @@ - (void) textStorageDidChange:(NSNotification *)noti {
114114
//We just want to document the next valid line.
115115
VVTextResult *resultUntilSemiColon = [textView vv_textResultUntilNextString:@";"];
116116
VVTextResult *resultUntilBrace = [textView vv_textResultUntilNextString:@"{"];
117+
VVTextResult *resultUntilFileEnd = [textView vv_textResultToEndOfFile];
117118

118119
VVTextResult *resultToDocument = nil;
119120

120121
if (resultUntilSemiColon && resultUntilBrace) {
121122
resultToDocument = (resultUntilSemiColon.range.length < resultUntilBrace.range.length) ? resultUntilSemiColon : resultUntilBrace;
122123
} else if (resultUntilBrace) {
123124
resultToDocument = resultUntilBrace;
124-
} else {
125+
} else if (resultUntilSemiColon) {
125126
resultToDocument = resultUntilSemiColon;
127+
} else {
128+
resultToDocument = resultUntilFileEnd;
126129
}
127130

128131
//We always write document until semicolon for enum. (Maybe struct later)

0 commit comments

Comments
 (0)