diff --git a/desktop/internal/core/remote_helpers.go b/desktop/internal/core/remote_helpers.go index b4cb7ef0d..b0c6eb5b9 100644 --- a/desktop/internal/core/remote_helpers.go +++ b/desktop/internal/core/remote_helpers.go @@ -287,8 +287,9 @@ type RemoteWorkspaceTrustTarget struct { } // Place is the route of the target's hops, outermost first: "destination:port" for an SSH hop, -// with the User option in front when the destination names no user, and "engine:container" for -// a container, joined by " → ". It is empty for a target it cannot read. +// with the User option in front when the destination names no user, "engine:container" for a +// container and "wsl:[user@]distribution" for a WSL distribution, as WSLConnection.Identity +// writes it, joined by " → ". It is empty for a target it cannot read. func (t RemoteWorkspaceTrustTarget) Place() string { var target struct { Hops []struct { @@ -302,6 +303,7 @@ func (t RemoteWorkspaceTrustTarget) Place() string { Engine string `json:"engine"` Container string `json:"container"` } `json:"container"` + WSL *WSLConnection `json:"wsl"` } `json:"hops"` } if json.Unmarshal(t.Target, &target) != nil { @@ -323,6 +325,8 @@ func (t RemoteWorkspaceTrustTarget) Place() string { hops = append(hops, place) case hop.Container != nil: hops = append(hops, hop.Container.Engine+":"+hop.Container.Container) + case hop.WSL != nil: + hops = append(hops, hop.WSL.Identity()) } } return strings.Join(hops, " → ") diff --git a/desktop/internal/core/remote_session.go b/desktop/internal/core/remote_session.go index 62b842146..363ab7477 100644 --- a/desktop/internal/core/remote_session.go +++ b/desktop/internal/core/remote_session.go @@ -23,10 +23,15 @@ type RemoteServerBuild struct { SHA256 string `json:"sha256"` } -// RemoteConnectRequest opens a session to the host of Connection, installing the server build -// for the host's platform when the host does not already run that exact build. +// RemoteConnectRequest opens a session to the host of Connection, or to the local WSL +// distribution WSL names, installing the server build for the host's platform when the host does +// not already run that exact build. Exactly one of the two is set; Core refuses a request with +// both or neither as CodeInvalidRequest, before anything starts. type RemoteConnectRequest struct { - Connection SSHConnection `json:"connection"` + Connection SSHConnection `json:"connection,omitzero"` + // WSL opens a distribution of the Windows Subsystem for Linux through the system's wsl.exe + // instead of OpenSSH. Core asks nothing of the user for it: there is no AskPass. + WSL *WSLConnection `json:"wsl,omitempty"` // Servers are the builds the application ships; Core picks the one for the host. Servers []RemoteServerBuild `json:"servers"` // ServerVersion is the version of the shipped builds. @@ -35,6 +40,51 @@ type RemoteConnectRequest struct { InstallRoot string `json:"installRoot,omitempty"` } +// WSLConnection is a distribution of the Windows Subsystem for Linux on this machine, as +// remote.connect's wsl field names it. Core trims both fields; an empty User is the +// distribution's default user. Core refuses a malformed field by name ("distribution" or "user") +// with the reasons required, tooLong and invalid, read by RemoteConnectionFieldError. +type WSLConnection struct { + // Distribution is the name wsl.exe --list prints, such as Ubuntu-24.04. + Distribution string `json:"distribution"` + // User is the Linux account, passed as wsl.exe --user. + User string `json:"user,omitempty"` +} + +// Identity is the connection as Core names it in the trust records and the recent projects: +// wsl:distribution, or wsl:user@distribution. +func (c WSLConnection) Identity() string { + distribution, user := strings.TrimSpace(c.Distribution), strings.TrimSpace(c.User) + if user == "" { + return "wsl:" + distribution + } + return "wsl:" + user + "@" + distribution +} + +// RemoteWSLDistributions is what remote.listWslDistributions found on this machine. +type RemoteWSLDistributions struct { + // Available says whether wsl.exe ran: false on systems other than Windows and on a Windows + // without WSL. + Available bool `json:"available"` + // Distributions are the installed distributions in wsl.exe's order, without Docker Desktop's + // engine distributions; at most 64. + Distributions []string `json:"distributions"` + // Diagnostics is what wsl.exe printed when it failed, such as the message that WSL is not set + // up, redacted. It is upstream text, shown as it is and never logged. + Diagnostics string `json:"diagnostics"` +} + +// RemoteListWSLDistributions lists the WSL distributions installed on this machine. Core runs +// wsl.exe --list, bounded to 15 seconds (CodeTimedOut past them), and saves nothing. +func (c *Client) RemoteListWSLDistributions(ctx context.Context) (RemoteWSLDistributions, error) { + var result RemoteWSLDistributions + if err := c.Execute(ctx, "remote.listWslDistributions", nil, &result); err != nil { + return RemoteWSLDistributions{}, err + } + result.Distributions = nonNil(result.Distributions) + return result, nil +} + // RemoteSession is a session remote.connect opened. type RemoteSession struct { // ID names the session in every later request. @@ -62,8 +112,9 @@ type RemoteConnectResult struct { // RemoteConnect opens a session as request asks. Questions OpenSSH asks reach the prompt // WithGitAuthentication put in ctx, as for RemoteProbe. Core bounds an attempt, answers -// included, to five minutes. Failures are CodeInvalidRequest before OpenSSH starts, -// CodeRuntimeMissing without ssh, CodeRemoteServerInvalid when the build cannot be read or +// included, to five minutes; a WSL connection asks nothing, and a distribution that is not +// installed is RemoteProbeUnreachable. Failures are CodeInvalidRequest before OpenSSH or wsl.exe +// starts, CodeRuntimeMissing without ssh, CodeRemoteServerInvalid when the build cannot be read or // differs from its SHA-256, and the context's error when ctx ends. A session whose events could // not all be observed is closed again and the observation failure returned: the user may not // have seen every question it asked. diff --git a/desktop/internal/core/remote_session_test.go b/desktop/internal/core/remote_session_test.go index 534fe0329..3db7f075b 100644 --- a/desktop/internal/core/remote_session_test.go +++ b/desktop/internal/core/remote_session_test.go @@ -6,6 +6,7 @@ import ( "errors" "os" "os/exec" + "runtime" "strings" "sync/atomic" "testing" @@ -243,3 +244,44 @@ func TestRemoteConnectRefusesAMalformedBuildBeforeConnecting(t *testing.T) { t.Fatalf("connect = %v, want invalid_request", err) } } + +// A WSL connection is sent as the wsl field alone, and Core refuses one it cannot run by the field +// it names before wsl.exe starts: so do a request naming both a host and a distribution and one +// naming neither. +func TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField(t *testing.T) { + wire, err := json.Marshal(RemoteConnectRequest{WSL: &WSLConnection{Distribution: "Ubuntu"}, Servers: []RemoteServerBuild{}}) + if err != nil || strings.Contains(string(wire), `"connection"`) || !strings.Contains(string(wire), `"wsl":{"distribution":"Ubuntu"}`) { + t.Fatalf("request = %s, %v, want the wsl field without a connection", wire, err) + } + if identity := (WSLConnection{Distribution: " Debian ", User: " dev "}).Identity(); identity != "wsl:dev@Debian" { + t.Fatalf("identity = %q", identity) + } + client := NewClient() + for _, tc := range []struct { + request RemoteConnectRequest + field, reason string + }{ + {RemoteConnectRequest{WSL: &WSLConnection{Distribution: " "}}, "distribution", "required"}, + {RemoteConnectRequest{WSL: &WSLConnection{Distribution: "-d"}}, "distribution", "invalid"}, + {RemoteConnectRequest{WSL: &WSLConnection{Distribution: "Ubuntu", User: "a b"}}, "user", "invalid"}, + {RemoteConnectRequest{Connection: SSHConnection{Host: "devbox"}, WSL: &WSLConnection{Distribution: "Ubuntu"}}, "wsl", "invalid"}, + {RemoteConnectRequest{}, "connection", "required"}, + } { + tc.request.Servers, tc.request.ServerVersion = shippedTargets, "0.0.0-test" + _, err := client.RemoteConnect(testContext(t), tc.request) + if field, reason, ok := RemoteConnectionFieldError(err); !ok || field != tc.field || reason != tc.reason { + t.Fatalf("connect refused %q %q (%v), want %q %q", field, reason, ok, tc.field, tc.reason) + } + } +} + +// Outside Windows there is no WSL: the listing says so without running anything. +func TestRemoteListWSLDistributionsIsUnavailableOutsideWindows(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Windows lists the machine's own distributions") + } + listed, err := NewClient().RemoteListWSLDistributions(testContext(t)) + if err != nil || listed.Available || listed.Distributions == nil || len(listed.Distributions) != 0 || listed.Diagnostics != "" { + t.Fatalf("listing = %+v, %v, want unavailable with an empty list", listed, err) + } +} diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index efbb51bb7..d5d790003 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -1745,6 +1745,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.keepAlive": "Keep-Alive (s)", "desktop.remote.keepAliveHelp": "How often OpenSSH checks that the server still answers (ServerAliveInterval), so a dropped network is noticed.", "desktop.remote.keepAlivePlaceholder": "Auto (SSH config)", + "desktop.remote.kind.ssh": "SSH", "desktop.remote.listFooter": "{count} saved · on this computer only", "desktop.remote.menuItem": "Remote Development…", "desktop.remote.more": "More", @@ -1861,14 +1862,14 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.source.connection": "This connection", "desktop.remote.source.default": "Default", "desktop.remote.source.sshConfig": "SSH config", - "desktop.remote.status.connected": "SSH: {name}", + "desktop.remote.status.connected": "{kind}: {name}", "desktop.remote.status.disconnect": "Disconnect and Close", - "desktop.remote.status.disconnected": "SSH: {name} · Disconnected", + "desktop.remote.status.disconnected": "{kind}: {name} · Disconnected", "desktop.remote.status.label": "Remote Connection", - "desktop.remote.status.latency": "SSH: {name} · {ms} ms", + "desktop.remote.status.latency": "{kind}: {name} · {ms} ms", "desktop.remote.status.reconnect": "Reconnect", - "desktop.remote.status.reconnecting": "SSH: {name} · Reconnecting…", - "desktop.remote.status.unresponsive": "SSH: {name} · Not responding", + "desktop.remote.status.reconnecting": "{kind}: {name} · Reconnecting…", + "desktop.remote.status.unresponsive": "{kind}: {name} · Not responding", "desktop.remote.step.authenticate": "Authenticate", "desktop.remote.step.config": "Read configuration", "desktop.remote.step.connect": "Connect to host", @@ -1917,7 +1918,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.workspace.gitAbove": "This folder is inside a Git repository that starts in a folder above it on the host. Open the repository's top folder to use Git in a remote workspace.", "desktop.remote.workspace.localOnly": "This feature does not work in a remote workspace yet. You can browse, edit, save and search the host's files, run terminals and use Git on the host.", "desktop.remote.workspace.safeBanner": "This remote workspace is in safe mode: you can browse, edit, save and search its files on the host. Trust the folder to use Git.", - "desktop.remote.workspace.title": "{folder} [SSH: {connection}]", + "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", + "desktop.remote.wsl.about": "Opens through wsl.exe on this computer, as the Linux user below. Nothing about the distribution is saved: the folders opened in it are not remembered, and the list is read again each time this window opens.", + "desktop.remote.wsl.distributionInvalid": "wsl.exe does not accept this distribution name.", + "desktop.remote.wsl.heading": "WSL", + "desktop.remote.wsl.kind": "WSL distribution on this computer", + "desktop.remote.wsl.missing": "wsl.exe was not found on this computer. Install the Windows Subsystem for Linux to open a distribution.", + "desktop.remote.wsl.start": "Start the distribution", + "desktop.remote.wsl.unreachable": "This WSL distribution is not installed, or it did not start.", + "desktop.remote.wsl.user": "Linux user", + "desktop.remote.wsl.userHelp": "The account the workspace runs as. Leave it empty to use the distribution's default user.", + "desktop.remote.wsl.userInvalid": "Linux does not accept this user name.", + "desktop.remote.wsl.userPlaceholder": "Default user", + "desktop.remote.wsl.userTooLong": "A Linux user name has at most 32 characters.", "desktop.remoteAuth.failed": "Cannot pass the answer to SSH: {reason}", "desktop.remoteAuth.refused": "SSH did not take the answer: it may be at most 8192 bytes and may not contain a line break. The question was cancelled.", "desktop.remoteAuth.secretHint": "The answer goes only to this SSH connection. Lithe does not keep it.", @@ -5442,6 +5455,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.keepAlive": "保活间隔(秒)", "desktop.remote.keepAliveHelp": "OpenSSH 每隔多久确认一次服务器仍有响应(ServerAliveInterval),以便发现网络已断开。", "desktop.remote.keepAlivePlaceholder": "自动(SSH 配置)", + "desktop.remote.kind.ssh": "SSH", "desktop.remote.listFooter": "{count} 个连接 · 只保存在本机", "desktop.remote.menuItem": "远程开发…", "desktop.remote.more": "更多", @@ -5558,14 +5572,14 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.source.connection": "本连接", "desktop.remote.source.default": "默认值", "desktop.remote.source.sshConfig": "SSH 配置", - "desktop.remote.status.connected": "SSH: {name}", + "desktop.remote.status.connected": "{kind}: {name}", "desktop.remote.status.disconnect": "断开并关闭", - "desktop.remote.status.disconnected": "SSH: {name} · 已断开", + "desktop.remote.status.disconnected": "{kind}: {name} · 已断开", "desktop.remote.status.label": "远程连接", - "desktop.remote.status.latency": "SSH: {name} · {ms} 毫秒", + "desktop.remote.status.latency": "{kind}: {name} · {ms} 毫秒", "desktop.remote.status.reconnect": "重新连接", - "desktop.remote.status.reconnecting": "SSH: {name} · 正在重新连接…", - "desktop.remote.status.unresponsive": "SSH: {name} · 无响应", + "desktop.remote.status.reconnecting": "{kind}: {name} · 正在重新连接…", + "desktop.remote.status.unresponsive": "{kind}: {name} · 无响应", "desktop.remote.step.authenticate": "身份验证", "desktop.remote.step.config": "读取配置", "desktop.remote.step.connect": "连接主机", @@ -5614,7 +5628,19 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.remote.workspace.gitAbove": "此文件夹位于主机上更上层文件夹开始的 Git 仓库中。请打开仓库的顶层文件夹,以便在远程工作区中使用 Git。", "desktop.remote.workspace.localOnly": "远程工作区暂不支持此功能,可以浏览、编辑、保存和搜索主机上的文件,也可以在主机上运行终端和使用 Git。", "desktop.remote.workspace.safeBanner": "此远程工作区处于安全模式:可以浏览、编辑、保存和搜索主机上的文件。信任此文件夹后即可使用 Git。", - "desktop.remote.workspace.title": "{folder} [SSH: {connection}]", + "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", + "desktop.remote.wsl.about": "通过本机的 wsl.exe 打开,以下方的 Linux 用户运行。不保存这个发行版的任何信息:不记住在其中打开过的文件夹,每次打开本窗口时重新读取列表。", + "desktop.remote.wsl.distributionInvalid": "wsl.exe 不接受这个发行版名称。", + "desktop.remote.wsl.heading": "WSL", + "desktop.remote.wsl.kind": "本机 WSL 发行版", + "desktop.remote.wsl.missing": "本机找不到 wsl.exe。安装适用于 Linux 的 Windows 子系统(WSL)后才能打开发行版。", + "desktop.remote.wsl.start": "启动发行版", + "desktop.remote.wsl.unreachable": "这个 WSL 发行版没有安装,或者没能启动。", + "desktop.remote.wsl.user": "Linux 用户", + "desktop.remote.wsl.userHelp": "工作区以哪个账户运行。留空则使用发行版的默认用户。", + "desktop.remote.wsl.userInvalid": "Linux 不接受这个用户名。", + "desktop.remote.wsl.userPlaceholder": "默认用户", + "desktop.remote.wsl.userTooLong": "Linux 用户名最多 32 个字符。", "desktop.remoteAuth.failed": "无法把回答交给 SSH:{reason}", "desktop.remoteAuth.refused": "SSH 没有接受这个回答:回答最多 8192 字节,且不能包含换行。这个问题已取消。", "desktop.remoteAuth.secretHint": "回答只交给这次 SSH 连接,Lithe 不会保存。", diff --git a/desktop/internal/remoteconn/trust_test.go b/desktop/internal/remoteconn/trust_test.go index 115a85ca1..589246362 100644 --- a/desktop/internal/remoteconn/trust_test.go +++ b/desktop/internal/remoteconn/trust_test.go @@ -70,9 +70,11 @@ func TestRemoteTrustRevokeRemovesRecordsWithoutAConnection(t *testing.T) { } devbox := `{"hops":[{"ssh":{"destination":"devbox","port":2222,"user":"dev"}}]}` lab := `{"hops":[{"ssh":{"destination":"lab"}},{"container":{"engine":"docker","program":"docker","container":"web"}}]}` + wsl := `{"hops":[{"wsl":{"distribution":"Ubuntu","user":"dev"}}]}` seed := `{"version":1,"targets":[` + `{"target":` + devbox + `,"label":"Dev box","trustedWorkspaces":["/srv/app"],"distrustedWorkspaces":["/srv/tmp"]},` + - `{"target":` + lab + `,"trustedLocations":["/work"]}]}` + `{"target":` + lab + `,"trustedLocations":["/work"]},` + + `{"target":` + wsl + `,"trustedWorkspaces":["/home/dev/app"]}]}` if err := os.WriteFile(file, []byte(seed), 0o600); err != nil { t.Fatal(err) } @@ -81,7 +83,7 @@ func TestRemoteTrustRevokeRemovesRecordsWithoutAConnection(t *testing.T) { t.Fatal(err) } targets := trust.State.Document.Targets - if len(targets) != 2 { + if len(targets) != 3 { t.Fatalf("targets = %d", len(targets)) } if place := targets[0].Place(); targets[0].Label != "Dev box" || place != "dev@devbox:2222" { @@ -90,10 +92,14 @@ func TestRemoteTrustRevokeRemovesRecordsWithoutAConnection(t *testing.T) { if place := targets[1].Place(); place != "lab → docker:web" { t.Fatalf("second target place matches = %v", place == "lab → docker:web") } + // A WSL distribution is named as the connection window names it. + if place := targets[2].Place(); place != "wsl:dev@Ubuntu" { + t.Fatalf("WSL target place matches = %v", place == "wsl:dev@Ubuntu") + } absent := []core.RemoteWorkspaceTrustRevoke{{Target: targets[0].Target, List: core.RemoteTrustTrustedLocations, Path: "/srv"}} after, committed, err := trust.Revoke(ctx, kernel, absent) - if err != nil || committed || len(after.Targets) != 2 { + if err != nil || committed || len(after.Targets) != 3 { t.Fatalf("absent removal: committed = %v, targets = %d, err = %v", committed, len(after.Targets), err) } if text, _ := os.ReadFile(file); string(text) != seed { @@ -103,6 +109,7 @@ func TestRemoteTrustRevokeRemovesRecordsWithoutAConnection(t *testing.T) { after, committed, err = trust.Revoke(ctx, kernel, []core.RemoteWorkspaceTrustRevoke{ {Target: targets[0].Target, List: core.RemoteTrustDistrustedWorkspaces, Path: "/srv/tmp"}, {Target: targets[1].Target, List: core.RemoteTrustTrustedLocations, Path: "/work"}, + {Target: targets[2].Target, List: core.RemoteTrustTrustedWorkspaces, Path: "/home/dev/app"}, }) if err != nil || !committed { t.Fatalf("removal: committed = %v, err = %v", committed, err) diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 806f09972..667165c66 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -212,6 +212,7 @@ type Kernel interface { RemoteConnections(ctx context.Context, document *string) (core.RemoteConnectionsState, error) EditRemoteConnections(ctx context.Context, document *string, edit core.RemoteConnectionEdit) (core.RemoteConnectionsPublication, error) RemoteProbe(ctx context.Context, connection core.SSHConnection) (core.RemoteProbeResult, error) + RemoteListWSLDistributions(ctx context.Context) (core.RemoteWSLDistributions, error) RemoteAuthRespond(ctx context.Context, requestID string, answer *string) (bool, error) RemoteConnect(ctx context.Context, request core.RemoteConnectRequest) (core.RemoteConnectResult, error) RemoteDisconnect(ctx context.Context, sessionID string) (bool, error) diff --git a/desktop/internal/workbench/remote.go b/desktop/internal/workbench/remote.go index 85cb1a687..8b5306a88 100644 --- a/desktop/internal/workbench/remote.go +++ b/desktop/internal/workbench/remote.go @@ -104,6 +104,8 @@ type remoteState struct { // importer is the import page, nil when it is not shown; imports are the counts the empty // page and the import menu name. importer *remoteImporter + // wsl is this computer's WSL distributions, read once per opening (remote_wsl.go). + wsl remoteWSL // log folds OpenSSH's words under a failed test or connection. log ui.CollapsibleState imports remoteImportCounts @@ -126,14 +128,17 @@ type remoteForm struct { // have this name, since Core refuses control characters in one. const remoteNewGroup = "\x00new" -// remoteListRow is a row of the saved list: a section's heading, or a saved connection. +// remoteListRow is a row of the list: a section's heading, a saved connection, or a WSL +// distribution. type remoteListRow struct { // heading is set on a section's heading, which names group ("" for the connections without - // one) and the number of connections in the section. + // one, remoteWSLHeading for the WSL distributions) and the number of rows in the section. heading bool group string count int entry *core.SavedRemoteConnection + // wsl is the distribution of a WSL row. + wsl string } // remoteProbe is a test in progress, cancelled by Stop or by closing the window. @@ -147,6 +152,8 @@ type remoteProbeOutcome struct { // at is when the test ended, for the overview's "tested 5 minutes ago". at time.Time err error + // wsl is set when the host was a WSL distribution, whose failures read differently. + wsl bool } // remoteFieldRefusal is the field of the form Core (or the form's own number check) refused, and @@ -174,6 +181,7 @@ func (a *App) openRemote(surface actionSurface) { r.form.clear() a.performed("remote.connections.open", surface) a.loadRemote(remoteLoadSelectFirst, "") + a.loadRemoteWSL() } // closeRemote closes the window, stopping a running test or connection and ending the session a @@ -380,16 +388,22 @@ func (r *remoteState) probedOutcome(connection core.SSHConnection) *remoteProbeO return r.probed[remoteStored(connection)] } -// resetEditing drops the last test or connection, its errors and the delete question. +// resetEditing drops the last test or connection, its errors, the delete question and the WSL +// distribution shown. func (r *remoteState) resetEditing() { r.stopProbe() r.stopConnect() r.result, r.err, r.fieldErr, r.confirmDelete = nil, "", remoteFieldRefusal{}, false + r.wsl.selected = "" } -// syncListSelection selects the row of the edited connection, none for a new one. +// syncListSelection selects the row of the edited connection or the WSL distribution shown, none +// for a new connection. func (r *remoteState) syncListSelection() { at := r.rowOf(r.selected) + if r.wsl.selected != "" { + at = r.wslRow(r.wsl.selected) + } if r.list.Selected() != at { r.list.Select(at) if at >= 0 { diff --git a/desktop/internal/workbench/remote_browse.go b/desktop/internal/workbench/remote_browse.go index 53debbdf6..e59688a16 100644 --- a/desktop/internal/workbench/remote_browse.go +++ b/desktop/internal/workbench/remote_browse.go @@ -24,16 +24,17 @@ import ( // the folder is chosen: Back, closing the window and quitting end it. Opening the folder hands it // to the workspace (remote_workspace.go) and remembers the folder with the connection. // -// Only a saved connection connects, as saved: the workspace connects again with the same, and -// the folder it remembers belongs to the entry. OpenSSH's questions are asked in the -// authentication dialog, as a test asks them. +// Only a saved connection or a WSL distribution of this computer connects (remote_wsl.go), as +// shown: the workspace connects again with the same, and the folder it remembers belongs to the +// saved entry. OpenSSH's questions are asked in the authentication dialog, as a test asks them. // remoteBrowser chooses the host folder to open over a session the window connected. type remoteBrowser struct { - session core.RemoteSession - entryID string - name string - connection core.SSHConnection + session core.RemoteSession + // entryID and name are the saved connection's, or the WSL distribution's identity and name. + entryID string + name string + host remoteHost // recent are the connection's recent folders, latest first. recent []string // path is what the path field holds. dir is the folder listed last, or tried last when it @@ -66,28 +67,39 @@ func (r *remoteState) stopConnect() { } } -// connectable says whether Connect may start for the selected connection: it is saved, the form -// shows it as saved, and nothing else runs. +// connectable says whether Connect may start for what the page shows: a WSL distribution, or a +// saved connection the form shows as saved; and nothing else runs. func (r *remoteState) connectable() bool { return r.open && r.browser == nil && r.connect == nil && r.probe == nil && !r.saving && - r.entry(r.selected) != nil && !r.dirty() + (r.wsl.selected != "" || (r.entry(r.selected) != nil && !r.dirty())) } -// connectRemote connects to the selected saved connection's host, showing each step and the -// questions OpenSSH asks on the page, then opens folder on it, or lists the host's folders to -// choose one when folder is "". +// connectTarget is what Connect connects to: the WSL distribution shown, as an entry named after +// it with its identity for id, or the selected saved connection. +func (r *remoteState) connectTarget() (core.SavedRemoteConnection, remoteHost) { + if r.wsl.selected != "" { + wsl := r.wsl.connection() + return core.SavedRemoteConnection{ID: wsl.Identity(), Name: wsl.Distribution}, remoteHost{wsl: &wsl} + } + entry := *r.entry(r.selected) + return entry, remoteHost{ssh: entry.Connection} +} + +// connectRemote connects to the host the page shows, showing each step and the questions OpenSSH +// asks on the page, then opens folder on it, or lists the host's folders to choose one when folder +// is "". func (a *App) connectRemote(folder string) { r := &a.remote if !r.connectable() { return } - entry := *r.entry(r.selected) + entry, host := r.connectTarget() r.result, r.err, r.fieldErr, r.confirmDelete, r.moreMenu = nil, "", remoteFieldRefusal{}, false, false a.performed("remote.connect", surfaceButton) ctx, cancel := context.WithTimeout(a.operationContext(context.Background()), remoteProbeTimeout) attempt := &remoteProbe{cancel: cancel} r.connect = attempt - steps := newRemoteSteps(entry, folder, a.now()) + steps := newRemoteSteps(entry, host, folder, a.now()) r.steps = steps ctx = core.WithRemoteStages(ctx, func(stage core.RemoteStage) { a.post(func(a *App) { @@ -99,7 +111,7 @@ func (a *App) connectRemote(folder string) { generation, kernel := r.generation, a.kernel a.background(nil, 0, func(context.Context) func(*App) { defer cancel() - result, err := a.connectRemoteHost(a.gitAuthentication(ctx), kernel, entry.Connection) + result, err := a.connectRemoteHost(a.gitAuthentication(ctx), kernel, host) return func(a *App) { r := &a.remote if !r.open || r.generation != generation || r.connect != attempt { @@ -112,7 +124,7 @@ func (a *App) connectRemote(folder string) { r.connect = nil if err == nil && result.Status == core.RemoteProbeConnected && result.Session != nil { r.steps = nil - a.browseRemote(entry, *result.Session) + a.browseRemote(entry, host, *result.Session) if folder != "" { a.openRemoteFolderAt(folder) } @@ -124,11 +136,16 @@ func (a *App) connectRemote(folder string) { if field, reason, ok := core.RemoteConnectionFieldError(err); ok { a.operationRejected("remote_connect", "field_refused") r.steps = nil - r.err = remoteRefusalText(a.language(), remoteFieldRefusal{field: field, reason: reason}) + refusal := remoteFieldRefusal{field: field, reason: reason} + if host.wsl != nil { + r.err = remoteWSLRefusalText(a.language(), refusal) + } else { + r.err = remoteRefusalText(a.language(), refusal) + } return } a.operationFailed("remote_connect", remoteConnectFailure(result, err)) - steps.fail(a.now(), remoteConnectOutcome(result, err), a.language()) + steps.fail(a.now(), remoteConnectOutcome(host, result, err), a.language()) r.log.Open = true } }) @@ -160,10 +177,11 @@ func remoteConnectFailureText(language i18n.Language, err error) string { return "" } -// browseRemote starts choosing the folder to open over session, in the account's home directory. -func (a *App) browseRemote(entry core.SavedRemoteConnection, session core.RemoteSession) { +// browseRemote starts choosing the folder to open over session to host, in the account's home +// directory. +func (a *App) browseRemote(entry core.SavedRemoteConnection, host remoteHost, session core.RemoteSession) { r := &a.remote - r.browser = &remoteBrowser{session: session, entryID: entry.ID, name: entry.Name, connection: entry.Connection, recent: entry.RecentFolders} + r.browser = &remoteBrowser{session: session, entryID: entry.ID, name: entry.Name, host: host, recent: entry.RecentFolders} start := session.HomeDirectory if !path.IsAbs(start) { start = "/" @@ -394,8 +412,8 @@ func (a *App) openRemoteFolder() { } // openRemoteFolderNow opens dir once its trust is decided (remote_trust.go), trusted when trusted -// is set and in safe mode otherwise. It also marks the connection as connected now, for the -// list's "2 hours ago". +// is set and in safe mode otherwise. It also marks a saved connection as connected now, for the +// list's "2 hours ago"; a WSL distribution is not saved, so nothing is remembered for it. func (a *App) openRemoteFolderNow(dir string, trusted bool) { r := &a.remote b := r.browser @@ -403,7 +421,7 @@ func (a *App) openRemoteFolderNow(dir string, trusted bool) { return } b.opening, b.err = true, "" - entryID := b.entryID + entryID, remember := b.entryID, b.host.wsl == nil generation, kernel, toolRoot := r.generation, a.kernel, a.globalToolchainRoot() a.background(nil, remoteReadTimeout, func(ctx context.Context) func(*App) { anchor, err := a.remotePlaceholderAnchor() @@ -411,7 +429,7 @@ func (a *App) openRemoteFolderNow(dir string, trusted bool) { err = remoteplaceholder.Ensure(anchor) } var rememberErr error - if err == nil { + if err == nil && remember { // The folder is remembered even when the workspace then fails to open, as the editor // remembers a project it opened. var source remoteconn.Source @@ -445,7 +463,7 @@ func (a *App) openRemoteFolderNow(dir string, trusted bool) { return } target := remoteTarget{ - connectionID: b.entryID, name: b.name, connection: b.connection, session: b.session, + connectionID: b.entryID, name: b.name, host: b.host, session: b.session, remoteRoot: dir, root: remoteplaceholder.Root(anchor, b.entryID, dir), trusted: trusted, } // The session is the workspace's from here on. diff --git a/desktop/internal/workbench/remote_browse_view.go b/desktop/internal/workbench/remote_browse_view.go index fa1945f97..7cee63bc5 100644 --- a/desktop/internal/workbench/remote_browse_view.go +++ b/desktop/internal/workbench/remote_browse_view.go @@ -75,7 +75,7 @@ func (a *App) remoteBrowserHead(c ui.C, language i18n.Language, b *remoteBrowser FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().Shrink(1).MinWidth(0) ui.Row(c.Part("state")).FillWidth().Gap(8).Items(ui.Center).Children(func() { a.remoteStatusPill(c.Part("live"), i18n.Shared(language, "desktop.remote.browse.connected"), a.colors.Success) - ui.Text(c, remoteAddress(b.connection)).Mono().FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) + ui.Text(c, b.host.address()).Mono().FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) if system != "" { ui.Text(c, system).FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().Shrink(1).MinWidth(0) } diff --git a/desktop/internal/workbench/remote_connections_visual_test.go b/desktop/internal/workbench/remote_connections_visual_test.go index 6b01f240c..13ee38d16 100644 --- a/desktop/internal/workbench/remote_connections_visual_test.go +++ b/desktop/internal/workbench/remote_connections_visual_test.go @@ -18,7 +18,8 @@ import ( // saved, saved connections under their groups with the tested one's overview, its form, a new // connection whose host Core refused under its field, OpenSSH's password question over the window, // a refused test, the connection steps with OpenSSH's questions on the page and a failure, the -// question whether to trust a folder, and Motty's hosts to import. +// question whether to trust a folder, Motty's hosts to import, the host's folders, and a WSL +// distribution's page and a failed connection to one. func TestVisualRemoteConnections(t *testing.T) { out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") if out == "" { @@ -194,7 +195,7 @@ func TestVisualRemoteConnections(t *testing.T) { // Connecting runs the steps on the page, with OpenSSH's questions under the step that // asks them. r.selectEntry(buildBox) - steps := newRemoteSteps(*r.entry(buildBox), "", h.app.now()) + steps := newRemoteSteps(*r.entry(buildBox), remoteHost{ssh: r.entry(buildBox).Connection}, "", h.app.now()) r.steps = steps asked := make(chan struct{}) h.app.gitAuth.queue = []core.GitAuthChallenge{{ @@ -218,7 +219,7 @@ func TestVisualRemoteConnections(t *testing.T) { // The first time a folder opens, the window asks whether to trust it. parent := "/home/dev" r.selectEntry(buildBox) - r.trust = &remoteTrustPrompt{browser: &remoteBrowser{entryID: buildBox, name: "Build box", connection: r.entry(buildBox).Connection}, dir: "/home/dev/project", trust: remoteconn.Trust{ + r.trust = &remoteTrustPrompt{browser: &remoteBrowser{entryID: buildBox, name: "Build box", host: remoteHost{ssh: r.entry(buildBox).Connection}}, dir: "/home/dev/project", trust: remoteconn.Trust{ State: core.RemoteWorkspaceTrustState{WorkspaceTrust: &core.RemoteWorkspaceTrustOf{ State: core.WorkspaceTrustUnset, Workspace: "/home/dev/project", OfferedLocation: &parent, }}, @@ -264,7 +265,7 @@ func TestVisualRemoteConnections(t *testing.T) { // Once connected, the page lists the host's folders to open one. r.selectEntry(buildBox) - browser := &remoteBrowser{entryID: buildBox, name: "Build box", connection: r.entry(buildBox).Connection, + browser := &remoteBrowser{entryID: buildBox, name: "Build box", host: remoteHost{ssh: r.entry(buildBox).Connection}, recent: []string{"/home/dev/src/lithe", "/srv/ci/workspace"}, dir: "/home/dev/src", folders: []string{"lithe", "lithe-core-rust", "scratch"}, files: []string{"README.txt"}, repositories: map[string]bool{"lithe": true, "lithe-core-rust": true}, @@ -273,6 +274,26 @@ func TestVisualRemoteConnections(t *testing.T) { r.browser = browser shot("folder") r.browser = nil + + // This computer's WSL distributions list under their own heading, and one opens as the + // Linux account typed on its page; one that does not start fails with WSL's own text. + // The distributions come from wsl.exe; the scenes show fixed ones. + r.wsl.loaded = true + r.wsl.list = core.RemoteWSLDistributions{Available: true, Distributions: []string{"Ubuntu-24.04", "Debian"}} + r.buildRows() + r.selectRemoteWSL("Ubuntu-24.04") + r.wsl.user.SetText("dev") + shot("wsl") + r.selectRemoteWSL("Debian") + gone := &core.WSLConnection{Distribution: "Debian"} + steps = newRemoteSteps(core.SavedRemoteConnection{ID: gone.Identity(), Name: "Debian"}, remoteHost{wsl: gone}, "", h.app.now()) + r.steps = steps + steps.fail(h.app.now(), &remoteProbeOutcome{result: core.RemoteProbeResult{ + Status: core.RemoteProbeUnreachable, Diagnostics: "There is no distribution with the supplied name.", + }, wsl: true, at: h.app.now()}, h.app.language()) + r.log.Open = true + shot("wsl-failed") + r.steps = nil h.app.closeRemote() h.settleChain() }) diff --git a/desktop/internal/workbench/remote_detail_view.go b/desktop/internal/workbench/remote_detail_view.go index 850f6dfd9..1ad6896dd 100644 --- a/desktop/internal/workbench/remote_detail_view.go +++ b/desktop/internal/workbench/remote_detail_view.go @@ -30,6 +30,8 @@ func (a *App) remotePage(c ui.C, language i18n.Language) { } entry := r.entry(r.selected) switch { + case r.wsl.selected != "": + a.remoteWSLPage(c, language) case r.editing: a.remoteFormPage(c, language) case entry != nil: @@ -449,7 +451,8 @@ func (a *App) remoteHostTags(c ui.C, language i18n.Language, host core.RemotePro // remoteFailureHint says what to check after a test that did not connect, and is "" when there // is nothing more to say than why it failed. func remoteFailureHint(language i18n.Language, outcome *remoteProbeOutcome) string { - if outcome.err != nil { + // The hints name OpenSSH's settings, which a WSL distribution does not have. + if outcome.err != nil || outcome.wsl { return "" } switch outcome.result.Status { @@ -578,6 +581,8 @@ func (a *App) remoteFooter(c ui.C, language i18n.Language) { entry := r.entry(r.selected) ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { switch { + case r.wsl.selected != "": + a.remoteWSLFooter(c, language) case r.editing: a.remoteFormFooter(c, language, entry) case entry != nil && r.confirmDelete: diff --git a/desktop/internal/workbench/remote_list.go b/desktop/internal/workbench/remote_list.go index 75a8bc724..424efe63b 100644 --- a/desktop/internal/workbench/remote_list.go +++ b/desktop/internal/workbench/remote_list.go @@ -40,8 +40,9 @@ type remoteFormValues struct { } // buildRows lays out the list from the sections Core found for the query while one is typed, else -// from the source's, under a heading for each group when any section names one. A folded group -// keeps its heading only, and a search unfolds every group. +// from the source's, under a heading for each group when any section names one, followed by the +// WSL distributions (remote_wsl.go). A folded group keeps its heading only, and a search unfolds +// every group. func (r *remoteState) buildRows() { r.rows = nil byID := make(map[string]*core.SavedRemoteConnection, len(r.source.Connections)) @@ -70,6 +71,7 @@ func (r *remoteState) buildRows() { } } } + r.rows = append(r.rows, r.wslRows()...) } // toggleRemoteGroup folds or unfolds group in the list. @@ -138,12 +140,18 @@ func (a *App) remoteLive(id string) bool { // remoteWindows is how many open windows work in a folder over the saved connection id. func (a *App) remoteWindows(id string) int { + return a.remoteWindowsWhere(func(other string) bool { return other == id }) +} + +// remoteWindowsWhere is how many open windows work in a folder over a connection whose id match +// accepts. +func (a *App) remoteWindowsWhere(match func(id string) bool) int { if a.sessions == nil { return 0 } count := 0 for _, w := range a.sessions.list { - if w.project != nil && w.project.remote != nil && w.project.remote.connectionID == id && + if w.project != nil && w.project.remote != nil && match(w.project.remote.connectionID) && w.project.remote.session != "" && !w.project.remote.closed { count++ } diff --git a/desktop/internal/workbench/remote_shell_view.go b/desktop/internal/workbench/remote_shell_view.go index 8b151ac9b..915df700a 100644 --- a/desktop/internal/workbench/remote_shell_view.go +++ b/desktop/internal/workbench/remote_shell_view.go @@ -82,6 +82,8 @@ func (a *App) remoteTitle(language i18n.Language) string { crumb = r.browser.name case r.steps != nil: crumb = r.steps.entry.Name + case r.wsl.selected != "": + crumb = r.wsl.selected case r.editing && r.entry(r.selected) == nil: crumb = i18n.Shared(language, "desktop.remote.newConnection") case r.editing: @@ -158,18 +160,27 @@ func (a *App) remoteRows(k ui.C, language i18n.Language, title string, rows []re if r.rows[row].heading { return remoteGroupHeading(language, r.rows[row].group) } + if r.rows[row].wsl != "" { + return r.rows[row].wsl + } return r.rows[row].entry.Name } r.list.Header = func(row int) bool { return row >= 0 && row < len(r.rows) && r.rows[row].heading } ui.List(k.Part("rows"), &r.list, len(rows), func(row ui.ListRow) { - if item := rows[row.Index]; item.heading { + switch item := rows[row.Index]; { + case item.heading: a.remoteHeadingRow(row, language, item) - } else { + case item.wsl != "": + a.remoteWSLRow(row, language, item.wsl) + default: a.remoteEntryRow(row, language, *item.entry) } }).Scrollbars().FillWidth().Grow(1).Shrink(1).MinHeight(0).Label(title) if r.list.Changed() { - if at := r.list.Selected(); at >= 0 && at < len(rows) && rows[at].entry != nil && (rows[at].entry.ID != r.selected || r.editing || r.steps != nil || r.browser != nil || r.importer != nil) { + away := r.steps != nil || r.browser != nil || r.importer != nil + at := r.list.Selected() + switch { + case at >= 0 && at < len(rows) && rows[at].entry != nil && (rows[at].entry.ID != r.selected || r.editing || r.wsl.selected != "" || away): id := rows[at].entry.ID c := k c.After(func() { @@ -180,6 +191,17 @@ func (a *App) remoteRows(k ui.C, language i18n.Language, title string, rows []re a.performed("remote.connection.select", surfaceButton) r.selectEntry(id) }) + case at >= 0 && at < len(rows) && rows[at].wsl != "" && (rows[at].wsl != r.wsl.selected || away): + name := rows[at].wsl + c := k + c.After(func() { + if !a.leaveRemoteFlows() { + r.syncListSelection() + return + } + a.performed("remote.wsl.select", surfaceButton) + r.selectRemoteWSL(name) + }) } } else { // The list selects only rows it has declared, so the row a save added becomes the diff --git a/desktop/internal/workbench/remote_status_view.go b/desktop/internal/workbench/remote_status_view.go index 04687c610..0782c7884 100644 --- a/desktop/internal/workbench/remote_status_view.go +++ b/desktop/internal/workbench/remote_status_view.go @@ -18,17 +18,17 @@ import ( func remoteStatusText(language i18n.Language, r *remoteProject) string { switch r.link { case remoteUnresponsive: - return i18n.SharedFormat(language, "desktop.remote.status.unresponsive", map[string]string{"name": r.name}) + return i18n.SharedFormat(language, "desktop.remote.status.unresponsive", map[string]string{"kind": r.host.kind(language), "name": r.name}) case remoteReconnecting: - return i18n.SharedFormat(language, "desktop.remote.status.reconnecting", map[string]string{"name": r.name}) + return i18n.SharedFormat(language, "desktop.remote.status.reconnecting", map[string]string{"kind": r.host.kind(language), "name": r.name}) case remoteDisconnected: - return i18n.SharedFormat(language, "desktop.remote.status.disconnected", map[string]string{"name": r.name}) + return i18n.SharedFormat(language, "desktop.remote.status.disconnected", map[string]string{"kind": r.host.kind(language), "name": r.name}) } if r.latency <= 0 { - return i18n.SharedFormat(language, "desktop.remote.status.connected", map[string]string{"name": r.name}) + return i18n.SharedFormat(language, "desktop.remote.status.connected", map[string]string{"kind": r.host.kind(language), "name": r.name}) } ms := strconv.FormatInt(max(r.latency.Milliseconds(), 1), 10) - return i18n.SharedFormat(language, "desktop.remote.status.latency", map[string]string{"name": r.name, "ms": ms}) + return i18n.SharedFormat(language, "desktop.remote.status.latency", map[string]string{"kind": r.host.kind(language), "name": r.name, "ms": ms}) } // remoteStatusLook is the icon of the item and its colour for r's link. diff --git a/desktop/internal/workbench/remote_steps.go b/desktop/internal/workbench/remote_steps.go index e79ccd902..41a06e5f1 100644 --- a/desktop/internal/workbench/remote_steps.go +++ b/desktop/internal/workbench/remote_steps.go @@ -17,6 +17,10 @@ import ( // OpenSSH asks, under the step that asks them: the host key under the connection, the rest under // the authentication. The authentication dialog leaves those questions to the page while it is // shown. A connection that fails stays on the page, at the step it failed, with why. +// +// A WSL distribution has no OpenSSH configuration to read and asks nothing, so its steps start at +// the connection, named as starting the distribution: Core reports the same stages once its shell +// answers. // remoteStep is one step of a connection, in the order they run. type remoteStep int @@ -52,6 +56,7 @@ func remoteStepName(language i18n.Language, step remoteStep) string { // remoteSteps is a connection the page shows running, or failed. type remoteSteps struct { entry core.SavedRemoteConnection + host remoteHost // folder is what opens once connected, "" to choose one. folder string // reached is the step running, or the one that failed. @@ -64,10 +69,24 @@ type remoteSteps struct { outcome *remoteProbeOutcome } -// newRemoteSteps starts showing a connection to entry. The configuration is read before Core -// starts, so the connection itself runs first. -func newRemoteSteps(entry core.SavedRemoteConnection, folder string, now time.Time) *remoteSteps { - return &remoteSteps{entry: entry, folder: folder, reached: remoteStepConnect, began: now} +// newRemoteSteps starts showing a connection to host, named as entry. The configuration is read +// before Core starts, so the connection itself runs first. +func newRemoteSteps(entry core.SavedRemoteConnection, host remoteHost, folder string, now time.Time) *remoteSteps { + return &remoteSteps{entry: entry, host: host, folder: folder, reached: remoteStepConnect, began: now} +} + +// shows says whether the page lists step: every step over SSH, and over WSL the steps after +// starting the distribution, which reads no configuration and asks nothing. +func (s *remoteSteps) shows(step remoteStep) bool { + return s.host.wsl == nil || (step != remoteStepConfig && step != remoteStepAuthenticate) +} + +// name is step's name for this connection: over WSL, the connection starts the distribution. +func (s *remoteSteps) name(language i18n.Language, step remoteStep) string { + if step == remoteStepConnect && s.host.wsl != nil { + return i18n.Shared(language, "desktop.remote.wsl.start") + } + return remoteStepName(language, step) } // advance ends the steps before to. @@ -150,15 +169,20 @@ func (a *App) remoteStepsView(c ui.C, language i18n.Language, s *remoteSteps) { a.remoteTile(c.Part("tile"), remoteSystemMark(a.remote.probedOutcome(s.entry.Connection)), s.entry.Name, s.entry.Color, remoteHeroTile, 15) ui.Column(c).Grow(1).Basis(0).MinWidth(0).Gap(5).Children(func() { ui.Text(c, title).FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().MinWidth(0) - ui.Text(c, remoteAddress(s.entry.Connection)).Mono().FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + ui.Text(c, s.host.address()).Mono().FontSize(a.theme.Metrics.FontSizeS).Color(a.colors.Subtle).Ellipsis().MinWidth(0) }) }) a.remoteBordered(c.Part("list")).Children(func() { + first := true for step := remoteStepConfig; step < remoteStepCount; step++ { + if !s.shows(step) { + continue + } k := c.KeyInt(int(step)) - if step > 0 { + if !first { ui.Row(k.Part("line")).FillWidth().Height(1).Shrink(0).Background(a.colors.Line) } + first = false a.remoteStepRow(k, language, s, step, reached, question) } }) @@ -193,7 +217,7 @@ func (a *App) remoteStepRow(c ui.C, language i18n.Language, s *remoteSteps, step if !done && !current { color = a.colors.Subtle } - label := ui.Text(c, remoteStepName(language, step)).Color(color).Grow(1).MinWidth(0).Ellipsis() + label := ui.Text(c, s.name(language, step)).Color(color).Grow(1).MinWidth(0).Ellipsis() if current { label.Weight(gfx.WeightMedium) } @@ -309,7 +333,7 @@ func (a *App) remoteQuestionCard(c ui.C, language i18n.Language, s *remoteSteps, } // remoteStepsFooter declares the buttons under a connection: Stop while it runs; back to the -// connection, its form, or again once it failed. +// connection, its form, or again once it failed. A WSL distribution has no form to go to. func (a *App) remoteStepsFooter(c ui.C, language i18n.Language, s *remoteSteps) { r := &a.remote ui.Row(c).FillWidth().Items(ui.Center).Gap(8).Children(func() { @@ -324,7 +348,7 @@ func (a *App) remoteStepsFooter(c ui.C, language i18n.Language, s *remoteSteps) c.After(func() { r.steps = nil }) } ui.Spacer(c) - if ui.Button(c.Part("edit"), i18n.Shared(language, "desktop.remote.steps.editConnection")).Outline().Disabled(!r.editable()).Clicked() { + if s.host.wsl == nil && ui.Button(c.Part("edit"), i18n.Shared(language, "desktop.remote.steps.editConnection")).Outline().Disabled(!r.editable()).Clicked() { c.After(func() { r.steps = nil a.editSelectedRemote() diff --git a/desktop/internal/workbench/remote_trust.go b/desktop/internal/workbench/remote_trust.go index 64ce73d34..e673e838a 100644 --- a/desktop/internal/workbench/remote_trust.go +++ b/desktop/internal/workbench/remote_trust.go @@ -220,7 +220,7 @@ func (a *App) remoteTrustView(c ui.C, language i18n.Language, t *remoteTrustProm ui.Column(c).Grow(1).Basis(0).MinWidth(0).Gap(12).Children(func() { ui.Column(c).FillWidth().Gap(6).Children(func() { ui.Text(c, i18n.Shared(language, "desktop.remote.trust.title")).FontSize(16).Weight(gfx.WeightSemibold) - ui.Text(c, remoteAddress(t.browser.connection)+" : "+t.dir).Mono().FontSize(small).Ellipsis().Shrink(1).MinWidth(0) + ui.Text(c, t.browser.host.address()+" : "+t.dir).Mono().FontSize(small).Ellipsis().Shrink(1).MinWidth(0) }) ui.Paragraph(c.Part("body"), i18n.Shared(language, "desktop.remote.trust.body"), 6).FontSize(small).Color(a.colors.Subtle) ui.Column(c.Part("choices")).FillWidth().Gap(4).Pad(12).Radius(8).Stroke(1, a.colors.Line).Children(func() { diff --git a/desktop/internal/workbench/remote_view.go b/desktop/internal/workbench/remote_view.go index 9faa3c075..6bfed06f3 100644 --- a/desktop/internal/workbench/remote_view.go +++ b/desktop/internal/workbench/remote_view.go @@ -39,8 +39,11 @@ var remoteColorChoices = append([]core.RemoteConnectionColor{""}, core.RemoteCon // remoteGroupHeading is the heading of group in the list, "" being the connections without one. func remoteGroupHeading(language i18n.Language, group string) string { - if group == "" { + switch group { + case "": return i18n.Shared(language, "desktop.remote.ungrouped") + case remoteWSLHeading: + return i18n.Shared(language, "desktop.remote.wsl.heading") } return group } @@ -332,6 +335,9 @@ func remoteFailureText(language i18n.Language, outcome *remoteProbeOutcome) stri } var coreErr *core.Error if errors.As(err, &coreErr) && coreErr.Code == core.CodeRuntimeMissing { + if outcome.wsl { + return i18n.Shared(language, "desktop.remote.wsl.missing") + } return i18n.Shared(language, "desktop.remote.probe.noSSH") } return i18n.SharedFormat(language, "desktop.remote.probe.error", map[string]string{"reason": remoteLogError(err).Error()}) @@ -351,6 +357,9 @@ func remoteFailureText(language i18n.Language, outcome *remoteProbeOutcome) stri case core.RemoteProbeHostKeyRejected: return i18n.Shared(language, "desktop.remote.probe.hostKeyRejected") case core.RemoteProbeUnreachable: + if outcome.wsl { + return i18n.Shared(language, "desktop.remote.wsl.unreachable") + } return i18n.Shared(language, "desktop.remote.probe.unreachable") } return i18n.Shared(language, "desktop.remote.probe.failed") diff --git a/desktop/internal/workbench/remote_workspace.go b/desktop/internal/workbench/remote_workspace.go index 6906f4c93..524ad9eb3 100644 --- a/desktop/internal/workbench/remote_workspace.go +++ b/desktop/internal/workbench/remote_workspace.go @@ -12,7 +12,8 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/remoteserver" ) -// A remote workspace is a project whose folder is on an SSH host (#2231, R0). Its root is a +// A remote workspace is a project whose folder is on an SSH host or in a WSL distribution of this +// computer (#2231, R0; remote_wsl.go). Its root is a // placeholder below a read-only file of the user's cache directory (remoteplaceholder), and its // context carries a core.RemoteWorkspace binding: every Core request of the project runs on the // host or is refused with not_supported, and a local call with a path of the project fails @@ -76,11 +77,12 @@ const ( type remoteProject struct { // binding carries the session and the two roots in every Core request of the project. binding *core.RemoteWorkspace - // connectionID, name and connection are the saved connection the workspace was opened over, - // as it was when the workspace opened; connecting again uses the same. + // connectionID, name and host are the saved connection, or the WSL distribution, the + // workspace was opened over, as it was when the workspace opened; connecting again uses the + // same. A WSL distribution's id is its identity (core.WSLConnection.Identity). connectionID string name string - connection core.SSHConnection + host remoteHost // session is the session the binding is attached to, "" while there is none. session string // home is the host account's home directory, "" when the host did not report it. @@ -117,7 +119,7 @@ type remoteProject struct { type remoteTarget struct { connectionID string name string - connection core.SSHConnection + host remoteHost session core.RemoteSession // remoteRoot is the host folder, an absolute POSIX path; root is its local placeholder. remoteRoot string @@ -198,9 +200,9 @@ func (a *App) remotePlaceholderAnchor() (string, error) { return remoteplaceholder.DefaultAnchor() } -// connectRemoteHost opens a session to the host of connection with the server builds the client -// carries. It runs off the window thread. -func (a *App) connectRemoteHost(ctx context.Context, kernel Kernel, connection core.SSHConnection) (core.RemoteConnectResult, error) { +// connectRemoteHost opens a session to host with the server builds the client carries. It runs +// off the window thread. +func (a *App) connectRemoteHost(ctx context.Context, kernel Kernel, host remoteHost) (core.RemoteConnectResult, error) { bundle, err := a.remoteServerBundle() if err != nil { return core.RemoteConnectResult{}, err @@ -209,12 +211,12 @@ func (a *App) connectRemoteHost(ctx context.Context, kernel Kernel, connection c for i, build := range bundle.Builds { servers[i] = core.RemoteServerBuild{Target: build.Target, Path: build.Path, SHA256: build.SHA256} } - return kernel.RemoteConnect(ctx, core.RemoteConnectRequest{Connection: connection, Servers: servers, ServerVersion: bundle.Version}) + return kernel.RemoteConnect(ctx, host.request(servers, bundle.Version)) } -// remoteConnectOutcome is a connection's result as the window shows a test's. -func remoteConnectOutcome(result core.RemoteConnectResult, err error) *remoteProbeOutcome { - return &remoteProbeOutcome{result: core.RemoteProbeResult{Status: result.Status, Host: result.Host, Diagnostics: result.Diagnostics}, err: err} +// remoteConnectOutcome is the result of a connection to host as the window shows a test's. +func remoteConnectOutcome(host remoteHost, result core.RemoteConnectResult, err error) *remoteProbeOutcome { + return &remoteProbeOutcome{result: core.RemoteProbeResult{Status: result.Status, Host: result.Host, Diagnostics: result.Diagnostics}, err: err, wsl: host.wsl != nil} } // remoteConnectFailure is the error the log keeps for a connection that failed: err, or Core's @@ -375,10 +377,10 @@ func (a *App) reconnectRemote(p *project, userStarted bool) { } attempt := &remoteProbe{cancel: cancel} r.reconnecting = attempt - kernel, connection := a.kernel, r.connection + kernel, host := a.kernel, r.host a.background(nil, 0, func(context.Context) func(*App) { defer cancel() - result, err := a.connectRemoteHost(ctx, kernel, connection) + result, err := a.connectRemoteHost(ctx, kernel, host) return func(a *App) { if a.project != p || r.closed || r.reconnecting != attempt { if result.Session != nil { @@ -397,7 +399,7 @@ func (a *App) reconnectRemote(p *project, userStarted bool) { if result.Session != nil { a.releaseRemoteSession(result.Session.ID) } - r.failure = remoteConnectOutcome(result, err) + r.failure = remoteConnectOutcome(host, result, err) if !userStarted && r.attempt < remoteReconnectAttempts && remoteRetryable(result.Status, err) { r.link = remoteReconnecting a.scheduleRemote(p, remoteReconnectPause(r.attempt), func(a *App, p *project) { a.reconnectRemote(p, false) }) @@ -495,7 +497,7 @@ func (a *App) openRemoteProject(target remoteTarget) { } name := path.Base(target.remoteRoot) p := &project{root: target.root, name: name, commit: newCommitState()} - r := &remoteProject{connectionID: target.connectionID, name: target.name, connection: target.connection, home: target.session.HomeDirectory} + r := &remoteProject{connectionID: target.connectionID, name: target.name, host: target.host, home: target.session.HomeDirectory} p.remote = r r.binding = core.NewRemoteWorkspace(target.root, target.remoteRoot, a.remoteSessionLost(p)) // Trusted, the workspace's Git runs on the host, and its commands are kept in the Git console diff --git a/desktop/internal/workbench/remote_workspace_test.go b/desktop/internal/workbench/remote_workspace_test.go index ebb8fdcec..254f50abb 100644 --- a/desktop/internal/workbench/remote_workspace_test.go +++ b/desktop/internal/workbench/remote_workspace_test.go @@ -80,6 +80,8 @@ type remoteHostKernel struct { git remoteHostGit // ports are the host's listening ports and the sessions' forwards (remote_ports_test.go). ports remoteHostPorts + // wsl is this computer's WSL distributions (remote_wsl_test.go). + wsl remoteHostWSL } // remoteTestTree is the workspace's tree the Project tool window lists by default. @@ -95,6 +97,9 @@ func (k *remoteHostKernel) RemoteConnect(_ context.Context, request core.RemoteC defer k.mu.Unlock() k.connects++ k.servers = append(k.servers, request.Servers) + if request.WSL != nil { + return k.wsl.connect(k.connects, request) + } if request.Connection.Host != remoteTestHost { return core.RemoteConnectResult{Status: core.RemoteProbeUnreachable}, nil } diff --git a/desktop/internal/workbench/remote_wsl.go b/desktop/internal/workbench/remote_wsl.go new file mode 100644 index 000000000..df606ddcd --- /dev/null +++ b/desktop/internal/workbench/remote_wsl.go @@ -0,0 +1,258 @@ +package workbench + +import ( + "context" + "slices" + "strconv" + "strings" + "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/icons" + "github.com/vivaui/viva/gfx" + "github.com/vivaui/viva/ui" +) + +// The Remote Development window also opens the distributions of the Windows Subsystem for Linux +// installed on this computer as remote workspaces (#2231). Core lists them each time the window +// opens (remote.listWslDistributions, which answers unavailable without running anything on other +// systems), and the list shows them under their own heading after the saved connections, while no +// search is typed: a search finds saved connections only. +// +// Nothing about a distribution is saved. It connects through the system's wsl.exe as the Linux +// account typed on its page, or the distribution's default user, and asks nothing, so no +// authentication dialog opens. The rest is the SSH path: the steps, the folder chosen on the host, +// the trust decision, the workspace and its reconnection. Its folders are not remembered, since the +// saved list holds SSH connections only. +// +// Neither the distribution nor the account is logged; wsl.exe's own words are shown under a failed +// connection and never logged. + +const ( + // remoteWSLHeading is the list's group of the WSL heading. No saved group can have it, since + // Core refuses control characters in one. + remoteWSLHeading = "\x00wsl" + // remoteWSLTimeout bounds listing the distributions. Core bounds wsl.exe at 15 seconds, the + // time the WSL service may take to start for the first time after Windows starts. + remoteWSLTimeout = 20 * time.Second + // remoteWSLPrefix starts the identity Core gives a WSL distribution (core.WSLConnection.Identity), + // which no saved connection's id starts with. + remoteWSLPrefix = "wsl:" +) + +// remoteHost is what a session connects to: a saved SSH connection, or a WSL distribution of this +// computer when wsl is set. +type remoteHost struct { + ssh core.SSHConnection + wsl *core.WSLConnection +} + +// address is the host as the window shows it: [user@]host[:port] for SSH and +// wsl:[user@]distribution for WSL. +func (h remoteHost) address() string { + if h.wsl != nil { + return h.wsl.Identity() + } + return remoteAddress(h.ssh) +} + +// kind is how the host is reached, as the window title and the status bar name it: SSH or WSL. +func (h remoteHost) kind(language i18n.Language) string { + if h.wsl != nil { + return i18n.Shared(language, "desktop.remote.wsl.heading") + } + return i18n.Shared(language, "desktop.remote.kind.ssh") +} + +// request is Core's request to connect to the host with servers, the server builds of version. +func (h remoteHost) request(servers []core.RemoteServerBuild, version string) core.RemoteConnectRequest { + request := core.RemoteConnectRequest{Servers: servers, ServerVersion: version} + if h.wsl != nil { + wsl := *h.wsl + request.WSL = &wsl + } else { + request.Connection = h.ssh + } + return request +} + +// remoteWSL is the window's WSL distributions. +type remoteWSL struct { + // list is Core's answer, once loaded. + loaded bool + list core.RemoteWSLDistributions + // selected is the distribution the page shows, "" while it shows a saved connection or none. + selected string + // user is the page's Linux account; empty is the distribution's default user. + user ui.Field +} + +// connection is the selected distribution as the page connects to it. The account is passed as +// typed, and Core trims it. +func (w *remoteWSL) connection() core.WSLConnection { + return core.WSLConnection{Distribution: w.selected, User: w.user.Text()} +} + +// wslShown says whether the list shows the WSL distributions: Core found some, and no search is +// typed. +func (r *remoteState) wslShown() bool { + return r.found == nil && r.wsl.list.Available && len(r.wsl.list.Distributions) > 0 +} + +// loadRemoteWSL asks Core for the WSL distributions in the background and lists them. +func (a *App) loadRemoteWSL() { + r := &a.remote + generation, kernel := r.generation, a.kernel + a.background(nil, remoteWSLTimeout, func(ctx context.Context) func(*App) { + list, err := kernel.RemoteListWSLDistributions(ctx) + return func(a *App) { + r := &a.remote + if !r.open || r.generation != generation { + // log-exempt: 用户取消:窗口关闭后不再应用发行版列表。 + return + } + r.wsl.loaded = true + if err != nil { + // The list only lacks its WSL distributions; nothing else depends on them. + a.backgroundFailed("remote_wsl_list", remoteLogError(err)) + return + } + r.wsl.list = list + r.buildRows() + r.syncListSelection() + } + }) +} + +// wslRows are the list's rows of the WSL distributions: their heading, and the distributions +// unless the heading is folded. +func (r *remoteState) wslRows() []remoteListRow { + if !r.wslShown() { + return nil + } + rows := []remoteListRow{{heading: true, group: remoteWSLHeading, count: len(r.wsl.list.Distributions)}} + if r.collapsed[remoteWSLHeading] { + return rows + } + for _, name := range r.wsl.list.Distributions { + rows = append(rows, remoteListRow{wsl: name}) + } + return rows +} + +// wslRow is the list row of the distribution name, -1 when the list has none. +func (r *remoteState) wslRow(name string) int { + return slices.IndexFunc(r.rows, func(row remoteListRow) bool { return row.wsl == name }) +} + +// selectRemoteWSL shows the page of the distribution name, as its default user, dropping what the +// form held, the last test and its errors. +func (r *remoteState) selectRemoteWSL(name string) { + r.resetEditing() + r.selected, r.editing = "", false + r.form.clear() + r.wsl.selected = name + r.wsl.user.SetText("") + r.syncListSelection() +} + +// remoteWSLWindows counts the workspaces open over the distribution name, as any account. +func (a *App) remoteWSLWindows(name string) int { + return a.remoteWindowsWhere(func(id string) bool { + rest, ok := strings.CutPrefix(id, remoteWSLPrefix) + if !ok { + return false + } + if _, distribution, ok := strings.Cut(rest, "@"); ok { + rest = distribution + } + return rest == name + }) +} + +// remoteWSLRefusalText is the window's text for a WSL field Core refused. +func remoteWSLRefusalText(language i18n.Language, refusal remoteFieldRefusal) string { + switch { + case refusal.field == "user" && refusal.reason == "tooLong": + return i18n.Shared(language, "desktop.remote.wsl.userTooLong") + case refusal.field == "user": + return i18n.Shared(language, "desktop.remote.wsl.userInvalid") + } + return i18n.Shared(language, "desktop.remote.wsl.distributionInvalid") +} + +// remoteWSLRow declares a distribution in the list: its mark, its name over how it is reached, and +// on the right whether a window has it open. +func (a *App) remoteWSLRow(row ui.ListRow, language i18n.Language, name string) { + r := &a.remote + rc := row.C + small := a.theme.Metrics.FontSizeS + row.Element.Height(remoteRowHeight).Items(ui.Center).Gap(9).PadSides(0, 12, 0, 0).Radius(6) + if name == r.wsl.selected { + row.Element.Background(a.colors.Selection) + } + // The stripe's room keeps the rows aligned with the saved connections'. + ui.Row(rc.Part("stripe")).Width(3).Height(remoteRowHeight - 14).Shrink(0) + a.remoteTile(rc.Part("tile"), "", name, "", 26, 10) + ui.Column(rc).Grow(1).Basis(0).MinWidth(0).Gap(2).Children(func() { + ui.Text(rc, name).Weight(gfx.WeightMedium).Ellipsis().MinWidth(0) + ui.Text(rc, i18n.Shared(language, "desktop.remote.wsl.kind")).FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + }) + if a.remoteWSLWindows(name) > 0 { + ui.Row(rc.Part("live")).Shrink(0).Items(ui.Center).Gap(5).Children(func() { + a.remoteDot(rc.Part("dot"), a.colors.Success, 6) + ui.Text(rc, i18n.Shared(language, "desktop.remote.connectedNow")).FontSize(small).Color(a.colors.Success) + }) + } +} + +// remoteWSLPage declares the selected distribution's page: its name, that it opens through +// wsl.exe on this computer, the account it opens as, and Open Folder. +func (a *App) remoteWSLPage(c ui.C, language i18n.Language) { + r := &a.remote + name := r.wsl.selected + small := a.theme.Metrics.FontSizeS + ui.Scroll(c.Part("wsl")).Fill().Children(func() { + ui.Column(c).FillWidth().Gap(22).PadSides(20, 24, 24, 24).Children(func() { + a.remoteNotices(c) + h := c.Part("hero") + ui.Row(h).FillWidth().Items(ui.Center).Gap(14).Children(func() { + a.remoteTile(h.Part("tile"), "", name, "", remoteHeroTile, 15) + ui.Column(h).Grow(1).Basis(0).MinWidth(0).Gap(5).Children(func() { + ui.Row(h).FillWidth().Items(ui.Center).Gap(8).Children(func() { + ui.Text(h, name).FontSize(16).Weight(gfx.WeightSemibold).Ellipsis().Shrink(1).MinWidth(0) + a.remotePill(h.Part("kind"), i18n.Shared(language, "desktop.remote.wsl.heading"), a.colors.Subtle) + if windows := a.remoteWSLWindows(name); windows > 0 { + a.remoteStatusPill(h.Part("live"), i18n.SharedFormat(language, "desktop.remote.connectedWindows", map[string]string{"count": strconv.Itoa(windows)}), a.colors.Success) + } + }) + wsl := r.wsl.connection() + ui.Text(h, wsl.Identity()).Mono().FontSize(small).Color(a.colors.Subtle).Ellipsis().MinWidth(0) + }) + if ui.Button(h.Part("open"), i18n.Shared(language, "desktop.remote.openFolder")).Icon(icons.FolderOpen).Shrink(0).Disabled(!r.connectable()).Clicked() { + c.After(func() { a.connectRemote("") }) + } + }) + ui.Paragraph(c.Part("about"), i18n.Shared(language, "desktop.remote.wsl.about"), 4).FontSize(small).Color(a.colors.Subtle) + label := i18n.Shared(language, "desktop.remote.wsl.user") + a.remoteSection(c.Part("account"), label, i18n.Shared(language, "desktop.remote.wsl.userHelp"), nil, func() { + ui.TextField(c.Part("user"), &r.wsl.user, label, i18n.Shared(language, "desktop.remote.wsl.userPlaceholder")). + Width(260).Disabled(r.connect != nil || r.browser != nil) + }) + }) + }) +} + +// remoteWSLFooter declares the buttons under a distribution's page: Close, and Connect, which lists +// its folders to choose one. +func (a *App) remoteWSLFooter(c ui.C, language i18n.Language) { + r := &a.remote + ui.Spacer(c) + if ui.Button(c.Part("close"), i18n.Shared(language, "desktop.remote.close")).Outline().Clicked() { + c.After(a.closeRemote) + } + if ui.Button(c.Part("connect"), i18n.Shared(language, "desktop.remote.connect")).Disabled(!r.connectable()).Clicked() { + c.After(func() { a.connectRemote("") }) + } +} diff --git a/desktop/internal/workbench/remote_wsl_test.go b/desktop/internal/workbench/remote_wsl_test.go new file mode 100644 index 000000000..3507de40f --- /dev/null +++ b/desktop/internal/workbench/remote_wsl_test.go @@ -0,0 +1,222 @@ +package workbench + +import ( + "context" + "slices" + "strconv" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/1lck/Lithe-IDEA/desktop/internal/remoteplaceholder" +) + +// The WSL distributions of the test's computer: remoteTestWSL is installed and connects, and +// remoteTestWSLGone is listed but does not start. +const ( + remoteTestWSL = "Ubuntu-24.04" + remoteTestWSLGone = "Debian" +) + +// remoteHostWSL stands in for wsl.exe: it lists the distributions and connects to remoteTestWSL +// alone, recording each connection asked for. Its zero value lists none, as Core answers on a +// system without WSL. +type remoteHostWSL struct { + list core.RemoteWSLDistributions + // lists counts the listings; requests are the connections asked for, in order. + lists int + requests []core.WSLConnection + // refuse is the error the next connections end with; nil connects. + refuse error +} + +func (k *remoteHostKernel) RemoteListWSLDistributions(context.Context) (core.RemoteWSLDistributions, error) { + k.mu.Lock() + defer k.mu.Unlock() + k.wsl.lists++ + return k.wsl.list, nil +} + +// connect answers the connect request numbered n, which names a WSL distribution. It runs under +// the kernel's lock. +func (w *remoteHostWSL) connect(n int, request core.RemoteConnectRequest) (core.RemoteConnectResult, error) { + w.requests = append(w.requests, *request.WSL) + if w.refuse != nil { + return core.RemoteConnectResult{}, w.refuse + } + if request.Connection != (core.SSHConnection{}) || request.WSL.Distribution != remoteTestWSL { + return core.RemoteConnectResult{Status: core.RemoteProbeUnreachable}, nil + } + session := &core.RemoteSession{ID: "session-" + strconv.Itoa(n), HostName: "wsl", UserName: "dev", HomeDirectory: remoteTestHome} + return core.RemoteConnectResult{Status: core.RemoteProbeConnected, Session: session}, nil +} + +// remoteWSLHarness is remoteWorkspaceHarness on a computer with remoteTestWSL and +// remoteTestWSLGone installed, the window opened again so that it lists them. +func remoteWSLHarness(t *testing.T) (*harness, *remoteHostKernel, *treeRecordingLog) { + t.Helper() + h, k, _, logger := remoteWorkspaceHarness(t) + k.set(func(k *remoteHostKernel) { + k.wsl.list = core.RemoteWSLDistributions{Available: true, Distributions: []string{remoteTestWSL, remoteTestWSLGone}} + }) + h.app.closeRemote() + h.app.openRemote(surfaceMenu) + h.await("the WSL distributions", func() bool { return h.app.remote.wsl.loaded && !h.app.remote.loading }) + h.settle() + return h, k, logger +} + +// The window lists the WSL distributions under their own heading after the saved connections, and +// a distribution's page opens a folder in it as the account typed: Core is asked to connect over +// wsl.exe, not OpenSSH, and the workspace names the distribution. Nothing is saved for it, and +// neither the distribution nor the account is logged. +func TestRemoteWSLOpensAFolderInADistribution(t *testing.T) { + h, k, logger := remoteWSLHarness(t) + lang := h.app.language() + r := &h.app.remote + heading := i18n.Shared(lang, "desktop.remote.wsl.heading") + if !h.shows(heading) || !h.shows(remoteTestWSL) || !h.shows(remoteTestWSLGone) { + t.Fatal("the list does not show the WSL heading with the distributions") + } + if at := r.wslRow(remoteTestWSL); at <= r.rowOf(r.selected) { + t.Fatalf("WSL row %d, saved row %d: the distributions are not after the saved connections", at, r.rowOf(r.selected)) + } + + h.clickFront(remoteTestWSL) + h.settle() + if r.wsl.selected != remoteTestWSL || r.selected != "" || r.list.Selected() != r.wslRow(remoteTestWSL) { + t.Fatal("choosing the distribution does not show its page") + } + if !h.showsWrapped(i18n.Shared(lang, "desktop.remote.wsl.about")) || !h.shows("wsl:"+remoteTestWSL) { + t.Fatal("the page does not say how the distribution opens") + } + r.wsl.user.SetText("dev") + h.redraw() + if !h.shows("wsl:dev@" + remoteTestWSL) { + t.Fatal("the page does not name the account typed") + } + + p := h.openBrowsedProject(t, h.connectAndBrowse(t)) + if got := k.wsl.requests; len(got) != 1 || got[0] != (core.WSLConnection{Distribution: remoteTestWSL, User: "dev"}) { + t.Fatalf("asked for %d WSL connections, want the distribution as the account typed", len(got)) + } + identity := "wsl:dev@" + remoteTestWSL + anchor, _ := h.app.remoteAnchor() + if want := remoteplaceholder.Root(anchor, identity, remoteTestHome+"/project"); p.root != want || p.remote.connectionID != identity { + t.Fatal("the workspace is not placed under the distribution's identity") + } + if got, want := h.app.projectDisplayName(p), "project [WSL: "+remoteTestWSL+"]"; got != want { + t.Fatalf("title %q, want %q", got, want) + } + if status := remoteStatusText(lang, p.remote); !strings.HasPrefix(status, "WSL: "+remoteTestWSL) || !h.shows(status) { + t.Fatalf("status %q does not name the distribution over WSL", status) + } + saved := savedRemoteConnections(t, h) + if len(saved) != 1 || len(saved[0].RecentFolders) != 0 || saved[0].LastConnectedAt != 0 { + t.Fatalf("%d saved connections: opening in WSL changed the saved list", len(saved)) + } + if countFailures(logger, "remote_remember_folder") != 0 { + t.Fatal("remembering the folder was tried for a distribution") + } + want := []string{"remote.connections.open", "remote.connection.new", "remote.connection.save", "remote.connections.open", "remote.wsl.select", "remote.connect", "remote.workspace.open"} + if got := remoteActions(logger); !slices.Equal(got, want) { + t.Fatalf("performed %q, want %q", got, want) + } + if event := loggedAny(t, logger, remoteTestWSL, "dev@", remoteTestHome); event != "" { + t.Fatal("logged the distribution, the account or a host path") + } + + // A window over the distribution shows it connected, whatever the account. + h.app.openRemote(surfaceMenu) + h.await("the WSL distributions", func() bool { return h.app.remote.wsl.loaded }) + if h.app.remoteWSLWindows(remoteTestWSL) != 1 || h.app.remoteWSLWindows(remoteTestWSLGone) != 0 { + t.Fatal("the windows open over the distribution are not counted") + } +} + +// A distribution that does not start fails at the connection with WSL's own text and no OpenSSH +// hint; a search lists the saved connections only, and folding the heading hides the +// distributions. +func TestRemoteWSLFailuresSearchAndFolding(t *testing.T) { + h, k, _ := remoteWSLHarness(t) + lang := h.app.language() + r := &h.app.remote + + h.clickFront(remoteTestWSLGone) + h.settle() + h.clickFront(i18n.Shared(lang, "desktop.remote.connect")) + h.await("the failed connection", func() bool { return r.steps != nil && r.steps.failed }) + h.settle() + outcome := r.steps.outcome + if !outcome.wsl || remoteFailureText(lang, outcome) != i18n.Shared(lang, "desktop.remote.wsl.unreachable") || remoteFailureHint(lang, outcome) != "" { + t.Fatal("the failure does not read as WSL's") + } + if !h.showsWrapped(i18n.Shared(lang, "desktop.remote.wsl.unreachable")) || h.showsWrapped(i18n.Shared(lang, "desktop.remote.probe.hint.unreachable")) { + t.Fatal("the page does not show WSL's failure alone") + } + if !h.shows("wsl:" + remoteTestWSLGone) { + t.Fatal("the steps do not name the distribution") + } + if !h.shows(i18n.Shared(lang, "desktop.remote.wsl.start")) || h.shows(i18n.Shared(lang, "desktop.remote.step.config")) || + h.shows(i18n.Shared(lang, "desktop.remote.step.authenticate")) || h.shows(i18n.Shared(lang, "desktop.remote.steps.editConnection")) { + t.Fatal("the steps of a distribution list OpenSSH's, or offer a connection's form") + } + + // Core refusing the account names the account, on the distribution's page. + h.app.stopRemoteConnect() + r.steps = nil + k.set(func(k *remoteHostKernel) { + k.wsl.refuse = &core.Error{Command: "remote.connect", Code: core.CodeInvalidRequest, Message: "invalid", Details: `{"field":"user","reason":"tooLong"}`} + }) + r.wsl.user.SetText(strings.Repeat("u", 40)) + h.redraw() + h.clickFront(i18n.Shared(lang, "desktop.remote.connect")) + h.await("the refused account", func() bool { return r.connect == nil && r.err != "" }) + h.settle() + if r.err != i18n.Shared(lang, "desktop.remote.wsl.userTooLong") || r.steps != nil || !h.shows(r.err) { + t.Fatal("the refused account is not explained on the page") + } + + // Choosing a saved connection leaves the distribution's page. + h.clickFront(remoteTestHost) + h.settle() + if r.wsl.selected != "" || r.entry(r.selected) == nil { + t.Fatal("choosing the saved connection does not show it") + } + + r.query.SetText(remoteTestHost) + h.app.searchRemote() + h.await("the search", func() bool { return r.found != nil }) + h.settle() + if r.wslRow(remoteTestWSL) >= 0 || h.shows(remoteTestWSL) { + t.Fatal("a search lists the WSL distributions") + } + h.app.clearRemoteSearch() + h.settle() + if r.wslRow(remoteTestWSL) < 0 { + t.Fatal("clearing the search does not list the distributions again") + } + h.app.toggleRemoteGroup(remoteWSLHeading) + h.redraw() + if r.wslRow(remoteTestWSL) >= 0 || !h.shows(i18n.Shared(lang, "desktop.remote.wsl.heading")) { + t.Fatal("folding the WSL heading does not keep the heading alone") + } +} + +// Without WSL, Core answers the list as unavailable, and the window shows no WSL heading. +func TestRemoteWSLAbsentShowsNothing(t *testing.T) { + h, k, _, _ := remoteWorkspaceHarness(t) + r := &h.app.remote + h.await("the WSL distributions", func() bool { return r.wsl.loaded }) + h.settle() + if k.count(func(k *remoteHostKernel) int { return k.wsl.lists }) != 1 { + t.Fatal("the distributions are not listed once when the window opens") + } + if slices.ContainsFunc(r.rows, func(row remoteListRow) bool { return row.wsl != "" || row.group == remoteWSLHeading }) { + t.Fatal("the list shows WSL rows without WSL") + } + if h.shows(i18n.Shared(h.app.language(), "desktop.remote.wsl.heading")) { + t.Fatal("the window shows the WSL heading without WSL") + } +} diff --git a/desktop/internal/workbench/window_title.go b/desktop/internal/workbench/window_title.go index ab0f5fe6f..bbd30b3b3 100644 --- a/desktop/internal/workbench/window_title.go +++ b/desktop/internal/workbench/window_title.go @@ -43,11 +43,11 @@ func (a *App) windowTitle() string { // projectDisplayName is the name the taskbar and Alt+Tab show for p: its folder's name, or // that name under the folder above it when another open tab shows a project of the same name, // so two checkouts of one repository do not look alike. A remote workspace's name says the -// connection it is on, as "folder [SSH: connection]". +// connection it is on, as "folder [SSH: connection]" or "folder [WSL: distribution]". func (a *App) projectDisplayName(p *project) string { name := p.name if r := p.remote; r != nil { - return i18n.SharedFormat(a.language(), "desktop.remote.workspace.title", map[string]string{"folder": name, "connection": r.name}) + return i18n.SharedFormat(a.language(), "desktop.remote.workspace.title", map[string]string{"folder": name, "kind": r.host.kind(a.language()), "connection": r.name}) } if !a.projectNameShared(p) { return name diff --git a/docs/assets/remote-connections/README.md b/docs/assets/remote-connections/README.md index da35e7517..4259b2e80 100644 --- a/docs/assets/remote-connections/README.md +++ b/docs/assets/remote-connections/README.md @@ -7,6 +7,7 @@ - 空页面上 Motty 和 `~/.ssh/config` 的可导入数量; - 导入页的 Motty 主机、逐项字段映射和 `~/.ssh/config` 的主机; - 选文件夹页的远程目录; +- WSL 发行版列表和连接失败时 wsl.exe 的输出; - OpenSSH 的主机密钥和密码询问。 截图里的主机、用户、指纹和路径都是虚构的。截图覆盖深色与浅色主题、中文与英文界面,用于确认: @@ -49,6 +50,10 @@ - 底部显示将导入的连接数和将新建的分组。 - **从 SSH 配置导入:** 表格列出 Host 别名、`ssh -G` 解析出的生效值和结果。被其他主机用作跳板的主机注明“作为 … 的 ProxyJump”;通配符 Host 跳过并说明原因。 +- **WSL 发行版:** 已保存的连接之后是“WSL”分组,列出本机的发行版(截图里的发行版由测试给出,不运行 wsl.exe): + - 选中后右侧显示发行版名、“WSL”标签和 `wsl:用户@发行版` 地址,说明经本机 wsl.exe 打开、不保存任何信息,下方可填写 Linux 用户; + - 连接失败时步骤从“启动发行版”开始,没有读取配置和身份验证;失败原因用 WSL 自己的说明,不显示 SSH 的排查提示,底部没有“编辑连接”。 + 截图不能代替 macOS/Windows 原生窗口验收。 | 场景 | 浅色英文 | 深色中文 | @@ -67,6 +72,8 @@ | 从 Motty 导入(展开字段映射) | [浅色英文](remote-connections-import-light-en-US.png) | [深色中文](remote-connections-import-dark-zh-CN.png) | | 从 SSH 配置导入 | [浅色英文](remote-connections-import-ssh-light-en-US.png) | [深色中文](remote-connections-import-ssh-dark-zh-CN.png) | | 选择远程文件夹 | [浅色英文](remote-connections-folder-light-en-US.png) | [深色中文](remote-connections-folder-dark-zh-CN.png) | +| WSL 发行版页(填写 Linux 用户) | [浅色英文](remote-connections-wsl-light-en-US.png) | [深色中文](remote-connections-wsl-dark-zh-CN.png) | +| 连接 WSL 发行版失败 | [浅色英文](remote-connections-wsl-failed-light-en-US.png) | [深色中文](remote-connections-wsl-failed-dark-zh-CN.png) | 复验方法:在仓库根目录把 `LITHE_VISUAL_OUTPUT_DIR` 设为绝对路径 `"$(pwd)/docs/assets/remote-connections"`,然后在 `desktop/` 下运行 `../scripts/desktop/desktop-go.sh test -tags vivahead,lithevisual ./internal/workbench -run '^TestVisualRemoteConnections$' -count=1 -timeout 300s`。 diff --git a/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png new file mode 100644 index 000000000..b8e4683e5 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-wsl-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png b/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png new file mode 100644 index 000000000..2e23b5e2d Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-wsl-failed-dark-zh-CN.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png b/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png new file mode 100644 index 000000000..938d9c686 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-wsl-failed-light-en-US.png differ diff --git a/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png b/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png new file mode 100644 index 000000000..e735c9824 Binary files /dev/null and b/docs/assets/remote-connections/remote-connections-wsl-light-en-US.png differ diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh index 4f6463d70..789e17d79 100755 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -322,7 +322,9 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # remoteStage events and classified authentication questions (#2231); #155 build preferences. # Lithe-core-rust main at ae593eb: #156 remote.parseForwardAddress reads a port, host:port or URL # typed into the Ports window (#2231). -PINNED_CORE_REVISION="ae593eb1cca7c5529823f8339608d7e0ba3dd6ec" +# Lithe-core-rust main at 5c163e9: #157 remote.connect opens a local WSL distribution through +# wsl.exe (the wsl field) and remote.listWslDistributions lists the installed ones (#2231). +PINNED_CORE_REVISION="5c163e9660d1447d17a8279aec151d23099e47e1" PROFILE="debug" CHECKOUT_ONLY="no" while [[ $# -gt 0 ]]; do diff --git a/shared/i18n/features/remote-connections.json b/shared/i18n/features/remote-connections.json index 5d5b643c6..73949b132 100644 --- a/shared/i18n/features/remote-connections.json +++ b/shared/i18n/features/remote-connections.json @@ -885,53 +885,58 @@ }, { "id": "desktop.remote.status.connected", - "description": "Status bar item of a remote workspace: text while connected, before the first round trip is known", + "description": "Status bar item of a remote workspace: text while connected, before the first round trip is known; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { - "name": "string" + "name": "string", + "kind": "string" } }, { "id": "desktop.remote.status.latency", - "description": "Status bar item of a remote workspace: text while connected with the round trip of the last heartbeat in milliseconds", + "description": "Status bar item of a remote workspace: text while connected with the round trip of the last heartbeat in milliseconds; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { "name": "string", - "ms": "integer" + "ms": "integer", + "kind": "string" } }, { "id": "desktop.remote.status.unresponsive", - "description": "Status bar item of a remote workspace: text when the last heartbeat went unanswered", + "description": "Status bar item of a remote workspace: text when the last heartbeat went unanswered; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { - "name": "string" + "name": "string", + "kind": "string" } }, { "id": "desktop.remote.status.reconnecting", - "description": "Status bar item of a remote workspace: text while connecting again after the connection was lost", + "description": "Status bar item of a remote workspace: text while connecting again after the connection was lost; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { - "name": "string" + "name": "string", + "kind": "string" } }, { "id": "desktop.remote.status.disconnected", - "description": "Status bar item of a remote workspace: text when the connection was lost and connecting again failed", + "description": "Status bar item of a remote workspace: text when the connection was lost and connecting again failed; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { - "name": "string" + "name": "string", + "kind": "string" } }, { @@ -950,13 +955,14 @@ }, { "id": "desktop.remote.workspace.title", - "description": "Window title and task switcher name of a remote workspace", + "description": "Window title and task switcher name of a remote workspace; {kind} is how it is reached, SSH or WSL", "platforms": [ "desktop" ], "parameters": { "folder": "string", - "connection": "string" + "connection": "string", + "kind": "string" } }, { @@ -2322,6 +2328,97 @@ "timeout": "string", "keepAlive": "string" } + }, + { + "id": "desktop.remote.kind.ssh", + "description": "How a remote workspace over SSH is reached, in its window title and status bar item", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.heading", + "description": "Remote Development window: heading of the list's WSL distributions of this computer and the tag on a distribution's page; also how a remote workspace in one is reached, in its window title and status bar item", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.kind", + "description": "Remote Development window: line under a WSL distribution's name in the list", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.about", + "description": "Remote Development window: paragraph on a WSL distribution's page", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.user", + "description": "Remote Development window: title of a WSL distribution's account field, and the field's accessible name", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.userHelp", + "description": "Remote Development window: help of a WSL distribution's account field", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.userPlaceholder", + "description": "Remote Development window: placeholder of a WSL distribution's empty account field", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.userInvalid", + "description": "Remote Development window: error when Core refused the account typed for a WSL distribution", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.userTooLong", + "description": "Remote Development window: error when the account typed for a WSL distribution is too long", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.distributionInvalid", + "description": "Remote Development window: error when Core refused a WSL distribution's name", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.unreachable", + "description": "Remote Development window: why a connection to a WSL distribution failed, when it is not installed or did not start", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.missing", + "description": "Remote Development window: why a connection to a WSL distribution failed, when this computer has no wsl.exe", + "platforms": [ + "desktop" + ] + }, + { + "id": "desktop.remote.wsl.start", + "description": "Remote Development window: the step of a connection to a WSL distribution that starts it, in place of connecting to a host", + "platforms": [ + "desktop" + ] } ], "locales": { @@ -2465,14 +2562,14 @@ "desktop.remote.browse.enterHint": "Double-click to open", "desktop.remote.browse.git": "Git", "desktop.remote.status.label": "Remote Connection", - "desktop.remote.status.connected": "SSH: {name}", - "desktop.remote.status.latency": "SSH: {name} · {ms} ms", - "desktop.remote.status.unresponsive": "SSH: {name} · Not responding", - "desktop.remote.status.reconnecting": "SSH: {name} · Reconnecting…", - "desktop.remote.status.disconnected": "SSH: {name} · Disconnected", + "desktop.remote.status.connected": "{kind}: {name}", + "desktop.remote.status.latency": "{kind}: {name} · {ms} ms", + "desktop.remote.status.unresponsive": "{kind}: {name} · Not responding", + "desktop.remote.status.reconnecting": "{kind}: {name} · Reconnecting…", + "desktop.remote.status.disconnected": "{kind}: {name} · Disconnected", "desktop.remote.status.reconnect": "Reconnect", "desktop.remote.status.disconnect": "Disconnect and Close", - "desktop.remote.workspace.title": "{folder} [SSH: {connection}]", + "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.titleWith": "Remote Development › {crumb}", "desktop.remote.newConnection": "New Connection", "desktop.remote.search": "Search connections", @@ -2628,7 +2725,20 @@ "desktop.remote.probe.hint.authentication": "Check the user name; the password method asks when connecting. If the server only allows keys, set Authentication to “{method}”.", "desktop.remote.probe.hint.hostKey": "Connecting shows the host’s fingerprint for you to confirm. If it changed, check with the host’s administrator before updating known_hosts.", "desktop.remote.probe.hint.unreachable": "Check the host and the port. If the host can only be reached through another one, add that one as a jump host.", - "desktop.remote.advancedSummary": "Connect timeout {timeout} · Keep-alive {keepAlive}" + "desktop.remote.advancedSummary": "Connect timeout {timeout} · Keep-alive {keepAlive}", + "desktop.remote.kind.ssh": "SSH", + "desktop.remote.wsl.heading": "WSL", + "desktop.remote.wsl.kind": "WSL distribution on this computer", + "desktop.remote.wsl.about": "Opens through wsl.exe on this computer, as the Linux user below. Nothing about the distribution is saved: the folders opened in it are not remembered, and the list is read again each time this window opens.", + "desktop.remote.wsl.user": "Linux user", + "desktop.remote.wsl.userHelp": "The account the workspace runs as. Leave it empty to use the distribution's default user.", + "desktop.remote.wsl.userPlaceholder": "Default user", + "desktop.remote.wsl.userInvalid": "Linux does not accept this user name.", + "desktop.remote.wsl.userTooLong": "A Linux user name has at most 32 characters.", + "desktop.remote.wsl.distributionInvalid": "wsl.exe does not accept this distribution name.", + "desktop.remote.wsl.unreachable": "This WSL distribution is not installed, or it did not start.", + "desktop.remote.wsl.missing": "wsl.exe was not found on this computer. Install the Windows Subsystem for Linux to open a distribution.", + "desktop.remote.wsl.start": "Start the distribution" }, "zh-CN": { "desktop.remote.title": "远程开发", @@ -2770,14 +2880,14 @@ "desktop.remote.browse.enterHint": "双击进入", "desktop.remote.browse.git": "Git", "desktop.remote.status.label": "远程连接", - "desktop.remote.status.connected": "SSH: {name}", - "desktop.remote.status.latency": "SSH: {name} · {ms} 毫秒", - "desktop.remote.status.unresponsive": "SSH: {name} · 无响应", - "desktop.remote.status.reconnecting": "SSH: {name} · 正在重新连接…", - "desktop.remote.status.disconnected": "SSH: {name} · 已断开", + "desktop.remote.status.connected": "{kind}: {name}", + "desktop.remote.status.latency": "{kind}: {name} · {ms} 毫秒", + "desktop.remote.status.unresponsive": "{kind}: {name} · 无响应", + "desktop.remote.status.reconnecting": "{kind}: {name} · 正在重新连接…", + "desktop.remote.status.disconnected": "{kind}: {name} · 已断开", "desktop.remote.status.reconnect": "重新连接", "desktop.remote.status.disconnect": "断开并关闭", - "desktop.remote.workspace.title": "{folder} [SSH: {connection}]", + "desktop.remote.workspace.title": "{folder} [{kind}: {connection}]", "desktop.remote.titleWith": "远程开发 › {crumb}", "desktop.remote.newConnection": "新建连接", "desktop.remote.search": "搜索连接", @@ -2933,7 +3043,20 @@ "desktop.remote.probe.hint.authentication": "检查用户名是否正确;密码方式会在连接时询问。若服务器只允许密钥,把身份验证改成“{method}”。", "desktop.remote.probe.hint.hostKey": "连接时会显示主机指纹请你确认;如果指纹变了,先向主机管理员核实,再更新 known_hosts。", "desktop.remote.probe.hint.unreachable": "检查主机和端口;如果只能经另一台主机访问,把它加为跳板机。", - "desktop.remote.advancedSummary": "连接超时 {timeout} · 保活间隔 {keepAlive}" + "desktop.remote.advancedSummary": "连接超时 {timeout} · 保活间隔 {keepAlive}", + "desktop.remote.kind.ssh": "SSH", + "desktop.remote.wsl.heading": "WSL", + "desktop.remote.wsl.kind": "本机 WSL 发行版", + "desktop.remote.wsl.about": "通过本机的 wsl.exe 打开,以下方的 Linux 用户运行。不保存这个发行版的任何信息:不记住在其中打开过的文件夹,每次打开本窗口时重新读取列表。", + "desktop.remote.wsl.user": "Linux 用户", + "desktop.remote.wsl.userHelp": "工作区以哪个账户运行。留空则使用发行版的默认用户。", + "desktop.remote.wsl.userPlaceholder": "默认用户", + "desktop.remote.wsl.userInvalid": "Linux 不接受这个用户名。", + "desktop.remote.wsl.userTooLong": "Linux 用户名最多 32 个字符。", + "desktop.remote.wsl.distributionInvalid": "wsl.exe 不接受这个发行版名称。", + "desktop.remote.wsl.unreachable": "这个 WSL 发行版没有安装,或者没能启动。", + "desktop.remote.wsl.missing": "本机找不到 wsl.exe。安装适用于 Linux 的 Windows 子系统(WSL)后才能打开发行版。", + "desktop.remote.wsl.start": "启动发行版" } } } diff --git a/shared/platform-feature-matrix/features/remote-workspace.json b/shared/platform-feature-matrix/features/remote-workspace.json index 2ef2dda03..97db91539 100644 --- a/shared/platform-feature-matrix/features/remote-workspace.json +++ b/shared/platform-feature-matrix/features/remote-workspace.json @@ -2,7 +2,7 @@ "id": "remote-workspace", "area": "工作区", "group": "远程开发", - "capability": "远程连接、远程路径工作区、主机文件编辑与监听、主机终端、主机搜索与替换、远程信任与主机 Git、端口转发", + "capability": "远程连接(SSH 主机与本机 WSL 发行版)、远程路径工作区、主机文件编辑与监听、主机终端、主机搜索与替换、远程信任与主机 Git、端口转发", "macos": { "implementationStatus": "partial", "verificationStatus": "pending", @@ -45,7 +45,9 @@ "desktop/internal/workbench/remote_ports.go", "desktop/internal/workbench/remote_ports_view.go", "desktop/internal/workbench/remote_ports_test.go", - "desktop/internal/workbench/remote_ports_visual_test.go" + "desktop/internal/workbench/remote_ports_visual_test.go", + "desktop/internal/workbench/remote_wsl.go", + "desktop/internal/workbench/remote_wsl_test.go" ] }, "windows": { @@ -77,11 +79,12 @@ "desktop/internal/workbench/gitreview.go", "desktop/internal/core/remote_forward.go", "desktop/internal/workbench/remote_ports.go", - "desktop/internal/workbench/remote_ports_view.go" + "desktop/internal/workbench/remote_ports_view.go", + "desktop/internal/workbench/remote_wsl.go" ] }, "owner": "Remote", - "verification": "在“远程开发”窗口选中已保存的 Linux SSH 连接点“连接”:SSH 询问出现在窗口中,连接后窗口改为主机的文件夹选择,从主目录开始列出子文件夹(跳过名称不是 UTF-8 的条目并说明数量),可输入 ~ 或 / 开头的路径跳转,不存在的路径说明原因且不能打开;“返回”断开这次会话回到连接表单。选中文件夹点“打开”:新标签页打开远程工作区,窗口标题为“文件夹 [SSH: 连接名]”,项目树经 Core 列出主机目录(本机占位目录始终为空),右键只有复制主机路径和刷新;以安全模式打开的文件夹,编辑器上方说明可以浏览、编辑、保存和搜索主机文件,信任文件夹后才能用 Git;受信任的文件夹说明文件、终端和 Git 都在主机上,运行、调试和语言服务器暂不可用;空白编辑区提示 Search Everywhere 和 Find in Files。在项目树双击文件:编辑器经会话读取主机文件(不超过 16 MiB),保存时带上打开时的大小和修改时间写回主机,新建的文件只在主机上不存在时创建;主机上的文件期间被别人改过时保存被拒绝并显示外部修改冲突,“加载磁盘版本”载入主机内容,本机占位目录始终为空。超过 8 MiB 的保存说明主机单次保存上限,编辑内容保留;主机上缺失、无权限、不是普通文件、超时和连接断开分别说明原因,连接断开后自动重连并把打开的文档和主机重新比对。图片、PDF 等查看器、文件夹外的文件、本地历史和插件终端都被拒绝并提示,不回退到本机。打开“终端”工具窗口:经会话的 remote.runTerminal 在主机文件夹运行主机账户的登录 shell(不带参数,不读本机 Shell 设置,没有本机 Shell 菜单),标签名为连接名,之后的标签为“连接名 (2)”等;输入按顺序、每块不超过 32 KiB 写入,主机说忙时稍后重试,窗口尺寸随输入发送;输出超过 8 MiB 未显示时丢弃最旧的部分并记一次失败。程序退出显示退出码,被信号结束显示 128+信号,关闭标签不算失败。连接断开时终端显示会话已结束,工作区按退避重连;未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。终端起不来时显示 Core 给出的原因(可能含主机路径),日志只记命令名和错误码。拖到终端的文件粘贴为主机路径并按 POSIX shell 加引号,本机工作区外的文件不粘贴并提示原因;粘贴图片不可用(图片会存到本机)。每个会话连接后,经 remote.runWatch 在主机上递归监听整个文件夹,跳过已启用插件隐藏的文件夹名(按原样比较大小写),插件改变隐藏名称时重新开始监听;在主机上新建、修改、删除文件后,项目树重新列出受影响的目录(Core 的 workspace.filterChanges 按可见性规则过滤,不需要会话),打开的文档与主机比对:没有编辑的重新载入,有编辑的显示外部修改冲突;文件夹外和被隐藏文件夹里的变化不触发列表。监听开始时、主机丢失变化(overflow)时、一次超过 4096 个变化时,重新列出树中展开的目录并比对所有文档,日志每次监听各记一次;主机监听数用尽时其余部分继续监听,提示一次“项目文件可能无法自动更新”。监听中文件夹被删除或移走时立即重新监听;主机找不到文件夹时项目树显示根目录不可用,监听等树重新列出文件夹后再开始,主机与树结论不一致时也只等待、不反复重试。其他监听失败只记命令名和错误码、提示一次,等下一个会话再开始;监听发现连接断开时与心跳一样结束会话并重连。Find in Files 的搜索、计数和替换预览带远程绑定发送,Core 从主机文件夹建立索引并读取主机上的当前内容,结果路径相对主机文件夹;点结果在远程编辑器打开主机文件并定位到匹配处,本机占位目录始终为空。主机监听报告的变化路径在下一次查询前增量更新索引,不重建;监听开始和主机丢失变化时重建一次。包含生成文件的查询每次都重建索引(主机监听跳过插件隐藏的文件夹);主机监听数用尽后、会话断开到下一个会话的监听开始之间,每次查询都重建,只由监听提示一次“项目文件可能无法自动更新”,搜索不再另外提示。查询显示期间主机上的变化让结果重新查询。Search Everywhere 所有页签都可用,文件名和文本来自主机,打开弹窗时重新读取生成文件的名称;远程工作区不启动语言服务器,符号只有 Core 在主机文件中找到的。Replace All 在编辑器中替换打开的文档;未打开的文件经会话读取主机内容,由 Core 替换后,只在主机文件仍是读取时的内容时写回,期间被改过的报告冲突,已被删除的说明主机上找不到文件,其余文件照常替换,都不写本机占位目录。在文件夹选择中打开从未决定过的文件夹:先询问是否信任(显示连接名和主机文件夹,Core 给出上级文件夹时可勾选信任其下的所有文件夹),“信任并打开”把决定按连接名记入 Core 的远程信任记录后以受信任方式打开,“以安全模式打开”只读打开,“返回”回到文件夹选择;之前决定过的文件夹直接按记录打开。安全模式下 Git、提交和日志窗口与本机项目一样说明需要信任,编辑器上方的提示里可以信任文件夹,信任后不重开窗口就在主机上启动 Git。受信任的工作区经会话在主机上运行 Git:状态、暂存、提交、差异(含编辑器行号旁的变更标记)、日志与分支、逐行追溯(读取主机上的文件内容)、搁置与储藏都读写主机仓库,本机占位目录始终没有 .git;“排除到本地”写入主机仓库的 info/exclude(缺少 info 文件夹时在主机上创建,读写期间文件被别人改过时这次排除失败、不覆盖)。同一会话经 remote.runWatch 递归监听主机仓库的 git 目录(公共目录在别处时一并监听),主机上 git checkout、commit 等改动元数据后按路径分类并重新读取状态;监听开始、丢失变化或主机监听数用尽时重新读取一次完整状态,新会话重新开始监听。主机文件夹位于上级目录开始的仓库内时,Git 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,复制路径复制主机路径;打开、在新窗口打开、在文件浏览器中显示和新建工作树被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 1、2、4、8、16 秒退避重连,共六次失败后显示“已断开”和原因,菜单里可“重新连接”;连接被关闭时立即重连。菜单里“断开并关闭”关闭工作区并结束会话,退出 Lithe 时关闭所有远程会话。最近项目不记录远程工作区。日志只有 remote.connect、remote.workspace.open/reconnect/disconnect 等动作和失败的操作名,不含主机、用户名、主机路径或主目录。运行 remote_workspace_test.go 的 5 个测试、remote_git_test.go 的 6 个测试、remoteplaceholder 的 TestHostAndLocalPathsMapBothWays、remote_documents_test.go 的 2 个测试、remote_terminal_test.go 的 9 个测试、remote_watch_test.go 的 5 个测试、remote_search_test.go 的 4 个测试、internal/core 的 TestRemoteTerminal*、TestRemoteWatch* 与 TestRemoteWorkspaceFiltersChangesWithoutTheHost、termview 的 TestOpenStartsTheProgramElsewhere,以及 TestVisualRemoteWorkspace 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段);主机侧监听的转发规则(主机端口转到另一台服务器)和反向转发只完成设计,尚未实现。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库、打开或新建远程工作树尚未支持。", + "verification": "在“远程开发”窗口选中已保存的 Linux SSH 连接点“连接”:SSH 询问出现在窗口中,连接后窗口改为主机的文件夹选择,从主目录开始列出子文件夹(跳过名称不是 UTF-8 的条目并说明数量),可输入 ~ 或 / 开头的路径跳转,不存在的路径说明原因且不能打开;“返回”断开这次会话回到连接表单。选中文件夹点“打开”:新标签页打开远程工作区,窗口标题为“文件夹 [SSH: 连接名]”,项目树经 Core 列出主机目录(本机占位目录始终为空),右键只有复制主机路径和刷新;以安全模式打开的文件夹,编辑器上方说明可以浏览、编辑、保存和搜索主机文件,信任文件夹后才能用 Git;受信任的文件夹说明文件、终端和 Git 都在主机上,运行、调试和语言服务器暂不可用;空白编辑区提示 Search Everywhere 和 Find in Files。在项目树双击文件:编辑器经会话读取主机文件(不超过 16 MiB),保存时带上打开时的大小和修改时间写回主机,新建的文件只在主机上不存在时创建;主机上的文件期间被别人改过时保存被拒绝并显示外部修改冲突,“加载磁盘版本”载入主机内容,本机占位目录始终为空。超过 8 MiB 的保存说明主机单次保存上限,编辑内容保留;主机上缺失、无权限、不是普通文件、超时和连接断开分别说明原因,连接断开后自动重连并把打开的文档和主机重新比对。图片、PDF 等查看器、文件夹外的文件、本地历史和插件终端都被拒绝并提示,不回退到本机。打开“终端”工具窗口:经会话的 remote.runTerminal 在主机文件夹运行主机账户的登录 shell(不带参数,不读本机 Shell 设置,没有本机 Shell 菜单),标签名为连接名,之后的标签为“连接名 (2)”等;输入按顺序、每块不超过 32 KiB 写入,主机说忙时稍后重试,窗口尺寸随输入发送;输出超过 8 MiB 未显示时丢弃最旧的部分并记一次失败。程序退出显示退出码,被信号结束显示 128+信号,关闭标签不算失败。连接断开时终端显示会话已结束,工作区按退避重连;未连接时按回车说明工作区未连接,重连后按回车在新会话上运行。终端起不来时显示 Core 给出的原因(可能含主机路径),日志只记命令名和错误码。拖到终端的文件粘贴为主机路径并按 POSIX shell 加引号,本机工作区外的文件不粘贴并提示原因;粘贴图片不可用(图片会存到本机)。每个会话连接后,经 remote.runWatch 在主机上递归监听整个文件夹,跳过已启用插件隐藏的文件夹名(按原样比较大小写),插件改变隐藏名称时重新开始监听;在主机上新建、修改、删除文件后,项目树重新列出受影响的目录(Core 的 workspace.filterChanges 按可见性规则过滤,不需要会话),打开的文档与主机比对:没有编辑的重新载入,有编辑的显示外部修改冲突;文件夹外和被隐藏文件夹里的变化不触发列表。监听开始时、主机丢失变化(overflow)时、一次超过 4096 个变化时,重新列出树中展开的目录并比对所有文档,日志每次监听各记一次;主机监听数用尽时其余部分继续监听,提示一次“项目文件可能无法自动更新”。监听中文件夹被删除或移走时立即重新监听;主机找不到文件夹时项目树显示根目录不可用,监听等树重新列出文件夹后再开始,主机与树结论不一致时也只等待、不反复重试。其他监听失败只记命令名和错误码、提示一次,等下一个会话再开始;监听发现连接断开时与心跳一样结束会话并重连。Find in Files 的搜索、计数和替换预览带远程绑定发送,Core 从主机文件夹建立索引并读取主机上的当前内容,结果路径相对主机文件夹;点结果在远程编辑器打开主机文件并定位到匹配处,本机占位目录始终为空。主机监听报告的变化路径在下一次查询前增量更新索引,不重建;监听开始和主机丢失变化时重建一次。包含生成文件的查询每次都重建索引(主机监听跳过插件隐藏的文件夹);主机监听数用尽后、会话断开到下一个会话的监听开始之间,每次查询都重建,只由监听提示一次“项目文件可能无法自动更新”,搜索不再另外提示。查询显示期间主机上的变化让结果重新查询。Search Everywhere 所有页签都可用,文件名和文本来自主机,打开弹窗时重新读取生成文件的名称;远程工作区不启动语言服务器,符号只有 Core 在主机文件中找到的。Replace All 在编辑器中替换打开的文档;未打开的文件经会话读取主机内容,由 Core 替换后,只在主机文件仍是读取时的内容时写回,期间被改过的报告冲突,已被删除的说明主机上找不到文件,其余文件照常替换,都不写本机占位目录。在文件夹选择中打开从未决定过的文件夹:先询问是否信任(显示连接名和主机文件夹,Core 给出上级文件夹时可勾选信任其下的所有文件夹),“信任并打开”把决定按连接名记入 Core 的远程信任记录后以受信任方式打开,“以安全模式打开”只读打开,“返回”回到文件夹选择;之前决定过的文件夹直接按记录打开。安全模式下 Git、提交和日志窗口与本机项目一样说明需要信任,编辑器上方的提示里可以信任文件夹,信任后不重开窗口就在主机上启动 Git。受信任的工作区经会话在主机上运行 Git:状态、暂存、提交、差异(含编辑器行号旁的变更标记)、日志与分支、逐行追溯(读取主机上的文件内容)、搁置与储藏都读写主机仓库,本机占位目录始终没有 .git;“排除到本地”写入主机仓库的 info/exclude(缺少 info 文件夹时在主机上创建,读写期间文件被别人改过时这次排除失败、不覆盖)。同一会话经 remote.runWatch 递归监听主机仓库的 git 目录(公共目录在别处时一并监听),主机上 git checkout、commit 等改动元数据后按路径分类并重新读取状态;监听开始、丢失变化或主机监听数用尽时重新读取一次完整状态,新会话重新开始监听。主机文件夹位于上级目录开始的仓库内时,Git 和提交窗口说明要打开仓库顶层文件夹,不显示变更也不记为失败。工作树列表、锁定、解锁、删除在主机上执行,复制路径复制主机路径;打开、在新窗口打开、在文件浏览器中显示和新建工作树被拒绝并提示。受信任的远程工作区里运行、调试、当前文件运行、测试、构建任务和插件语言服务器都不在本机启动,都记为拒绝并提示,运行、测试和构建工具窗口说明暂不可用。状态栏前端显示连接名和心跳往返时间;连续两次心跳无响应显示“无响应”,第三次结束会话并按 1、2、4、8、16 秒退避重连,共六次失败后显示“已断开”和原因,菜单里可“重新连接”;连接被关闭时立即重连。菜单里“断开并关闭”关闭工作区并结束会话,退出 Lithe 时关闭所有远程会话。最近项目不记录远程工作区。日志只有 remote.connect、remote.workspace.open/reconnect/disconnect 等动作和失败的操作名,不含主机、用户名、主机路径或主目录。运行 remote_workspace_test.go 的 5 个测试、remote_git_test.go 的 6 个测试、remoteplaceholder 的 TestHostAndLocalPathsMapBothWays、remote_documents_test.go 的 2 个测试、remote_terminal_test.go 的 9 个测试、remote_watch_test.go 的 5 个测试、remote_search_test.go 的 4 个测试、internal/core 的 TestRemoteTerminal*、TestRemoteWatch* 与 TestRemoteWorkspaceFiltersChangesWithoutTheHost、termview 的 TestOpenStartsTheProgramElsewhere,以及 TestVisualRemoteWorkspace 无头截图;在 Windows 运行 TestCoreRefusesUnadaptedCommandsAndAClosedSessionDetachesTheBinding,验证 Linux 主机路径能通过绑定校验。真实 SSH 主机上的整机验收(包括终端里 vim、top 等全屏程序与窗口缩放,主机上 git checkout 等大批量修改后的监听,以及大仓库上的搜索)仍待完成。远程工作区左侧多出“端口”工具窗口(本机工作区没有,关闭工作区后消失):窗口打开时每 3 秒经 ports.listening 读取主机上正在监听的端口和会话的转发,窗口关闭或未显示时停止读取;同一端口在 0.0.0.0 与 :: 上监听只显示一行;远端端口带上主机监听的 IP 地址,多个地址时显示第一个和其余数量,悬停提示列出全部,地址或网址过长被截断时悬停提示给出全文;列出远端端口、本机地址、进程(名称与 PID,读不到时为“未知”)、来源(监听发现、手动添加)和状态。默认不自动转发任何端口,打开窗口和发现新端口都不转发;行尾“转发”把端口转发到主机上对应族的回环地址,本机在 127.0.0.1 的同号端口监听,该端口被本机其他程序占用时改用空闲端口,本机地址用警告色显示并在提示里说明原端口。右键“转发到指定本机端口…”和已转发行的“更改本机端口…”打开对话框输入 1–65535 的本机端口,非法输入就地说明且不转发;改到另一个端口时先停止原转发再在新端口转发,选择在工作区打开期间保留,停止后再转发仍用该端口。顶部输入端口、主机:端口或网址(http、https、ws、wss,省略端口时按协议默认端口)可手动添加并转发,由 Core 的 remote.parseForwardAddress 解析;格式不对就地说明,网址里带用户名或密码时拒绝并说明,输入框保留原文、日志不记输入内容;同一目标再次添加不重复。网址行按输入的样子显示,转发到主机上提供该端口的回环地址;在浏览器打开和复制本机地址把主机部分换成本机地址并保留路径和查询,ws/wss 网址不提供在浏览器打开;浏览器打不开时提示网址,日志只记失败、不记网址。主机回环地址以外的目标先询问(S28),确认后才带 AllowNonLoopback 转发,取消记为拒绝。已转发行可在浏览器打开、复制本机地址、停止;手动添加且已停止、主机上也没有在监听的行可移除;窗口标题栏可全部停止,标题栏的 ⓘ 说明转发对本机其他程序可见(S30);会话转发数达到 Core 上限时说明上限;状态栏显示已转发数量,点击打开端口窗口;会话结束时转发随之结束,重连后不自动恢复。日志只记 remote.ports.forward/localPort/move/stop/status 等动作和失败操作名,不含主机、地址或进程名。运行 remote_ports_test.go 的 12 个测试、internal/core 的 TestRemoteSessionCommandsOfAnUnknownSession 与 TestRemoteParseForwardAddressReadsPortsAndURLs,以及 TestVisualRemotePorts 无头截图。手动添加的端口和本机端口选择只在工作区打开期间保留,关闭后不保存(需 Core 存储,后续阶段);主机侧监听的转发规则(主机端口转到另一台服务器)和反向转发只完成设计,尚未实现。远程 Git 的 AskPass 转交(推送、拉取时的凭据询问)、从上级目录开始的仓库、打开或新建远程工作树尚未支持。Windows 上“远程开发”窗口在已保存的连接之后以“WSL”标题列出本机安装的 WSL 发行版(Core 的 remote.listWslDistributions,每次打开窗口读取一次;搜索时不列出,标题可折叠;macOS 和没有 WSL 的 Windows 不显示这一组)。选中发行版后右侧说明经本机 wsl.exe 打开、不保存任何信息,可填写 Linux 用户(留空为发行版默认用户),地址显示为 wsl:[用户@]发行版。“连接”经 remote.connect 的 wsl 参数启动,不经 OpenSSH、没有询问,步骤从“启动发行版”开始,不显示读取配置和身份验证;发行版没有安装或没能启动、本机找不到 wsl.exe 时分别说明,不显示 SSH 的排查提示,也没有“编辑连接”;Core 拒绝的用户名或发行版名就地说明。连接后与 SSH 相同:选择文件夹、信任询问、工作区、心跳与重连;窗口标题为“文件夹 [WSL: 发行版]”,状态栏为“WSL: 发行版”(SSH 工作区的“SSH”也由同一参数给出),列表和概览显示已打开该发行版的窗口数。发行版不写入已保存的连接,打开过的文件夹不记入最近文件夹。日志只有 remote.wsl.select、remote.connect 等动作,不含发行版名、用户名或主机路径。运行 remote_wsl_test.go 的 3 个测试、internal/core 的 TestRemoteConnectSendsWSLAloneAndCoreRefusesItByField 与 TestRemoteListWSLDistributionsIsUnavailableOutsideWindows,以及 TestVisualRemoteConnections 的 WSL 截图;真实 Windows 上的 WSL 验收(wsl.exe 的错误输出、--exec 的二进制透传、结束 wsl.exe 后 Linux 进程是否退出、未知用户)仍待完成。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { @@ -118,5 +121,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva:连接和会话由 Core 的 remote.connect/remote.disconnect/remote.closeAll 管理,远端服务按嵌入清单上传;文件夹选择用 remote.readDir。打开的工作区以用户缓存目录下的空占位目录作为本机根,每个请求带上远程绑定(会话、占位根、主机根),Core 只对有远程适配的命令放行,其余以 not_supported 拒绝,所以没有远程实现的功能在桌面端直接拒绝而不读本机占位目录。编辑器的读、写和比对改走 remote.stat、remote.readFile、remote.writeFile(带预期版本,主机按大小和修改时间拒绝过期写入);解码、恢复、语言识别等纯计算命令不带远程绑定发送。日志只记命令名和错误码,不记 Core 返回的消息(可能含主机路径)。macOS 由单元测试与无头截图覆盖;Core 按 POSIX 规则校验 Linux 主机路径,按客户端规则处理本机占位根(#2264)。终端经 remote.runTerminal 运行,输入与尺寸经 remote.hostRequest 的 terminal.write/terminal.resize 发送;关闭标签取消这次请求,Core 随即向主机发 terminal.close;一个连接断开的终端让工作区按同一会话丢失处理(与心跳一致),其他失败只结束该终端。文件夹监听经 remote.runWatch 在请求的 goroutine 上运行整个会话期间,不计入窗口的后台任务;事件在锁内合并后只投递一次到窗口线程,停止监听时作废已排队的变化。Find in Files、Search Everywhere 和 Replace All 的 workspace.search、searchIndex.update/invalidate、searchEverywhere、replacePreview 带远程绑定发送,searchPresentation、replaceText 等纯计算命令不带绑定;Core 以“会话身份 + 主机路径”为键缓存索引,主机监听的变化经 workspace.filterChanges 过滤后更新它。会话结束后 Core 不释放该会话的索引,每次重连或重新打开多留一份(#2277)。 远程信任:Core 的 remote.workspaceTrust 按“会话身份 + 主机文件夹”读出记录,remote.editWorkspaceTrust 写入决定(含连接名),桌面端只把 Core 给出的文档存到偏好目录;projectCodeAllowed 且状态为 trusted 才算受信任。受信任后 git.* 请求带远程绑定发送,Core 在主机上运行 Git,返回的路径是占位路径(remoteplaceholder.LocalPath 把主机路径换成占位路径,文件夹外的主机路径映射到占位目录旁的 .lithe-remote-host 下,不会落到本机真实路径)。git 目录的监听与文件夹监听同样跑在请求自己的 goroutine 上,会话丢失或失去信任时取消。 端口:remote.startForward/stopForward/forwards 与 ports.listening 都带会话发送;Core 只在本机 127.0.0.1 监听,请求的本机端口被占用时选空闲端口并返回 localPortChanged 与 requestedLocalPort;同一目标再次转发返回已有转发(created=false),所以更改本机端口是先停止再转发。顶部输入由 Core 的 remote.parseForwardAddress 解析为目标端口、主机、协议和路径,不连接主机;桌面端把网址的主机换成主机上提供该端口的回环地址再转发。非回环目标需 allowNonLoopback(S28),超过上限返回 forward_limit_reached 并带 maximum。读取在窗口的后台任务里进行,只在窗口打开且被绘制过时排下一次,不做空闲轮询。" + "notes": "Viva:连接和会话由 Core 的 remote.connect/remote.disconnect/remote.closeAll 管理,远端服务按嵌入清单上传;文件夹选择用 remote.readDir。打开的工作区以用户缓存目录下的空占位目录作为本机根,每个请求带上远程绑定(会话、占位根、主机根),Core 只对有远程适配的命令放行,其余以 not_supported 拒绝,所以没有远程实现的功能在桌面端直接拒绝而不读本机占位目录。编辑器的读、写和比对改走 remote.stat、remote.readFile、remote.writeFile(带预期版本,主机按大小和修改时间拒绝过期写入);解码、恢复、语言识别等纯计算命令不带远程绑定发送。日志只记命令名和错误码,不记 Core 返回的消息(可能含主机路径)。macOS 由单元测试与无头截图覆盖;Core 按 POSIX 规则校验 Linux 主机路径,按客户端规则处理本机占位根(#2264)。终端经 remote.runTerminal 运行,输入与尺寸经 remote.hostRequest 的 terminal.write/terminal.resize 发送;关闭标签取消这次请求,Core 随即向主机发 terminal.close;一个连接断开的终端让工作区按同一会话丢失处理(与心跳一致),其他失败只结束该终端。文件夹监听经 remote.runWatch 在请求的 goroutine 上运行整个会话期间,不计入窗口的后台任务;事件在锁内合并后只投递一次到窗口线程,停止监听时作废已排队的变化。Find in Files、Search Everywhere 和 Replace All 的 workspace.search、searchIndex.update/invalidate、searchEverywhere、replacePreview 带远程绑定发送,searchPresentation、replaceText 等纯计算命令不带绑定;Core 以“会话身份 + 主机路径”为键缓存索引,主机监听的变化经 workspace.filterChanges 过滤后更新它。会话结束后 Core 不释放该会话的索引,每次重连或重新打开多留一份(#2277)。 远程信任:Core 的 remote.workspaceTrust 按“会话身份 + 主机文件夹”读出记录,remote.editWorkspaceTrust 写入决定(含连接名),桌面端只把 Core 给出的文档存到偏好目录;projectCodeAllowed 且状态为 trusted 才算受信任。受信任后 git.* 请求带远程绑定发送,Core 在主机上运行 Git,返回的路径是占位路径(remoteplaceholder.LocalPath 把主机路径换成占位路径,文件夹外的主机路径映射到占位目录旁的 .lithe-remote-host 下,不会落到本机真实路径)。git 目录的监听与文件夹监听同样跑在请求自己的 goroutine 上,会话丢失或失去信任时取消。 端口:remote.startForward/stopForward/forwards 与 ports.listening 都带会话发送;Core 只在本机 127.0.0.1 监听,请求的本机端口被占用时选空闲端口并返回 localPortChanged 与 requestedLocalPort;同一目标再次转发返回已有转发(created=false),所以更改本机端口是先停止再转发。顶部输入由 Core 的 remote.parseForwardAddress 解析为目标端口、主机、协议和路径,不连接主机;桌面端把网址的主机换成主机上提供该端口的回环地址再转发。非回环目标需 allowNonLoopback(S28),超过上限返回 forward_limit_reached 并带 maximum。读取在窗口的后台任务里进行,只在窗口打开且被绘制过时排下一次,不做空闲轮询。 WSL:remote.connect 的 connection 与 wsl 二选一,Core 经 wsl.exe --distribution … --exec 启动同一个远端服务,会话身份为 wsl:[用户@]发行版;桌面端的 remoteHost 在 SSH 连接与 WSL 发行版之间二选一,步骤、文件夹选择、信任、工作区和重连共用同一流程。remote.listWslDistributions 在 Windows 以外直接返回不可用,不运行任何程序。" }