Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb43713

Browse files
matifalimafredri
andauthored
fix: VSCode desktop connection (#7120)
Co-authored-by: Mathias Fredriksson <[email protected]>
1 parent 942aba3 commit bb43713

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

agent/agent.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,5 +1407,14 @@ func expandDirectory(dir string) (string, error) {
14071407
}
14081408
dir = filepath.Join(home, dir[1:])
14091409
}
1410-
return os.ExpandEnv(dir), nil
1410+
dir = os.ExpandEnv(dir)
1411+
1412+
if !filepath.IsAbs(dir) {
1413+
home, err := userHomeDir()
1414+
if err != nil {
1415+
return "", err
1416+
}
1417+
dir = filepath.Join(home, dir)
1418+
}
1419+
return dir, nil
14111420
}

agent/agent_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,22 @@ func TestAgent_Startup(t *testing.T) {
13911391
require.Equal(t, homeDir, client.getStartup().ExpandedDirectory)
13921392
})
13931393

1394+
t.Run("NotAbsoluteDirectory", func(t *testing.T) {
1395+
t.Parallel()
1396+
1397+
_, client, _, _, _ := setupAgent(t, agentsdk.Manifest{
1398+
StartupScript: "true",
1399+
StartupScriptTimeout: 30 * time.Second,
1400+
Directory: "coder/coder",
1401+
}, 0)
1402+
assert.Eventually(t, func() bool {
1403+
return client.getStartup().Version != ""
1404+
}, testutil.WaitShort, testutil.IntervalFast)
1405+
homeDir, err := os.UserHomeDir()
1406+
require.NoError(t, err)
1407+
require.Equal(t, filepath.Join(homeDir, "coder/coder"), client.getStartup().ExpandedDirectory)
1408+
})
1409+
13941410
t.Run("HomeEnvironmentVariable", func(t *testing.T) {
13951411
t.Parallel()
13961412

docs/templates/open-in-coder.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ To support any infrastructure and software stack, Coder provides a generic appro
3838
}
3939
```
4040
41+
> Note: The `dir` attribute can be set in multiple ways, for example:
42+
>
43+
> - `~/coder`
44+
> - `/home/coder/coder`
45+
> - `coder` (relative to the home directory)
46+
4147
- If you want the template to support any repository via [parameters](./parameters.md)
4248
4349
```hcl

0 commit comments

Comments
 (0)