Xcode sometimes fails to provide assistance in understanding or writing Swift code that uses user-defined operators

Originator:jeremyw.sherman
Number:rdar://24169399 Date Originated:2016-01-13
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.2 (7C68)
Classification:UI/Usability Reproducible:Not Applicable
 
Summary:
Swift operators should have quickhelp, completion, and jump to definition. Put another way, they should be treated as first-class citizens alongside functions and methods, with the same developer assistance available for both writing and reading code using them as is available for code calling methods on a class.

Currently, option-clicking or command-double-clicking on Swift operators does nothing.

The requested enhancement is to treat these like functions, providing jump-to-definition and quick-help.

Quick-help would include the arity fixity and precedence information for the bare operator as provided at the declaration site. When used in context, it would also pull documentation for the specific definition used for the operands provided.

Jump to definition would prefer the specific version resolved, but if none has been resolved yet, it might jump to the operator declaration instead.

Autocomplete should be able to suggest `<|>` or `<|?` after typing `<|`, as well as providing info on the argument types, and once completed, function documentation should be visible, as well.

Without this support, code relying on operators, such as thoughtbot's Argo library (via its Runes project), is unnecessarily cryptic and difficult to suss out, even with Xcode's assistance, precisely because Xcode provides effectively zero assistance for understanding code using operators rather than named functions.

Steps to Reproduce:
1. Pull up the Basics page in Argo Playground after checking out and building thoughtbot/Argo.
2. Option-click `<|?` to view quick help for this operator function.


Expected Results:
3. I get the documentation and type signature for `<|?` from DecodeOptional.swift (https://github.com/thoughtbot/Argo/blob/v2.2.0/Argo/Operators/DecodeOptional.swift#L18-L21):

```
// Pull embedded optional value from JSON
public func <|? <T where T: Decodable, T == T.DecodedType>(json: JSON, keys: [String]) -> T??
```

Actual Results:
3. The text cursor ends up where I clicked. I see a blinking cursor in between the < and the |, and no quick help appears.

Version:
Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Target: x86_64-apple-darwin14.5.0

Xcode 7.2
Build version 7C68

ProductName:	Mac OS X
ProductVersion:	10.10.5
BuildVersion:	14F1509

Notes:
Without this support, I can't recommend developers rely on operators in their APIs, even where that would otherwise be appropriate. Operators as second- or third-class citizens is very unfortunate. :(

***

Jeremy Sherman
13-Jan-2016 12:07 PM

Odd. I played with it further, and managed to get quick help to appear for some operators, but not for others. Specifically, in this patch of code from the Basic page of the playground:

```swift
extension User: Decodable  {
  static func decode(j: JSON) -> Decoded<User> {
    return curry(self.init)
      <^> j <| "id"
      <*> j <| "name"
      <*> j <|? "email"
  }
}
```

The operators from DecodeDecoded.swift (<^> and <*>) _do_ show up as functions and have quick help and jump to definition support, but the operators from its sibling file DecodeOptional.swift (<| and <|?) do NOT provide that support.

Those are properly linked when I view the test code for the project, so the Playground itself appears to be having the issue. It should be reproducible by checking out the project and interacting with the Playground.

This turns this from a UI/Usability issue into a Bug. The title has been amended, but I cannot change the radar classification myself, it seems.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!