Skip to content

Commit 506b80e

Browse files
committed
Run node with interactive logged-in bash
1 parent 450ae78 commit 506b80e

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

Copilot for Xcode/DebugView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ final class DebugSettings: ObservableObject {
77
var disableLazyVStack: Bool
88
@AppStorage(\.preCacheOnFileOpen)
99
var preCacheOnFileOpen: Bool
10+
@AppStorage(\.runNodeWithInteractiveLoggedInShell)
11+
var runNodeWithInteractiveLoggedInShell: Bool
1012
init() {}
1113
}
1214

@@ -24,6 +26,10 @@ struct DebugSettingsView: View {
2426
Text("Cache editor information on file open")
2527
}
2628
.toggleStyle(.switch)
29+
Toggle(isOn: $settings.runNodeWithInteractiveLoggedInShell) {
30+
Text("Run node with interactive logged-in bash")
31+
}
32+
.toggleStyle(.switch)
2733
}
2834
}.buttonStyle(.copilot)
2935
}

Core/Sources/CopilotService/CopilotService.swift

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import CopilotModel
22
import Foundation
33
import LanguageClient
44
import LanguageServerProtocol
5-
import XPCShared
65
import Preferences
6+
import XPCShared
77

88
public protocol CopilotAuthServiceType {
99
func checkStatus() async throws -> CopilotStatus
@@ -55,25 +55,43 @@ public class CopilotBaseService {
5555
if userEnvPath.isEmpty {
5656
userEnvPath = "/usr/bin:/usr/local/bin" // fallback
5757
}
58-
let executionParams = {
58+
let executionParams: Process.ExecutionParameters
59+
if UserDefaults.shared.value(for: \.runNodeWithInteractiveLoggedInShell) {
5960
let nodePath = UserDefaults.shared.value(for: \.nodePath)
60-
return Process.ExecutionParameters(
61-
path: "/usr/bin/env",
62-
arguments: [
63-
nodePath.isEmpty ? "node" : nodePath,
64-
Bundle.main.url(
65-
forResource: "agent",
66-
withExtension: "js",
67-
subdirectory: "copilot/dist"
68-
)!.path,
69-
"--stdio",
70-
],
71-
environment: [
72-
"PATH": userEnvPath,
73-
],
74-
currentDirectoryURL: supportURL
75-
)
76-
}()
61+
let command = [
62+
nodePath.isEmpty ? "node" : nodePath,
63+
"\"\(Bundle.main.url(forResource: "agent", withExtension: "js", subdirectory: "copilot/dist")!.path)\"",
64+
"--stdio",
65+
].joined(separator: " ")
66+
executionParams = {
67+
Process.ExecutionParameters(
68+
path: "/bin/bash",
69+
arguments: ["-i", "-l", "-c", command],
70+
environment: [:],
71+
currentDirectoryURL: supportURL
72+
)
73+
}()
74+
} else {
75+
executionParams = {
76+
let nodePath = UserDefaults.shared.value(for: \.nodePath)
77+
return Process.ExecutionParameters(
78+
path: "/usr/bin/env",
79+
arguments: [
80+
nodePath.isEmpty ? "node" : nodePath,
81+
Bundle.main.url(
82+
forResource: "agent",
83+
withExtension: "js",
84+
subdirectory: "copilot/dist"
85+
)!.path,
86+
"--stdio",
87+
],
88+
environment: [
89+
"PATH": userEnvPath,
90+
],
91+
currentDirectoryURL: supportURL
92+
)
93+
}()
94+
}
7795
let localServer = CopilotLocalProcessServer(executionParameters: executionParams)
7896
localServer.logMessages = false
7997
localServer.notificationHandler = { _, respond in
@@ -161,7 +179,7 @@ public final class CopilotSuggestionService: CopilotBaseService, CopilotSuggesti
161179
ignoreSpaceOnlySuggestions: Bool
162180
) async throws -> [CopilotCompletion] {
163181
let languageId = languageIdentifierFromFileURL(fileURL)
164-
182+
165183
let relativePath = {
166184
let filePath = fileURL.path
167185
let rootPath = projectRootURL.path

Core/Sources/Preferences/Keys.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ public struct UserDefaultPreferenceKeys {
172172

173173
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
174174
public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() }
175+
public var runNodeWithInteractiveLoggedInShell: FeatureFlags
176+
.RunNodeWithInteractiveLoggedInShell { .init() }
175177
}
176178

177179
public enum FeatureFlags {
@@ -184,4 +186,9 @@ public enum FeatureFlags {
184186
public let defaultValue = true
185187
public let key = "FeatureFlag-PreCacheOnFileOpen"
186188
}
189+
190+
public struct RunNodeWithInteractiveLoggedInShell: UserDefaultPreferenceKey {
191+
public let defaultValue = true
192+
public let key = "FeatureFlag-RunNodeWithInteractiveLoggedInShell"
193+
}
187194
}

0 commit comments

Comments
 (0)