Skip to content

Commit 46dce42

Browse files
committed
Update settings runNodeWithInteractiveLoggedInShell and make it more obvious
1 parent c1b0e09 commit 46dce42

File tree

6 files changed

+84
-23
lines changed

6 files changed

+84
-23
lines changed

Copilot for Xcode/DebugView.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ final class DebugSettings: ObservableObject {
66
@AppStorage(\.disableLazyVStack)
77
var disableLazyVStack: Bool
88
@AppStorage(\.preCacheOnFileOpen)
9-
var preCacheOnFileOpen: Bool
10-
@AppStorage(\.runNodeWithInteractiveLoggedInShell)
119
var runNodeWithInteractiveLoggedInShell: Bool
1210
@AppStorage(\.useCustomScrollViewWorkaround) var useCustomScrollViewWorkaround
1311
init() {}
@@ -27,10 +25,6 @@ struct DebugSettingsView: View {
2725
Text("Cache editor information on file open")
2826
}
2927
.toggleStyle(.switch)
30-
Toggle(isOn: $settings.runNodeWithInteractiveLoggedInShell) {
31-
Text("Run node with interactive logged-in bash")
32-
}
33-
.toggleStyle(.switch)
3428
Toggle(isOn: $settings.useCustomScrollViewWorkaround) {
3529
Text("Use custom scroll view workaround for smooth scrolling")
3630
}

Copilot for Xcode/LaunchAgentView.swift

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import LaunchAgentManager
2-
import SwiftUI
32
import Preferences
3+
import SwiftUI
44

55
struct LaunchAgentView: View {
6+
class Settings: ObservableObject {
7+
@AppStorage(\.nodePath) var nodePath: String
8+
@AppStorage(\.runNodeWith) var runNodeWith
9+
10+
init() {}
11+
}
12+
613
@State var errorMessage: String?
714
@State var isDidRemoveLaunchAgentAlertPresented = false
815
@State var isDidSetupLaunchAgentAlertPresented = false
916
@State var isDidRestartLaunchAgentAlertPresented = false
10-
@AppStorage(\.nodePath) var nodePath: String
17+
@StateObject var settings = Settings()
1118

1219
var body: some View {
1320
Section {
@@ -85,14 +92,31 @@ struct LaunchAgentView: View {
8592
}
8693
}
8794

88-
HStack {
89-
Text("Path to Node: ")
90-
TextField("node", text: $nodePath)
91-
.textFieldStyle(.copilot)
95+
Form {
96+
TextField(text: $settings.nodePath, prompt: Text("node")) {
97+
Text("Path to Node")
98+
}
99+
100+
Picker(selection: $settings.runNodeWith) {
101+
ForEach(NodeRunner.allCases, id: \.rawValue) { runner in
102+
switch runner {
103+
case .env:
104+
Text("/usr/bin/env").tag(runner)
105+
case .bash:
106+
Text("/bin/bash -i -l").tag(runner)
107+
case .shell:
108+
Text("$SHELL -i -l").tag(runner)
109+
}
110+
}
111+
} label: {
112+
Text("Run Node with")
113+
}
92114
}
93-
94-
Text("You may have to restart the helper app to apply the changes. To do so, simply close the helper app by clicking on the menu bar icon that looks like a steer wheel, it will automatically restart as needed.")
95-
.foregroundColor(.secondary)
115+
116+
Text(
117+
"You may have to restart the helper app to apply the changes. To do so, simply close the helper app by clicking on the menu bar icon that looks like a steer wheel, it will automatically restart as needed."
118+
)
119+
.foregroundColor(.secondary)
96120

97121
HStack {
98122
Button(action: {

Core/Sources/CopilotService/CopilotService.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public class CopilotBaseService {
5656
userEnvPath = "/usr/bin:/usr/local/bin" // fallback
5757
}
5858
let executionParams: Process.ExecutionParameters
59-
if UserDefaults.shared.value(for: \.runNodeWithInteractiveLoggedInShell) {
59+
let runner = UserDefaults.shared.value(for: \.runNodeWith)
60+
61+
switch runner {
62+
case .bash:
6063
let nodePath = UserDefaults.shared.value(for: \.nodePath)
6164
let command = [
6265
nodePath.isEmpty ? "node" : nodePath,
@@ -71,7 +74,23 @@ public class CopilotBaseService {
7174
currentDirectoryURL: supportURL
7275
)
7376
}()
74-
} else {
77+
case .shell:
78+
let shell = ProcessInfo.processInfo.userEnvironment["SHELL"] ?? "/bin/bash"
79+
let nodePath = UserDefaults.shared.value(for: \.nodePath)
80+
let command = [
81+
nodePath.isEmpty ? "node" : nodePath,
82+
"\"\(Bundle.main.url(forResource: "agent", withExtension: "js", subdirectory: "copilot/dist")!.path)\"",
83+
"--stdio",
84+
].joined(separator: " ")
85+
executionParams = {
86+
Process.ExecutionParameters(
87+
path: shell,
88+
arguments: ["-i", "-l", "-c", command],
89+
environment: [:],
90+
currentDirectoryURL: supportURL
91+
)
92+
}()
93+
case .env:
7594
executionParams = {
7695
let nodePath = UserDefaults.shared.value(for: \.nodePath)
7796
return Process.ExecutionParameters(

Core/Sources/Preferences/Keys.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ public struct UserDefaultPreferenceKeys {
1818

1919
public var nodePath: NodePath { .init() }
2020

21+
// MARK: - Run Node With
22+
23+
public struct RunNodeWithKey: UserDefaultPreferenceKey {
24+
public let defaultValue = NodeRunner.bash
25+
public let key = "RunNodeWith"
26+
}
27+
28+
public var runNodeWith: RunNodeWithKey { .init() }
29+
2130
// MARK: - Realtime Suggestion
2231

2332
public struct RealtimeSuggestionToggle: UserDefaultPreferenceKey {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
public enum NodeRunner: Int, CaseIterable {
4+
case env
5+
case bash
6+
case shell
7+
}

Core/Sources/Preferences/UserDefaults.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public extension UserDefaults {
1111
shared.setupDefaultValue(for: \.suggestionPresentationMode)
1212
shared.setupDefaultValue(for: \.widgetColorScheme)
1313
shared.setupDefaultValue(for: \.customCommands)
14+
shared.setupDefaultValue(
15+
for: \.runNodeWith,
16+
defaultValue: shared.value(for: \.runNodeWithInteractiveLoggedInShell)
17+
? .bash
18+
: .env
19+
)
1420
}
1521
}
1622

@@ -45,7 +51,7 @@ extension Array: RawRepresentable where Element: Codable {
4551

4652
public extension UserDefaults {
4753
// MARK: - Normal Types
48-
54+
4955
func value<K: UserDefaultPreferenceKey>(
5056
for keyPath: KeyPath<UserDefaultPreferenceKeys, K>
5157
) -> K.Value where K.Value: UserDefaultsStorable {
@@ -69,7 +75,7 @@ public extension UserDefaults {
6975
set(key.defaultValue, forKey: key.key)
7076
}
7177
}
72-
78+
7379
// MARK: - Raw Representable
7480

7581
func value<K: UserDefaultPreferenceKey>(
@@ -109,20 +115,22 @@ public extension UserDefaults {
109115
}
110116

111117
func setupDefaultValue<K: UserDefaultPreferenceKey>(
112-
for keyPath: KeyPath<UserDefaultPreferenceKeys, K>
118+
for keyPath: KeyPath<UserDefaultPreferenceKeys, K>,
119+
defaultValue: K.Value? = nil
113120
) where K.Value: RawRepresentable, K.Value.RawValue == String {
114121
let key = UserDefaultPreferenceKeys()[keyPath: keyPath]
115122
if value(forKey: key.key) == nil {
116-
set(key.defaultValue.rawValue, forKey: key.key)
123+
set(defaultValue ?? key.defaultValue.rawValue, forKey: key.key)
117124
}
118125
}
119126

120127
func setupDefaultValue<K: UserDefaultPreferenceKey>(
121-
for keyPath: KeyPath<UserDefaultPreferenceKeys, K>
128+
for keyPath: KeyPath<UserDefaultPreferenceKeys, K>,
129+
defaultValue: K.Value? = nil
122130
) where K.Value: RawRepresentable, K.Value.RawValue == Int {
123131
let key = UserDefaultPreferenceKeys()[keyPath: keyPath]
124132
if value(forKey: key.key) == nil {
125-
set(key.defaultValue.rawValue, forKey: key.key)
133+
set(defaultValue ?? key.defaultValue.rawValue, forKey: key.key)
126134
}
127135
}
128136
}

0 commit comments

Comments
 (0)