Repository: CodeEditApp/CodeEdit
File: CodeEdit/Documents/CodeEditDocumentController.swift (Swift)

Code before:

            print(document, documentWasAlreadyOpen)
        }, cancelHandler: {})
    }

    override func openDocument(withContentsOf url: URL,
                               display displayDocument: Bool,
                               completionHandler: @escaping (NSDocument?, Bool, Error?) -> Void) {
        super.openDocument(withContentsOf: url, display: displayDocument) { document, documentWasAlreadyOpen, error in

            if let document = document {
                self.addDocument(document)
            }
            self.updateRecent(url)
            completionHandler(document, documentWasAlreadyOpen, error)
        }
    }

    override func clearRecentDocuments(_ sender: Any?) {
        super.clearRecentDocuments(sender)
        UserDefaults.standard.set([], forKey: "recentProjectPaths")
    }
}

extension NSDocumentController {
    func openDocument(completionHandler: @escaping (NSDocument?, Bool) -> Void, cancelHandler: @escaping () -> Void) {
        let dialog = NSOpenPanel()

        dialog.title = "Open Workspace or File"
        dialog.showsResizeIndicator = true
        dialog.showsHiddenFiles = false
        dialog.canChooseFiles = true
        dialog.canChooseDirectories = true

        dialog.begin { result in
            if result ==  NSApplication.ModalResponse.OK, let url = dialog.url {
                self.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
                    if let error = error {
                        NSAlert(error: error).runModal()
                        return
                    }

                    guard let document = document else {
                        let alert = NSAlert()
                        alert.messageText = NSLocalizedString("Failed to get document",
                                                              comment: "Failed to get document")
                        alert.runModal()
                        return
                    }
                    self.updateRecent(url)
                    completionHandler(document, documentWasAlreadyOpen)

Review comment (suggestion):
Instead of

```swift
func openDocument(completionHandler: @escaping (NSDocument?, Bool) -> Void, cancelHandler: @escaping () -> Void) {}
```

consider using a blank or `onCompletion` label for the first argument and `onCancel` for the second one.

```swift
func openDocument(_ completionHandler: @escaping (NSDocument?, Bool) -> Void, onCancel: @escaping () -> Void) {}
```

Code after:

            print(document, documentWasAlreadyOpen)
        }, onCancel: {})
    }

    override func openDocument(withContentsOf url: URL,
                               display displayDocument: Bool,
                               completionHandler: @escaping (NSDocument?, Bool, Error?) -> Void) {
        super.openDocument(withContentsOf: url, display: displayDocument) { document, documentWasAlreadyOpen, error in

            if let document = document {
                self.addDocument(document)
            }
            self.updateRecent(url)
            completionHandler(document, documentWasAlreadyOpen, error)
        }
    }

    override func clearRecentDocuments(_ sender: Any?) {
        super.clearRecentDocuments(sender)
        UserDefaults.standard.set([], forKey: "recentProjectPaths")
    }
}

extension NSDocumentController {
    func openDocument(onCompletion: @escaping (NSDocument?, Bool) -> Void, onCancel: @escaping () -> Void) {
        let dialog = NSOpenPanel()

        dialog.title = "Open Workspace or File"
        dialog.showsResizeIndicator = true
        dialog.showsHiddenFiles = false
        dialog.canChooseFiles = true
        dialog.canChooseDirectories = true

        dialog.begin { result in
            if result ==  NSApplication.ModalResponse.OK, let url = dialog.url {
                self.openDocument(withContentsOf: url, display: true) { document, documentWasAlreadyOpen, error in
                    if let error = error {
                        NSAlert(error: error).runModal()
                        return
                    }

                    guard let document = document else {
                        let alert = NSAlert()
                        alert.messageText = NSLocalizedString("Failed to get document",
                                                              comment: "Failed to get document")
                        alert.runModal()
                        return
                    }
                    self.updateRecent(url)
                    onCompletion(document, documentWasAlreadyOpen)