-
Notifications
You must be signed in to change notification settings - Fork 314
Don’t include local variables in document symbols #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don’t include local variables in document symbols #973
Conversation
@swift-ci Please test |
e90d614
to
46328c9
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Fixes swiftlang#962 rdar://117810784
switch piece { | ||
case .lineComment(let commentText), .blockComment(let commentText): | ||
let trimmedComment = commentText.trimmingPrefix(while: { $0 == "/" || $0 == "*" || $0 == " " }) | ||
if trimmedComment.starts(with: "MARK: ") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day we'll get to use nice things (trimmingPrefix
). How about:
fileprivate let MARK_PREFIX = "MARK: "
...
if trimmedComment.starts(with: MARK_PREFIX) {
let markText = trimmedComment.dropFirst(MARK_PREFIX.count)
...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea 👍🏽
switch piece { | ||
case .lineComment: | ||
documentSymbolName = markText.trimmingCharacters(in: CharacterSet(["/", "*"]).union(.whitespaces)) | ||
case .blockComment: documentSymbolName = markText.trimmingCharacters(in: .whitespaces) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have something like:
/****************
* MARK: foobar *
****************/
😅
Any reason in particular not to just always trim /
and*
(which you could then move up into trimmedComment
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did that
if self.parent?.is(MemberBlockItemSyntax.self) ?? false { | ||
return true | ||
} else if let codeBlockItem = self.parent?.as(CodeBlockItemSyntax.self), | ||
codeBlockItem.parent?.parent?.is(SourceFileSyntax.self) ?? false | ||
{ | ||
return true | ||
} else { | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really find that easier to read than eg.
if self.parent?.is(MemberBlockItemSyntax.self) ?? false {
return true
}
if let codeBlockItem = self.parent?.as(CodeBlockItemSyntax.self),
codeBlockItem.parent?.parent?.is(SourceFileSyntax.self) ?? false {
return true
}
return false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t have super strong opinions. Changed it
func trimmingPrefix(while condition: (Character) -> Bool) -> Substring { | ||
var result = self[...] | ||
while let first = result.first, condition(first) { | ||
result = result[result.index(after: result.startIndex)...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = result[result.index(after: result.startIndex)...] | |
result = result.dropFirst() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also given my comment above, you could add the other version of trimmingPrefix
that takes a Sequence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just removed it and am now trimming /
, *
and whitespace on either side of the comment.
46328c9
to
fe919c4
Compare
Fixes swiftlang#963 rdar://117811210
fe919c4
to
b85f3af
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test Windows |
Fixes #962
rdar://117810784
While at it, also include
// MARK:
comments in the document symbols request.Fixes #963
rdar://117811210