Repository navigation
Add Inline VS Code serve-web settings (port, data dir, persistence, extra args) #6900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
bff4d74
Add Inline VS Code serve-web settings (port, data dir, persistence, e…
c6108a6
Merge remote-tracking branch 'origin/main' into issue-6645-add-settin…
18ecbef
Bump SettingsWindowScene length budget for merged Inline VS Code + Sl…
d8313cf
Address review: injectable types, fail-closed ephemeral state, strip …
de81da1
Address review round 2: commit drafts on blur, tolerant config decode…
0df3a80
Address review round 3: clean up non-persistent serve-web data dirs o…
404170c
Address review: reject fractional cmux.json ports instead of truncating
ea0115a
Address review: split inline VS Code serve-web helpers into one-type-…
9bd8057
Address cmux-policy: docs on public symbols, per-field focus, instanc…
f81a8bf
Merge remote-tracking branch 'origin/main' into issue-6645-add-settin…
austinywang 19ef5bb
Address inline VS Code review feedback
austinywang a92756d
Localize inline VS Code settings
austinywang 6726c4d
Merge remote-tracking branch 'origin/main' into issue-6645-add-settin…
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Packages/macOS/CmuxSettings/Sources/CmuxSettings/Keys/InlineVSCodeCatalogSection.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import Foundation | ||
|
|
||
| /// Settings under the dotted-id prefix `inlineVSCode.*`. | ||
| /// | ||
| /// These control how the built-in "Open Current Directory in VS Code (Inline)" | ||
| /// command launches VS Code's `serve-web`. All four keys are JSON-backed so they | ||
| /// live in `~/.config/cmux/cmux.json` and can be edited either through the | ||
| /// Settings UI or by hand. They are read by the macOS app's serve-web launcher | ||
| /// at (re)start time; changing a value takes effect the next time inline VS Code | ||
| /// starts (use "Restart Inline VS Code" to apply immediately). | ||
| public struct InlineVSCodeCatalogSection: SettingCatalogSection { | ||
| /// Whether `serve-web` keeps its state (sign-in, Settings Sync, …) across | ||
| /// launches. Default `true`. When `false` (and no ``serverDataDir`` is set), | ||
| /// a throwaway data directory is used so nothing persists between launches. | ||
| public let persistServeWebState = JSONKey<Bool>( | ||
| id: "inlineVSCode.persistServeWebState", | ||
| defaultValue: true | ||
| ) | ||
|
|
||
| /// Local port `serve-web` binds. Default `0`, which selects a random free | ||
| /// port. Set a value in `1...65535` to pin the port. | ||
| public let port = JSONKey<Int>( | ||
| id: "inlineVSCode.port", | ||
| defaultValue: 0 | ||
| ) | ||
|
|
||
| /// The `serve-web` server data directory (`--server-data-dir`). Empty (the | ||
| /// default) uses the upstream VS Code default location. A leading `~` | ||
| /// expands to the home directory. | ||
| public let serverDataDir = JSONKey<String>( | ||
| id: "inlineVSCode.serverDataDir", | ||
| defaultValue: "" | ||
| ) | ||
|
|
||
| /// Advanced upstream VS Code `serve-web` flags appended after the | ||
| /// cmux-managed arguments. cmux-owned flags (host, port, connection token, | ||
| /// server data dir) are stripped so the loopback + connection-token | ||
| /// invariants hold. Empty by default. | ||
| public let extraArgs = JSONKey<[String]>( | ||
| id: "inlineVSCode.extraArgs", | ||
| defaultValue: [] | ||
| ) | ||
|
|
||
| public init() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
253 changes: 253 additions & 0 deletions
253
Packages/macOS/CmuxSettingsUI/Sources/CmuxSettingsUI/Sections/InlineVSCodeSection.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,253 @@ | ||
| import CmuxFoundation | ||
| import CmuxSettings | ||
| import SwiftUI | ||
|
|
||
| /// **Inline VS Code** section — controls how the built-in "Open Current | ||
| /// Directory in VS Code (Inline)" command launches VS Code's `serve-web`: | ||
| /// persistent state, the local port, the server data directory, and any extra | ||
| /// upstream `serve-web` flags. All four keys are JSON-backed (`inlineVSCode.*` | ||
| /// in `~/.config/cmux/cmux.json`); the macOS app reads them when inline VS Code | ||
| /// (re)starts. | ||
| @MainActor | ||
| public struct InlineVSCodeSection: View { | ||
| @State private var persist: JSONValueModel<Bool> | ||
| @State private var port: JSONValueModel<Int> | ||
| @State private var serverDataDir: JSONValueModel<String> | ||
| @State private var extraArgs: JSONValueModel<[String]> | ||
|
|
||
| @State private var portDraft: String = "" | ||
| @State private var portLoaded: Bool = false | ||
| @State private var serverDataDirDraft: String = "" | ||
| @State private var serverDataDirLoaded: Bool = false | ||
| @State private var extraArgsDraft: String = "" | ||
| @State private var extraArgsLoaded: Bool = false | ||
| @FocusState private var focusedField: Field? | ||
|
|
||
| private enum Field: Hashable { | ||
| case port | ||
| case serverDataDir | ||
| case extraArgs | ||
| } | ||
|
|
||
| public init( | ||
| jsonStore: JSONConfigStore, | ||
| catalog: SettingCatalog, | ||
| errorLog: SettingsErrorLog | ||
| ) { | ||
| _persist = State(initialValue: JSONValueModel( | ||
| store: jsonStore, | ||
| key: catalog.inlineVSCode.persistServeWebState, | ||
| errorLog: errorLog | ||
| )) | ||
| _port = State(initialValue: JSONValueModel( | ||
| store: jsonStore, | ||
| key: catalog.inlineVSCode.port, | ||
| errorLog: errorLog | ||
| )) | ||
| _serverDataDir = State(initialValue: JSONValueModel( | ||
| store: jsonStore, | ||
| key: catalog.inlineVSCode.serverDataDir, | ||
| errorLog: errorLog | ||
| )) | ||
| _extraArgs = State(initialValue: JSONValueModel( | ||
| store: jsonStore, | ||
| key: catalog.inlineVSCode.extraArgs, | ||
| errorLog: errorLog | ||
| )) | ||
| } | ||
|
|
||
| public var body: some View { | ||
| Group { | ||
| SettingsSectionHeader( | ||
| String(localized: "settings.section.inlineVSCode", defaultValue: "Inline VS Code"), | ||
| section: .inlineVSCode | ||
| ) | ||
| SettingsCard { | ||
| persistRow | ||
| SettingsCardDivider() | ||
| portRow | ||
| SettingsCardDivider() | ||
| serverDataDirRow | ||
| SettingsCardDivider() | ||
| extraArgsRow | ||
| SettingsCardDivider() | ||
| SettingsCardNote(String( | ||
| localized: "settings.inlineVSCode.note", | ||
| defaultValue: "These options apply when you run \"Open Current Directory in VS Code (Inline)\". Changes take effect the next time inline VS Code starts — use \"Restart Inline VS Code\" to apply them now. cmux always binds serve-web to 127.0.0.1 with a connection token; extra arguments are advanced and unsupported." | ||
| )) | ||
| } | ||
| } | ||
| .task { startObservingSettings() } | ||
| .onChange(of: port.current) { _, newValue in | ||
| let normalized = Self.portText(newValue) | ||
| if Self.parsePort(portDraft) != newValue { | ||
| portDraft = normalized | ||
| } | ||
| } | ||
| .onChange(of: serverDataDir.current) { _, newValue in | ||
| if serverDataDirDraft != newValue { | ||
| serverDataDirDraft = newValue | ||
| } | ||
| } | ||
| .onChange(of: extraArgs.current) { _, newValue in | ||
| if Self.parseExtraArgs(extraArgsDraft) != newValue { | ||
| extraArgsDraft = newValue.joined(separator: "\n") | ||
| } | ||
| } | ||
| .onChange(of: focusedField) { previous, _ in | ||
| // Commit the field that just lost focus so edits aren't lost when the | ||
| // user tabs away, clicks elsewhere, or closes the Settings window | ||
| // without pressing Return. | ||
| switch previous { | ||
| case .port: commitPort() | ||
| case .serverDataDir: commitServerDataDir() | ||
| case .extraArgs: commitExtraArgs() | ||
| case nil: break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func startObservingSettings() { | ||
| let models: [any SettingObservationStarting] = [persist, port, serverDataDir, extraArgs] | ||
| models.forEach { $0.startObserving() } | ||
| if !portLoaded { | ||
| portDraft = Self.portText(port.current) | ||
| portLoaded = true | ||
| } | ||
| if !serverDataDirLoaded { | ||
| serverDataDirDraft = serverDataDir.current | ||
| serverDataDirLoaded = true | ||
| } | ||
| if !extraArgsLoaded { | ||
| extraArgsDraft = extraArgs.current.joined(separator: "\n") | ||
| extraArgsLoaded = true | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var persistRow: some View { | ||
| SettingsCardRow( | ||
| configurationReview: .json("inlineVSCode.persistServeWebState"), | ||
| String(localized: "settings.inlineVSCode.persistState", defaultValue: "Persist serve-web State"), | ||
| subtitle: persist.current | ||
| ? String(localized: "settings.inlineVSCode.persistState.subtitleOn", defaultValue: "Keeps sign-in and Settings Sync state across restarts.") | ||
| : String(localized: "settings.inlineVSCode.persistState.subtitleOff", defaultValue: "Uses a throwaway data directory; nothing persists between launches.") | ||
| ) { | ||
| Toggle("", isOn: Binding(get: { persist.current }, set: { persist.set($0) })) | ||
| .labelsHidden() | ||
| .controlSize(.small) | ||
| .accessibilityIdentifier("SettingsInlineVSCodePersistToggle") | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var portRow: some View { | ||
| SettingsCardRow( | ||
| configurationReview: .json("inlineVSCode.port"), | ||
| String(localized: "settings.inlineVSCode.port", defaultValue: "Port"), | ||
| subtitle: String(localized: "settings.inlineVSCode.port.subtitle", defaultValue: "Local serve-web port. Leave empty (or 0) to pick a random free port. Range 1–65535."), | ||
| controlWidth: 120 | ||
| ) { | ||
| TextField( | ||
| String(localized: "settings.inlineVSCode.port.placeholder", defaultValue: "random"), | ||
| text: $portDraft | ||
| ) | ||
| .focused($focusedField, equals: .port) | ||
| .onSubmit { commitPort() } | ||
| .textFieldStyle(.roundedBorder) | ||
| .multilineTextAlignment(.trailing) | ||
| .accessibilityIdentifier("SettingsInlineVSCodePortField") | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var serverDataDirRow: some View { | ||
| SettingsCardRow( | ||
| configurationReview: .json("inlineVSCode.serverDataDir"), | ||
| String(localized: "settings.inlineVSCode.serverDataDir", defaultValue: "Server Data Directory"), | ||
| subtitle: String(localized: "settings.inlineVSCode.serverDataDir.subtitle", defaultValue: "serve-web --server-data-dir. Leave empty to use the VS Code default. A leading ~ expands to your home directory."), | ||
| controlWidth: 240 | ||
| ) { | ||
| TextField( | ||
| String(localized: "settings.inlineVSCode.serverDataDir.placeholder", defaultValue: "e.g. ~/Library/Application Support/cmux/vscode-serve-web"), | ||
| text: $serverDataDirDraft | ||
| ) | ||
| .focused($focusedField, equals: .serverDataDir) | ||
| .onSubmit { commitServerDataDir() } | ||
| .textFieldStyle(.roundedBorder) | ||
| .accessibilityIdentifier("SettingsInlineVSCodeServerDataDirField") | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var extraArgsRow: some View { | ||
| VStack(alignment: .leading, spacing: 6) { | ||
| SettingsCardRow( | ||
| configurationReview: .json("inlineVSCode.extraArgs"), | ||
| String(localized: "settings.inlineVSCode.extraArgs", defaultValue: "Extra serve-web Arguments"), | ||
| subtitle: String(localized: "settings.inlineVSCode.extraArgs.subtitle", defaultValue: "Advanced upstream VS Code serve-web flags, one per line. cmux-managed flags (host, port, connection token, server data dir) are ignored.") | ||
| ) { | ||
| EmptyView() | ||
| } | ||
| TextEditor(text: $extraArgsDraft) | ||
| .focused($focusedField, equals: .extraArgs) | ||
| .cmuxFont(.body, design: .monospaced) | ||
| .frame(minHeight: 56, maxHeight: 120) | ||
| .scrollContentBackground(.hidden) | ||
| .padding(6) | ||
| .background(Color(nsColor: .controlBackgroundColor)) | ||
| .cornerRadius(6) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: 6) | ||
| .stroke(Color(nsColor: .separatorColor), lineWidth: 0.5) | ||
| ) | ||
| .padding(.horizontal, 16) | ||
| .padding(.bottom, 12) | ||
| .accessibilityIdentifier("SettingsInlineVSCodeExtraArgsEditor") | ||
| } | ||
| } | ||
|
|
||
| private func commitPort() { | ||
| let parsed = Self.parsePort(portDraft) | ||
| if parsed != port.current { | ||
| port.set(parsed) | ||
| } | ||
| portDraft = Self.portText(parsed) | ||
| } | ||
|
|
||
| private func commitServerDataDir() { | ||
| let trimmed = serverDataDirDraft.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if trimmed != serverDataDir.current { | ||
| serverDataDir.set(trimmed) | ||
| } | ||
| serverDataDirDraft = trimmed | ||
| } | ||
|
|
||
| private func commitExtraArgs() { | ||
| let parsed = Self.parseExtraArgs(extraArgsDraft) | ||
| if parsed != extraArgs.current { | ||
| extraArgs.set(parsed) | ||
| } | ||
| } | ||
|
|
||
| /// Parses the port draft, clamping to the valid `serve-web` range. Empty or | ||
| /// out-of-range input resolves to `0` (a random free port). | ||
| static func parsePort(_ text: String) -> Int { | ||
| let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard let value = Int(trimmed), (0...65535).contains(value) else { return 0 } | ||
| return value | ||
| } | ||
|
|
||
| /// Renders a stored port for the text field: `0` shows as empty (random). | ||
| static func portText(_ port: Int) -> String { | ||
| port == 0 ? "" : String(port) | ||
| } | ||
|
|
||
| /// Splits the multi-line draft into one argument per non-empty trimmed line. | ||
| static func parseExtraArgs(_ text: String) -> [String] { | ||
| text | ||
| .split(separator: "\n", omittingEmptySubsequences: false) | ||
| .map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } | ||
| .filter { !$0.isEmpty } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.