Skip to content

Commit 16bd37d

Browse files
committed
fixup! feat(VSCode): add support for IDE inside Flatpak
1 parent cd4654f commit 16bd37d

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

cmd/agent/container/setup.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ func (cmd *SetupContainerCmd) installIDE(setupInfo *config.Result, ide *provider
413413
return cmd.setupVSCode(setupInfo, ide.Options, vscode.FlavorPositron, log)
414414
case string(config2.IDECodium):
415415
return cmd.setupVSCode(setupInfo, ide.Options, vscode.FlavorCodium, log)
416+
case string(config2.IDECodiumInsiders):
417+
return cmd.setupVSCode(setupInfo, ide.Options, vscode.FlavorCodiumInsiders, log)
416418
case string(config2.IDEOpenVSCode):
417419
return cmd.setupOpenVSCode(setupInfo, ide.Options, log)
418420
case string(config2.IDEGoland):

pkg/ide/vscode/open.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package vscode
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
@@ -76,7 +77,7 @@ func openViaCLI(ctx context.Context, workspace, folder string, newWindow bool, f
7677
}
7778

7879
if codePath[0] == "flatpak" {
79-
log.Debugf("Running with Flatpak suing the package %s.", codePath[2])
80+
log.Debugf("Running with Flatpak using the package %s.", codePath[2])
8081
out, err := exec.Command(codePath[0], "ps", "--columns=application").Output()
8182
if err != nil {
8283
return command.WrapCommandError(out, err)
@@ -144,10 +145,18 @@ func openViaCLI(ctx context.Context, workspace, folder string, newWindow bool, f
144145
folderUriArg := fmt.Sprintf("--folder-uri=vscode-remote://ssh-remote+%s.devpod/%s", workspace, folder)
145146
args = append(codePath, args...)
146147
args = append(args, folderUriArg)
148+
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
149+
var b bytes.Buffer
150+
if codePath[0] != "flatpak" {
151+
cmd.Stdout = &b
152+
cmd.Stderr = &b
153+
} else {
154+
log.Debug("Skipping output capture due to issue with `flatpak run` leading the command to hang")
155+
}
147156
log.Debugf("Run %s command %s %s", flavor.DisplayName(), args[0], strings.Join(args[1:], " "))
148-
out, err = exec.CommandContext(ctx, args[0], args[1:]...).CombinedOutput()
157+
err = cmd.Run()
149158
if err != nil {
150-
return command.WrapCommandError(out, err)
159+
return command.WrapCommandError(b.Bytes(), err)
151160
}
152161

153162
return nil

pkg/ide/vscode/vscode.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,48 @@ func (o *VsCodeServer) findServerBinaryPath(location string) string {
341341
return binPath
342342
}
343343

344+
if o.flavor == FlavorCodiumInsiders {
345+
// check legacy location `$HOME/.vscodium-server-insiders/bin`
346+
binDir := filepath.Join(location, "bin")
347+
for {
348+
if time.Now().After(deadline) {
349+
o.log.Warn("Timed out installing vscodium-server-insiders")
350+
break
351+
}
352+
entries, err := os.ReadDir(binDir)
353+
if err != nil || len(entries) == 0 {
354+
o.log.Infof("Read dir %s: %v", binDir, err)
355+
o.log.Info("Wait until vscodium-server-insiders is installed...")
356+
// check new location `$HOME/.vscodium-server-insiders/cli/servers/Stable-<version>/server/bin/code-server`
357+
newBinPath, err := o.findCodeServerBinary(location)
358+
if err != nil {
359+
o.log.Infof("Read new location %s: %v", location, err)
360+
o.log.Info("Wait until vscodium is installed...")
361+
time.Sleep(time.Second * 3)
362+
continue
363+
}
364+
365+
binPath = newBinPath
366+
break
367+
}
368+
369+
binPath = filepath.Join(binDir, entries[0].Name(), "bin", "codium-server-insiders")
370+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
371+
out, err := exec.CommandContext(ctx, binPath, "--help").CombinedOutput()
372+
cancel()
373+
if err != nil {
374+
o.log.Infof("Execute %s: %v", binPath, command.WrapCommandError(out, err))
375+
o.log.Info("Wait until vscodium-server-insiders is installed...")
376+
time.Sleep(time.Second * 3)
377+
continue
378+
}
379+
380+
break
381+
}
382+
383+
return binPath
384+
}
385+
344386
if o.flavor == FlavorInsiders {
345387
serversDir := filepath.Join(location, "cli", "servers")
346388
for {
@@ -457,6 +499,8 @@ func prepareServerLocation(userName string, create bool, flavor Flavor) (string,
457499
folderName = ".positron-server"
458500
case FlavorCodium:
459501
folderName = ".vscodium-server"
502+
case FlavorCodiumInsiders:
503+
folderName = ".vscodium-server-insiders"
460504
}
461505

462506
folder := filepath.Join(homeFolder, folderName)

0 commit comments

Comments
 (0)