Autocomplete suggests Code Snippets within documentation of some Swift protocol declarations.

Number:rdar://FB9776143 Date Originated:11/22/2021
Status:Open Resolved:
Product:Xcode Product Version:13.1
Classification:Unexpected Behavior Reproducible:Yes
When writing documentation using triple forward slashes within the scope of a Swift protocol, if the documentation follows a function declaration, and if the user has Code Snippets which use the "Code Expression" scope availability, those code snippets will be suggested by autocomplete after each whitespace input on the documentation line(s).

Speculation: Because functions may be declared within protocols without their normally required scope (`{ }`), the autocomplete engine continues to run under the context of a "Code Expression" until the next declaration of a var within the protocol, or until the protocol's scope is closed.

The attached Playground minimally reproduces this behavior. Attempting to input whitespace (or use Esc to manually bring up autocomplete) on either of the documentation lines annotated therein as producing the unexpected behavior will show the autocomplete suggestion list for the code snippets.

Known workarounds: Using block syntax (`/** docs */`) for documentation, or removing the "Code Expression" scope from the snippet's availability, avoids the unexpected autocompletion behavior.

Please list the steps you took to reproduce the issue:
Prerequisite: At least one Code Snippet defined which uses "Code Expression" as its scope availability.

1. Declare a swift Protocol
2. Declare a function within the protocol
3. Begin a line of documentation using triple forward slashes after the function declaration (still within the protocol scope)

What did you expect to happen?
I expect nothing to be suggested by autocomplete while writing documentation in any context.

What actually happened?
Autocomplete will suggest any code snippets which use the "Code Expression" scope availability after each new whitespace input within the line(s) of documentation following the function.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!