-
Notifications
You must be signed in to change notification settings - Fork 328
Separate signature and parameter documentation using swift-markdown #2292
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
base: main
Are you sure you want to change the base?
Separate signature and parameter documentation using swift-markdown #2292
Conversation
let parametersPrefix = "parameters:" | ||
let headingContent = headingText.string.trimmingCharacters(in: .whitespaces) | ||
|
||
guard headingContent.lowercased().hasPrefix(parametersPrefix) else { |
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.
We check for a prefix instead of headingContent == parametersPrefix
to match the behavior in Xcode.
b94a4a3
to
da27530
Compare
swiftlang/swift-markdown#237 @swift-ci please test Windows |
da27530
to
0ac09ca
Compare
swiftlang/swift-markdown#237 @swift-ci please test Windows |
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.
Very cool. I would have preferred to use docc here but maybe this is the simpler approach.
Do you know how hard it would be to get the symbol graph for a completion item, similar to how we get the documentation comment of a completion item. I’m just wondering that maybe it wouldn’t be all to hard to do so. But I haven’t tried.
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
@ahoppen That should be doable using a cursor info request provided the USR I think. There are other things that DocC needs (and I'm not entirely aware of what each of them is used for/represents). Besides, conversion from DocC response to markdown would require implementing a renderer within SourceKit-LSP (maybe that should be done in the long-term anyway but I'm not sure if it fits in the timeline here). I can attempt to use DocC again and see how it goes though. Last time I tried it wasn't a very pleasant experience. 😅 QQ, tests are failing on Windows due to issues with |
let name = String(components[0]).trimmingCharacters(in: .whitespaces) | ||
guard !name.isEmpty else { | ||
return nil | ||
} |
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.
What about raw identifiers e.g - `foo bar`: hello
?
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.
Added, can you please recheck? 🙏🏼
@ahoppen @hamishknight I added the discussion for why we didn't use swift-docc, eliminated mutable state in |
swiftlang/swift#84302 @swift-ci please test Windows |
Definitely out-of-scope for this PR, I would just like to explore future options so we can decide whether it is something we want to investigate in the future and file an actionable issue. Do you know if it would be possible to get the symbol graph of a completion item without having to go through a cursor info (@hamishknight, maybe you know)? Because if it was, I think the main thing to do would be to implement the symbol graph to Markdown renderer, which while being a bit of work might come in handy in the future anyway. |
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.
Thanks for adding the test cases and refining this. I have a few more comments on the implementation, the behavior looks great to me.
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
Tests/SourceKitLSPTests/ParametersDocumentationExtractorTests.swift
Outdated
Show resolved
Hide resolved
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’ve got a few more nitpicky comments, otherwise this looks great to me now.
Sources/SwiftLanguageService/ExtractParametersDocumentation.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ExtractParametersDocumentation.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ExtractParametersDocumentation.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftLanguageService/ParametersDocumentationExtractor.swift
Outdated
Show resolved
Hide resolved
…tTextContent parameter
6f583dd
to
668da58
Compare
swiftlang/swift-markdown#237 @swift-ci please test Windows |
1 similar comment
swiftlang/swift-markdown#237 @swift-ci please test Windows |
swiftlang/swift#84302 @swift-ci please test Windows |
@ahoppen @hamishknight @bnbarham The Windows build is still failing even after linking
After some investigation, it can't find Do you have any specific suggestions here? Thanks in advance. |
Ah looks like there's a typo in build.ps1: Should be |
swiftlang/swift#84302 @swift-ci please test Windows |
swiftlang/swift#84302 @swift-ci please test macOS |
Description
Separate signature and parameter documentation by parsing the documentation returned by sourcekitd using swift-markdown and extracting the parameter documentation.
Alternatives considered
The parameter extraction implementation is almost ported from the implementation in the Swift compiler codebase. The problem with doing that in the Swift compiler codebase is that once you parse a the comment as markdown into a
Document
you cannot easily convert it back into markdown (we'd need to write our own markdown formatter). Besides, cmark doesn't handle Doxygen commands.We considered using swift-docc but we faced some problems with it:
Implementing this using swift-markdown allows us to easily parse the comment, process it, convert it back to markdown and it also provides minimal parsing for Doxygen commands (we're only interested in
\param
) allowing us to use the same implementation for Clang-based declarations too.Although this approach involves code duplication, it's works for our simple use case and we can probably improve it a bit in the future.
Dependencies