lionheart / openradar-mirror

A mirror of radars pulled from http://openradar.me/.
246 stars 17 forks source link

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

Open openradar-mirror opened 8 years ago

openradar-mirror commented 8 years ago

Description

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:

  1. 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:

  1. 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:

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.

Product Version: Xcode 7.2 (7C68) Created: 2016-01-13T16:41:43.228700 Originated: 2016-01-13T00:00:00 Open Radar Link: http://www.openradar.me/24169399

openradar-mirror commented 8 years ago

Modified: 2016-01-13T17:08:22.769610

openradar-mirror commented 8 years ago

Modified: 2016-01-13T17:08:22.769610