|
4 | 4 | type Workspace, |
5 | 5 | type WorkspaceAgent, |
6 | 6 | } from "coder/site/src/api/typesGenerated"; |
7 | | -import * as jsonc from "jsonc-parser"; |
8 | 7 | import * as fs from "node:fs/promises"; |
9 | 8 | import * as os from "node:os"; |
10 | 9 | import * as path from "node:path"; |
@@ -60,6 +59,7 @@ import { |
60 | 59 | } from "./sshConfig"; |
61 | 60 | import { SshProcessMonitor } from "./sshProcess"; |
62 | 61 | import { computeSshProperties, sshSupportsSetEnv } from "./sshSupport"; |
| 62 | +import { applySettingOverrides, buildSshOverrides } from "./userSettings"; |
63 | 63 | import { WorkspaceStateMachine } from "./workspaceStateMachine"; |
64 | 64 |
|
65 | 65 | export interface RemoteDetails extends vscode.Disposable { |
@@ -459,85 +459,17 @@ export class Remote { |
459 | 459 | const inbox = await Inbox.create(workspace, workspaceClient, this.logger); |
460 | 460 | disposables.push(inbox); |
461 | 461 |
|
462 | | - // Do some janky setting manipulation. |
463 | 462 | this.logger.info("Modifying settings..."); |
464 | | - const remotePlatforms = vscodeProposed.workspace |
465 | | - .getConfiguration() |
466 | | - .get<Record<string, string>>("remote.SSH.remotePlatform", {}); |
467 | | - const connTimeout = vscodeProposed.workspace |
468 | | - .getConfiguration() |
469 | | - .get<number | undefined>("remote.SSH.connectTimeout"); |
470 | | - |
471 | | - // We have to directly munge the settings file with jsonc because trying to |
472 | | - // update properly through the extension API hangs indefinitely. Possibly |
473 | | - // VS Code is trying to update configuration on the remote, which cannot |
474 | | - // connect until we finish here leading to a deadlock. We need to update it |
475 | | - // locally, anyway, and it does not seem possible to force that via API. |
476 | | - let settingsContent = "{}"; |
477 | | - try { |
478 | | - settingsContent = await fs.readFile( |
479 | | - this.pathResolver.getUserSettingsPath(), |
480 | | - "utf8", |
481 | | - ); |
482 | | - } catch { |
483 | | - // Ignore! It's probably because the file doesn't exist. |
484 | | - } |
485 | | - |
486 | | - // Add the remote platform for this host to bypass a step where VS Code asks |
487 | | - // the user for the platform. |
488 | | - let mungedPlatforms = false; |
489 | | - if ( |
490 | | - !remotePlatforms[parts.sshHost] || |
491 | | - remotePlatforms[parts.sshHost] !== agent.operating_system |
492 | | - ) { |
493 | | - remotePlatforms[parts.sshHost] = agent.operating_system; |
494 | | - settingsContent = jsonc.applyEdits( |
495 | | - settingsContent, |
496 | | - jsonc.modify( |
497 | | - settingsContent, |
498 | | - ["remote.SSH.remotePlatform"], |
499 | | - remotePlatforms, |
500 | | - {}, |
501 | | - ), |
502 | | - ); |
503 | | - mungedPlatforms = true; |
504 | | - } |
505 | | - |
506 | | - // VS Code ignores the connect timeout in the SSH config and uses a default |
507 | | - // of 15 seconds, which can be too short in the case where we wait for |
508 | | - // startup scripts. For now we hardcode a longer value. Because this is |
509 | | - // potentially overwriting user configuration, it feels a bit sketchy. If |
510 | | - // microsoft/vscode-remote-release#8519 is resolved we can remove this. |
511 | | - const minConnTimeout = 1800; |
512 | | - let mungedConnTimeout = false; |
513 | | - if (!connTimeout || connTimeout < minConnTimeout) { |
514 | | - settingsContent = jsonc.applyEdits( |
515 | | - settingsContent, |
516 | | - jsonc.modify( |
517 | | - settingsContent, |
518 | | - ["remote.SSH.connectTimeout"], |
519 | | - minConnTimeout, |
520 | | - {}, |
521 | | - ), |
522 | | - ); |
523 | | - mungedConnTimeout = true; |
524 | | - } |
525 | | - |
526 | | - if (mungedPlatforms || mungedConnTimeout) { |
527 | | - try { |
528 | | - await fs.writeFile( |
529 | | - this.pathResolver.getUserSettingsPath(), |
530 | | - settingsContent, |
531 | | - ); |
532 | | - } catch (ex) { |
533 | | - // This could be because the user's settings.json is read-only. This is |
534 | | - // the case when using home-manager on NixOS, for example. Failure to |
535 | | - // write here is not necessarily catastrophic since the user will be |
536 | | - // asked for the platform and the default timeout might be sufficient. |
537 | | - mungedPlatforms = mungedConnTimeout = false; |
538 | | - this.logger.warn("Failed to configure settings", ex); |
539 | | - } |
540 | | - } |
| 463 | + const overrides = buildSshOverrides( |
| 464 | + vscodeProposed.workspace.getConfiguration(), |
| 465 | + parts.sshHost, |
| 466 | + agent.operating_system, |
| 467 | + ); |
| 468 | + await applySettingOverrides( |
| 469 | + this.pathResolver.getUserSettingsPath(), |
| 470 | + overrides, |
| 471 | + this.logger, |
| 472 | + ); |
541 | 473 |
|
542 | 474 | const logDir = this.getLogDir(featureSet); |
543 | 475 |
|
|
0 commit comments