1
1
"use strict"
2
2
3
3
import { getUser } from "coder/site/src/api/api"
4
- import { readFileSync } from "fs"
5
4
import * as module from "module"
6
- import path from "path"
7
5
import * as vscode from "vscode"
8
6
import { Commands } from "./commands"
9
7
import { Remote } from "./remote"
10
8
import { Storage } from "./storage"
11
9
12
10
export async function activate ( ctx : vscode . ExtensionContext ) : Promise < void > {
13
- const productJSON = readFileSync ( path . join ( vscode . env . appRoot , "product.json" ) )
14
- const product = JSON . parse ( productJSON . toString ( ) )
15
- const commit = product . commit
16
11
const output = vscode . window . createOutputChannel ( "Coder" )
17
- const storage = new Storage ( output , ctx . globalState , ctx . globalStorageUri )
18
- storage . init ( )
12
+ const storage = new Storage ( output , ctx . globalState , ctx . secrets , ctx . globalStorageUri , ctx . logUri )
13
+ await storage . init ( )
19
14
20
15
getUser ( )
21
16
. then ( ( ) => {
@@ -45,13 +40,16 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
45
40
vscode . commands . registerCommand ( "coder.logout" , commands . logout . bind ( commands ) )
46
41
vscode . commands . registerCommand ( "coder.open" , commands . open . bind ( commands ) )
47
42
48
- // The remote SSH extension is required to provide the restricted
49
- // proposed API for registering remote authority providers.
43
+ // The Remote SSH extension's proposed APIs are used to override
44
+ // the SSH host name in VS Code itself. It's visually unappealing
45
+ // having a lengthy name!
46
+ //
47
+ // This is janky, but that's alright since it provides such minimal
48
+ // functionality to the extension.
50
49
const remoteSSHExtension = vscode . extensions . getExtension ( "ms-vscode-remote.remote-ssh" )
51
50
if ( ! remoteSSHExtension ) {
52
51
throw new Error ( "Remote SSH extension not found" )
53
52
}
54
-
55
53
// eslint-disable-next-line @typescript-eslint/no-explicit-any
56
54
const vscodeProposed : typeof vscode = ( module as any ) . _load (
57
55
"vscode" ,
@@ -61,8 +59,18 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
61
59
false ,
62
60
)
63
61
64
- const remote = new Remote ( output , vscodeProposed , storage , commit )
65
- ctx . subscriptions . push ( remote )
62
+ // Since the "onResolveRemoteAuthority:ssh-remote" activation event exists
63
+ // in package.json we're able to perform actions before the authority is
64
+ // resolved by the remote SSH extension.
65
+ const activeRemotes = vscode . workspace . workspaceFolders ?. filter ( ( folder ) => folder . uri . scheme === "vscode-remote" )
66
+ // If the currently opened folder isn't remote we can return early!
67
+ if ( activeRemotes ?. length !== 1 ) {
68
+ return
69
+ }
70
+ const activeRemote = activeRemotes [ 0 ] . uri
71
+
72
+ ctx . globalStorageUri
66
73
67
- vscodeProposed . workspace . registerRemoteAuthorityResolver ( "coder" , remote )
74
+ const remote = new Remote ( vscodeProposed , storage , ctx . extensionMode )
75
+ await remote . setup ( activeRemote )
68
76
}
0 commit comments