@@ -70,7 +70,7 @@ func ListDevcontainers() ([]DevcontainerInfo, error) {
7070 }
7171 }
7272 localPath := parts [listPartLocalFolder ]
73- if strings . HasPrefix (localPath , " \\ \\ wsl$" ) && wsl .IsWsl () {
73+ if wsl . HasWslPathPrefix (localPath ) && wsl .IsWsl () {
7474 localPath , err = wsl .ConvertWindowsPathToWslPath (localPath )
7575 if err != nil {
7676 return []DevcontainerInfo {}, fmt .Errorf ("error converting path: %s" , err )
@@ -143,7 +143,7 @@ func GetSourceInfoFromDevContainer(containerIDOrName string) (SourceInfo, error)
143143 return SourceInfo {}, err
144144 }
145145
146- if strings . HasPrefix (localPath , " \\ \\ wsl$" ) && wsl .IsWsl () {
146+ if wsl . HasWslPathPrefix (localPath ) && wsl .IsWsl () {
147147 localPath , err = wsl .ConvertWindowsPathToWslPath (localPath )
148148 if err != nil {
149149 return SourceInfo {}, fmt .Errorf ("error converting path: %s" , err )
@@ -165,7 +165,7 @@ func GetSourceInfoFromDevContainer(containerIDOrName string) (SourceInfo, error)
165165 var mount DockerMount
166166 err = json .Unmarshal (output , & mount )
167167 if err != nil {
168- return SourceInfo {}, fmt .Errorf ("failed to get parse JSON getting mount folder for container %q (path=%q): %s" , containerIDOrName , mountFolder , err )
168+ return SourceInfo {}, fmt .Errorf ("failed to parse JSON getting mount folder for container %q (path=%q): %s" , containerIDOrName , mountFolder , err )
169169 }
170170
171171 return SourceInfo {
@@ -199,13 +199,22 @@ func GetClosestPathMatchForPath(devContainers []DevcontainerInfo, devcontainerPa
199199 matchingPaths := byLocalPathLength {}
200200 for _ , devcontainer := range devContainers {
201201 // Treat as match if the specified path is within the devcontainer path
202- if strings .HasPrefix (absPath , devcontainer .LocalFolderPath ) {
202+ testPath := devcontainer .LocalFolderPath
203+ if wsl .IsWsl () && wsl .HasWslPathPrefix (testPath ) {
204+ testPath , err = wsl .ConvertWindowsPathToWslPath (testPath )
205+ fmt .Println ("Converted to.." )
206+ if err != nil {
207+ return DevcontainerInfo {}, fmt .Errorf ("Error converting path from dev container list (%q): %s" , testPath , err )
208+ }
209+ }
210+ if strings .HasPrefix (absPath , testPath ) {
203211 matchingPaths = append (matchingPaths , devcontainer )
204212 }
205213 }
206214 if len (matchingPaths ) == 0 {
207215 return DevcontainerInfo {}, fmt .Errorf ("Could not find running container for path %q" , devcontainerPath )
208216 }
217+
209218 // return longest prefix match
210219 sort .Sort (matchingPaths )
211220 return matchingPaths [len (matchingPaths )- 1 ], nil
0 commit comments