( ide: IDE, inputPath: string, )
| 29 | } |
| 30 | |
| 31 | export async function resolveInputPath( |
| 32 | ide: IDE, |
| 33 | inputPath: string, |
| 34 | ): Promise<ResolvedPath | null> { |
| 35 | const trimmedPath = inputPath.trim(); |
| 36 | |
| 37 | // Handle file:// URIs |
| 38 | if (trimmedPath.startsWith("file://")) { |
| 39 | const displayPath = fileURLToPath(trimmedPath); |
| 40 | const isWithinWorkspace = await isUriWithinWorkspace(ide, trimmedPath); |
| 41 | return { |
| 42 | uri: trimmedPath, |
| 43 | displayPath, |
| 44 | isAbsolute: true, |
| 45 | isWithinWorkspace, |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | // Expand tilde paths (handles ~/ and ~username/) |
| 50 | const expandedPath = untildify(trimmedPath); |
| 51 | |
| 52 | // Check if it's an absolute path (including Windows paths) |
| 53 | const isAbsolute = |
| 54 | path.isAbsolute(expandedPath) || |
| 55 | // Windows network paths |
| 56 | expandedPath.startsWith("\\\\") || |
| 57 | // Windows drive letters |
| 58 | /^[a-zA-Z]:/.test(expandedPath); |
| 59 | |
| 60 | if (isAbsolute) { |
| 61 | // Convert to file:// URI format |
| 62 | const uri = pathToFileURL(expandedPath).href; |
| 63 | const isWithinWorkspace = await isUriWithinWorkspace(ide, uri); |
| 64 | return { |
| 65 | uri, |
| 66 | displayPath: expandedPath, |
| 67 | isAbsolute: true, |
| 68 | isWithinWorkspace, |
| 69 | }; |
| 70 | } |
| 71 | |
| 72 | // Handle relative paths... |
| 73 | const workspaceUri = await resolveRelativePathInDir(expandedPath, ide); |
| 74 | if (workspaceUri) { |
| 75 | return { |
| 76 | uri: workspaceUri, |
| 77 | displayPath: expandedPath, |
| 78 | isAbsolute: false, |
| 79 | isWithinWorkspace: true, |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | return null; |
| 84 | } |
no test coverage detected