Skip to content

Commit 334bd1c

Browse files
committed
install remote, jupyter, python extensions
1 parent 0d37773 commit 334bd1c

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

pkg/cmd/open/open.go

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ func startWorkspaceIfStopped(t *terminal.Terminal, tstore OpenStore, wsIDOrName
203203
return nil
204204
}
205205

206+
func tryToInstallExtensions(
207+
t *terminal.Terminal,
208+
extIDs []string,
209+
) error {
210+
for _, extID := range extIDs {
211+
extInstalled, err0 := uutil.IsVSCodeExtensionInstalled(extID)
212+
if !extInstalled {
213+
err1 := uutil.InstallVscodeExtension(extID)
214+
isRemoteInstalled, err2 := uutil.IsVSCodeExtensionInstalled(extID)
215+
if !isRemoteInstalled {
216+
err := multierror.Append(err0, err1, err2)
217+
t.Print(t.Red("Couldn't install the necessary VSCode extension automatically.\nError: " + err.Error()))
218+
t.Print("\tPlease install VSCode and the following VSCode extension: " + t.Yellow(extID) + ".\n")
219+
_ = terminal.PromptGetInput(terminal.PromptContent{
220+
Label: "Hit enter when finished:",
221+
ErrorMsg: "error",
222+
AllowEmpty: true,
223+
})
224+
}
225+
}
226+
}
227+
return nil
228+
}
229+
206230
// Opens code editor. Attempts to install code in path if not installed already
207231
func openVsCodeWithSSH(
208232
t *terminal.Terminal,
@@ -231,37 +255,15 @@ func openVsCodeWithSSH(
231255
s.Stop()
232256
t.Vprintf("\n")
233257

234-
// Check if user uses VSCode and intall extension for user
235-
isInstalled, err := uutil.IsVSCodeExtensionInstalled("ms-vscode-remote.remote-ssh")
258+
err = tryToInstallExtensions(t, []string{"ms-vscode-remote.remote-ssh", "ms-toolsai.jupyter-keymap", "ms-python.python"})
236259
if err != nil {
237-
t.Print(t.Red("Couldn't install the necessary VSCode extension automatically."))
238-
t.Print("\tPlease install VSCode and the following VSCode extension: " + t.Yellow("ms-vscode-remote.remote-ssh") + ".\n")
239-
_ = terminal.PromptGetInput(terminal.PromptContent{
240-
Label: "Hit enter when finished:",
241-
ErrorMsg: "error",
242-
AllowEmpty: true,
243-
})
244-
}
245-
// If we couldn't check for the extension being installed, they likely don't have code in path and this step should be skipped
246-
if !isInstalled && err == nil {
247-
// attempt to install the extension
248-
_ = uutil.InstallVscodeExtension("ms-vscode-remote.remote-ssh")
249-
250-
// verify installation
251-
isInstalled, err = uutil.IsVSCodeExtensionInstalled("ms-vscode-remote.remote-ssh")
252-
// tell the user to install manually if still not installed
253-
if !isInstalled || err != nil {
254-
t.Print(t.Red("Couldn't install the necessary VSCode extension automatically."))
255-
t.Print("\tPlease install VSCode and the following VSCode extension: " + t.Yellow("ms-vscode-remote.remote-ssh") + ".\n")
256-
_ = terminal.PromptGetInput(terminal.PromptContent{
257-
Label: "Hit enter when finished:",
258-
ErrorMsg: "error",
259-
AllowEmpty: true,
260-
})
261-
}
260+
return breverrors.WrapAndTrace(err)
262261
}
263262

264263
err = openVsCode(sshAlias, path, tstore)
264+
if err != nil {
265+
return breverrors.WrapAndTrace(err)
266+
}
265267

266268
// check if we are in a brev environment, if so transform the error message
267269
// to indicate that the user should run brev open locally instead of in

0 commit comments

Comments
 (0)