ronantakizawa/codereview-bench huggingface dataset:
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/QuickOpen/ViewModels/QuickOpenViewModel.swift (Swift)

Code before:
//
//  QuickOpenState.swift
//  CodeEditModules/QuickOpen
//
//  Created by Marco Carnevali on 05/04/22.
//

import Combine
import Foundation

final class QuickOpenViewModel: ObservableObject {

    @Published
    var openQuicklyQuery: String = ""

    @Published
    var openQuicklyFiles: [CEWorkspaceFile] = []

    @Published
    var isShowingOpenQuicklyFiles: Bool = false

    let fileURL: URL

    private let queue = DispatchQueue(label: "com.codeedit.CodeEdit.quickOpen.searchFiles")

    init(fileURL: URL) {
        self.fileURL = fileURL
    }

    func fetchOpenQuickly() {
        guard openQuicklyQuery != "" else {
            openQuicklyFiles = []
            self.isShowingOpenQuicklyFiles = !openQuicklyFiles.isEmpty
            return
        }

        queue.async { [weak self] in
            guard let self else { return }
            let enumerator = FileManager.default.enumerator(
                at: self.fileURL,
                includingPropertiesForKeys: [
                    .isRegularFileKey
                ],
                options: [
                    .skipsHiddenFiles,
                    .skipsPackageDescendants
                ]
            )
            if let filePaths = enumerator?.allObjects as? [URL] {

Review comment (suggestion):
```suggestion
    private let queue = DispatchQueue(label: "app.codeedit.CodeEdit.quickOpen.searchFiles")
```

Code after:
//
//  QuickOpenState.swift
//  CodeEditModules/QuickOpen
//
//  Created by Marco Carnevali on 05/04/22.
//

import Combine
import Foundation

final class QuickOpenViewModel: ObservableObject {

    @Published
    var openQuicklyQuery: String = ""

    @Published
    var openQuicklyFiles: [CEWorkspaceFile] = []

    @Published
    var isShowingOpenQuicklyFiles: Bool = false

    let fileURL: URL

    private let queue = DispatchQueue(label: "app.codeedit.CodeEdit.quickOpen.searchFiles")

    init(fileURL: URL) {
        self.fileURL = fileURL
    }

    func fetchOpenQuickly() {
        guard openQuicklyQuery != "" else {
            openQuicklyFiles = []
            self.isShowingOpenQuicklyFiles = !openQuicklyFiles.isEmpty
            return
        }

        queue.async { [weak self] in
            guard let self else { return }
            let enumerator = FileManager.default.enumerator(
                at: self.fileURL,
                includingPropertiesForKeys: [
                    .isRegularFileKey
                ],
                options: [
                    .skipsPackageDescendants
                ]
            )
            if let filePaths = enumerator?.allObjects as? [URL] {
                /// removes all filePaths which aren't regular files
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/QuickOpen/Views/QuickOpenPreviewView.swift (Swift)

Code before:
//
//  QuickOpenPreviewView.swift
//  CodeEditModules/QuickOpen
//
//  Created by Pavel Kasila on 20.03.22.
//

import SwiftUI

struct QuickOpenPreviewView: View {

    private let queue = DispatchQueue(label: "com.codeedit.CodeEdit.quickOpen.preview")
    private let item: CEWorkspaceFile

    @ObservedObject
    var document: CodeFileDocument

    init(
        item: CEWorkspaceFile
    ) {
        self.item = item
        let doc = try? CodeFileDocument(
            for: item.url,
            withContentsOf: item.url,
            ofType: "public.source-code"
        )
        self._document = .init(wrappedValue: doc ?? .init())
    }

    var body: some View {
        if let url = document.fileURL {
            if url.isImage() {
                if let image = NSImage(contentsOf: url) {
                    GeometryReader { proxy in
                        if image.size.width > proxy.size.width || image.size.height > proxy.size.height {
                            OtherFileView(document)
                        } else {

Review comment (suggestion):
```suggestion
    private let queue = DispatchQueue(label: "app.codeedit.CodeEdit.quickOpen.preview")
```

Code after:
//
//  QuickOpenPreviewView.swift
//  CodeEditModules/QuickOpen
//
//  Created by Pavel Kasila on 20.03.22.
//

import SwiftUI

struct QuickOpenPreviewView: View {

    private let queue = DispatchQueue(label: "app.codeedit.CodeEdit.quickOpen.preview")
    private let item: CEWorkspaceFile

    @ObservedObject
    var document: CodeFileDocument

    init(
        item: CEWorkspaceFile
    ) {
        self.item = item
        let doc = try? CodeFileDocument(
            for: item.url,
            withContentsOf: item.url,
            ofType: "public.source-code"
        )
        self._document = .init(wrappedValue: doc ?? .init())
    }

    var body: some View {
        if let url = document.fileURL {
            if url.isImage() {
                if let image = NSImage(contentsOf: url) {
                    GeometryReader { proxy in
                        if image.size.width > proxy.size.width || image.size.height > proxy.size.height {
                            OtherFileView(document)
                        } else {
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Settings/Pages/GeneralSettings/GeneralSettingsView.swift (Swift)

Code before:
//
//  GeneralSettingsView.swift
//  CodeEdit
//
//  Created by Austin Condiff on 4/1/23.
//

import SwiftUI

/// A view that implements the `General` settings page
struct GeneralSettingsView: View {
    private let inputWidth: Double = 160
    private let textEditorWidth: Double = 220
    private let textEditorHeight: Double = 30

    @EnvironmentObject var updater: SoftwareUpdater
    @FocusState private var focusedField: UUID?

    @AppSettings(\.general) var settings

    @State private var openInCodeEdit: Bool = true

    init() {
        guard let defaults = UserDefaults.init(
            suiteName: "com.codeedit.CodeEdit.shared"
        ) else {
            print("Failed to get/init shared defaults")
            return
        }

        self.openInCodeEdit = defaults.bool(forKey: "enableOpenInCE")
    }

    var body: some View {
        SettingsForm {
            Section {
                appearance
                fileIconStyle
                tabBarStyle
                navigatorTabBarPosition
                inspectorTabBarPosition
            }
            Section {
                showIssues
                showLiveIssues
            }
            Section {
                autoSave
                revealFileOnFocusChangeToggle
                reopenBehavior

Review comment (suggestion):
```suggestion
            suiteName: "app.codeedit.CodeEdit.shared"
```

Code after:
//
//  GeneralSettingsView.swift
//  CodeEdit
//
//  Created by Austin Condiff on 4/1/23.
//

import SwiftUI

/// A view that implements the `General` settings page
struct GeneralSettingsView: View {
    private let inputWidth: Double = 160
    private let textEditorWidth: Double = 220
    private let textEditorHeight: Double = 30

    @EnvironmentObject var updater: SoftwareUpdater
    @FocusState private var focusedField: UUID?

    @AppSettings(\.general) var settings

    @State private var openInCodeEdit: Bool = true

    init() {
        guard let defaults = UserDefaults.init(
            suiteName: "app.codeedit.CodeEdit.shared"
        ) else {
            print("Failed to get/init shared defaults")
            return
        }

        self.openInCodeEdit = defaults.bool(forKey: "enableOpenInCE")
    }

    var body: some View {
        SettingsForm {
            Section {
                appearance
                fileIconStyle
                tabBarStyle
                navigatorTabBarPosition
                inspectorTabBarPosition
            }
            Section {
                showIssues
                showLiveIssues
            }
            Section {
                autoSave
                revealFileOnFocusChangeToggle
                reopenBehavior
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/WindowCommands/NavigateCommands.swift (Swift)

Code before:
//
//  NavigateCommands.swift
//  CodeEdit
//
//  Created by Wouter Hennen on 13/03/2023.
//

import SwiftUI

struct NavigateCommands: Commands {
    var body: some Commands {
        CommandMenu("Navigate") {
            Group {
                Button("Reveal in Project Navigator") {
                    NSApp.sendAction(#selector(ProjectNavigatorViewController.revealFile(_:)), to: nil, from: nil)
                }
                .keyboardShortcut("j", modifiers: [.shift, .command])

                Button("Reveal Changes in Navigator") {

                }
                .keyboardShortcut("m", modifiers: [.shift, .command])

                Button("Open in Next Editor") {

                }
                .keyboardShortcut(",", modifiers: [.option, .command])

                Button("Open in...") {

                }

                Divider()

                Button("Show Previous Tab") {

                }

                Button("Show Next Tab") {

                }

                Divider()

Review comment (suggestion):
If you could enable this command by adding `.disabled` to the other buttons in NavigateCommands that'd be great. They're only disabled because there was no implementation.

Code after:
//
//  NavigateCommands.swift
//  CodeEdit
//
//  Created by Wouter Hennen on 13/03/2023.
//

import SwiftUI

struct NavigateCommands: Commands {

    @FocusedObject var tabGroup: TabGroupData?

    var body: some Commands {
        CommandMenu("Navigate") {
            Group {
                Button("Reveal in Project Navigator") {
                    NSApp.sendAction(#selector(ProjectNavigatorViewController.revealFile(_:)), to: nil, from: nil)
                }
                .keyboardShortcut("j", modifiers: [.shift, .command])

                Button("Reveal Changes in Navigator") {

                }
                .keyboardShortcut("m", modifiers: [.shift, .command])
                .disabled(true)

                Button("Open in Next Editor") {

                }
                .keyboardShortcut(",", modifiers: [.option, .command])
                .disabled(true)

                Button("Open in...") {

                }
                .disabled(true)

                Divider()

            }

            Group {
Repository: CodeEditApp/CodeEdit
File: CodeEdit/WindowSplitView.swift (Swift)

Code before:
//
//  WindowSplitView.swift
//  CodeEdit
//
//  Created by Wouter Hennen on 18/06/2023.
//

import SwiftUI

struct WindowSplitView: View {
    @StateObject var workspace: WorkspaceDocument
    @StateObject var navigatorViewModel = NavigatorSidebarViewModel()
    @State var visibility: NavigationSplitViewVisibility = .all
    @State var showInspector = true
    @State var window: NSWindow = .init()

    var body: some View {
        WindowObserver(window: window) {
            NavigationSplitView(columnVisibility: $visibility) {
                NavigatorSidebarView(workspace: workspace, viewModel: navigatorViewModel)
                    .toolbar {
                        ToolbarItem {
                            Button {
                                withAnimation(.linear(duration: 0)) {
                                    if visibility == .detailOnly {
                                        visibility = .all
                                    } else {
                                        visibility = .detailOnly
                                    }
                                }
                            } label: {
                                Image(systemName: "sidebar.left")
                                    .imageScale(.large)
                            }
                        }
                    }
            } detail: {

Review comment (suggestion):
Does this have to be created here, because it's just passed into `NavigatorSidebarView` and used nowhere else

Code after:
//
//  WindowSplitView.swift
//  CodeEdit
//
//  Created by Wouter Hennen on 18/06/2023.
//

import SwiftUI

struct WindowSplitView: View {
    @StateObject var workspace: WorkspaceDocument
    @State var visibility: NavigationSplitViewVisibility = .all
    @State var showInspector = true
    @State var window: NSWindow = .init()

    var body: some View {
        WindowObserver(window: window) {
            NavigationSplitView(columnVisibility: $visibility) {
                NavigatorAreaView(workspace: workspace, viewModel: NavigatorSidebarViewModel())
                    .toolbar {
                        ToolbarItem {
                            Button {
                                withAnimation(.linear(duration: 0)) {
                                    if visibility == .detailOnly {
                                        visibility = .all
                                    } else {
                                        visibility = .detailOnly
                                    }
                                }
                            } label: {
                                Image(systemName: "sidebar.left")
                                    .imageScale(.large)
                            }
                        }
                    }
            } detail: {
                if #available(macOS 14.0, *) {
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Settings/Pages/SearchSettings/Models/SearchSettings.swift (Swift)

Code before:
//
//  SearchSettings.swift
//  CodeEdit
//
//  Created by Esteban on 12/10/23.
//

import Foundation

extension SettingsData {

    struct SearchSettings: Codable, Hashable, SearchableSettingsPage {

        /// The search keys
        var searchKeys: [String] {
            [
                "Ignore Glob Patterns",
                "Ignore Patterns"
            ]
            .map { NSLocalizedString($0, comment: "") }
        }

        /// List of Glob Patterns that determine which files or directories to ignore
        var ignoreGlobPatterns: [GlobPattern] = .init()

        /// Default initializer
        init() {}

        /// Explicit decoder init for setting default values when key is not present in `JSON`
        init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)

            self.ignoreGlobPatterns = try container.decodeIfPresent(
                [GlobPattern].self,
                forKey: .ignoreGlobPatterns
            ) ?? []

Review comment (suggestion):
```suggestion
```
I think this line is unnecessary 

Code after:
//
//  SearchSettings.swift
//  CodeEdit
//
//  Created by Esteban on 12/10/23.
//

import Foundation

extension SettingsData {
    struct SearchSettings: Codable, Hashable, SearchableSettingsPage {

        /// The search keys
        var searchKeys: [String] {
            [
                "Ignore Glob Patterns",
                "Ignore Patterns"
            ]
            .map { NSLocalizedString($0, comment: "") }
        }

        /// List of Glob Patterns that determine which files or directories to ignore
        var ignoreGlobPatterns: [GlobPattern] = .init()

        /// Default initializer
        init() {}

        /// Explicit decoder init for setting default values when key is not present in `JSON`
        init(from decoder: Decoder) throws {
            let container = try decoder.container(keyedBy: CodingKeys.self)

            self.ignoreGlobPatterns = try container.decodeIfPresent(
                [GlobPattern].self,
                forKey: .ignoreGlobPatterns
            ) ?? []
        }
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/UtilityArea/Views/UtilityAreaView.swift (Swift)

Code before:
//
//  UtilityAreaView.swift
//  CodeEditModules/StatusBar
//
//  Created by Lukas Pistrol on 22.03.22.
//

import SwiftUI

struct UtilityAreaView: View {
    @Environment(\.colorScheme)
    private var colorScheme
    @Environment(\.controlActiveState)
    private var controlActiveState

    @EnvironmentObject private var model: UtilityAreaViewModel

    @State var selection: UtilityAreaTab? = .terminal

    var body: some View {
        VStack(spacing: 0) {
            if let selection {
                selection
            } else {
                Text("Tab not found")
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            }
        }
        .safeAreaInset(edge: .leading, spacing: 0) {
            HStack(spacing: 0) {
                AreaTabBar(items: $model.tabItems, selection: $selection, position: .side)
                Divider()
                    .overlay(Color(nsColor: colorScheme == .dark ? .black : .clear))
            }
        }
        .overlay(alignment: .bottomTrailing) {
            HStack(spacing: 5) {
                Divider()
                HStack(spacing: 0) {

Review comment (refactor):
```suggestion
    @AppSettings(\.theme.matchAppearance)
    private var matchAppearance

    @AppSettings(\.terminal.darkAppearance)
    private var darkAppearance

    @Environment(\.colorScheme)
    private var colorScheme

    @EnvironmentObject private var model: UtilityAreaViewModel

    @StateObject private var themeModel: ThemeModel = .shared
```

Code after:
//
//  UtilityAreaView.swift
//  CodeEditModules/StatusBar
//
//  Created by Lukas Pistrol on 22.03.22.
//

import SwiftUI

struct UtilityAreaView: View {
    @AppSettings(\.theme.matchAppearance)
    private var matchAppearance

    @AppSettings(\.terminal.darkAppearance)
    private var darkAppearance

    @Environment(\.colorScheme)
    private var colorScheme

    @EnvironmentObject private var model: UtilityAreaViewModel

    @StateObject private var themeModel: ThemeModel = .shared

    @State var selection: UtilityAreaTab? = .terminal

    var body: some View {
        VStack(spacing: 0) {
            if let selection {
                selection
            } else {
                Text("Tab not found")
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            }
        }
        .safeAreaInset(edge: .leading, spacing: 0) {
            HStack(spacing: 0) {
                AreaTabBar(items: $model.tabItems, selection: $selection, position: .side)
                Divider()
                    .overlay(Color(nsColor: colorScheme == .dark ? .black : .clear))
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Commands/Views/QuickActionsView.swift (Swift)

Code before:
//
//  CommandPaletteView.swift
//  CodeEdit
//
//  Created by Alex Sinelnikov on 24.05.2022.
//

import SwiftUI

/// Command palette view
struct QuickActionsView: View {

    @Environment(\.colorScheme)
    private var colorScheme: ColorScheme

    @ObservedObject private var state: QuickActionsViewModel

    @ObservedObject private var commandManager: CommandManager = .shared

    @State private var monitor: Any?

    @State private var selectedItem: Command?

    private let closePalette: () -> Void

    init(state: QuickActionsViewModel, closePalette: @escaping () -> Void) {
        self.state = state
        self.closePalette = closePalette
        state.filteredCommands = commandManager.commands
    }

    func callHandler(command: Command) {
        closePalette()
        command.closureWrapper.call()
        selectedItem = nil

Review comment (suggestion):
Change this comment to reflect the new name
```suggestion
/// Quick actions view
```

Code after:
//
//  CommandPaletteView.swift
//  CodeEdit
//
//  Created by Alex Sinelnikov on 24.05.2022.
//

import SwiftUI

/// Quick actions view
struct QuickActionsView: View {

    @Environment(\.colorScheme)
    private var colorScheme: ColorScheme

    @ObservedObject private var state: QuickActionsViewModel

    @ObservedObject private var commandManager: CommandManager = .shared

    @State private var monitor: Any?

    @State private var selectedItem: Command?

    private let closePalette: () -> Void

    init(state: QuickActionsViewModel, closePalette: @escaping () -> Void) {
        self.state = state
        self.closePalette = closePalette
        state.filteredCommands = commandManager.commands
    }

    func callHandler(command: Command) {
        closePalette()
        command.closureWrapper.call()
        selectedItem = nil
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Utils/DependencyInjection/ServiceType.swift (Swift)

Code before:
//
//  ServiceType.swift
//  CodeEdit
//
//  Created by Abe Malla on 4/3/24.
//

enum ServiceType {
    /// Returns a new singleton on the first call, then returns a cached one every other time
    case singleton
    /// Creates a new singleton reference each time and caches it, returning the newer singleton
    case newSingleton
    /// Creates a new singleton
    case new
}


Review comment (suggestion):
```suggestion

/// Defines the type of service instantiation strategy.
enum ServiceType {
```

Code after:
//
//  ServiceType.swift
//  CodeEdit
//
//  Created by Abe Malla on 4/3/24.
//

/// Defines the type of service instantiation strategy.
enum ServiceType {
    /// Returns a new singleton on the first call, then returns a cached one every other time
    case singleton
    /// Creates a new singleton reference each time and caches it, returning the newer singleton
    case newSingleton
    /// Creates a new singleton
    case new
}
Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Welcome/Views/RecentProjectsListView.swift (Swift)

Code before:
        let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
        recentProjects = projectsURL
    }

    func updateRecentProjects() {
        let recentProjectPaths: [String] = UserDefaults.standard.array(
            forKey: "recentProjectPaths"
        ) as? [String] ?? []
        let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
        recentProjects = projectsURL
    }
    public func donateSearchableItems() {
        let searchableItems = recentProjects.map { entity in
            let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
            attributeSet.title = entity.lastPathComponent
            attributeSet.relatedUniqueIdentifier = entity.path()
            return CSSearchableItem(
                uniqueIdentifier: entity.path(),
                domainIdentifier: "app.codeedit.CodeEdit.ProjectItem",
                attributeSet: attributeSet
            )
        }
        CSSearchableIndex.default().indexSearchableItems(searchableItems) { error in
            if let error = error {
                print(error)
            } else {
                print("Successfully indexed")
            }
        }
    }
}


Review comment (suggestion):
No need for a success message. The message for the error will eventually be integrated into a better logging solution for the application.

Code after:
        let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
        recentProjects = projectsURL
    }

    func updateRecentProjects() {
        let recentProjectPaths: [String] = UserDefaults.standard.array(
            forKey: "recentProjectPaths"
        ) as? [String] ?? []
        let projectsURL = recentProjectPaths.map { URL(filePath: $0) }
        recentProjects = projectsURL
    }

    func donateSearchableItems() {
        let searchableItems = recentProjects.map { entity in
            let attributeSet = CSSearchableItemAttributeSet(contentType: .content)
            attributeSet.title = entity.lastPathComponent
            attributeSet.relatedUniqueIdentifier = entity.path()
            return CSSearchableItem(
                uniqueIdentifier: entity.path(),
                domainIdentifier: "app.codeedit.CodeEdit.ProjectItem",
                attributeSet: attributeSet
            )
        }
        CSSearchableIndex.default().indexSearchableItems(searchableItems) { error in
            if let error = error {
                print(error)
            }
        }
    }
}