* Suggest similar files if the specified file doesn't exist.
(path: string)
| 163 | * Suggest similar files if the specified file doesn't exist. |
| 164 | */ |
| 165 | async function suggestSimilarFiles(path: string): Promise<string> { |
| 166 | try { |
| 167 | const dir = dirname(path) || '.' |
| 168 | const filename = basename(path) |
| 169 | const resolvedDir = resolve(process.cwd(), dir) |
| 170 | |
| 171 | const files = await readdir(resolvedDir) |
| 172 | const deepnoteFiles = files.filter(f => f.toLowerCase().endsWith('.deepnote')) |
| 173 | |
| 174 | if (deepnoteFiles.length === 0) { |
| 175 | return '\n\nNo .deepnote files found in this directory.' |
| 176 | } |
| 177 | |
| 178 | // Find similar filenames |
| 179 | const similar = deepnoteFiles |
| 180 | .filter(f => { |
| 181 | const baseName = basename(filename, extname(filename)) |
| 182 | return f.toLowerCase().includes(baseName.toLowerCase()) |
| 183 | }) |
| 184 | .slice(0, 3) |
| 185 | |
| 186 | if (similar.length > 0) { |
| 187 | return `\n\nDid you mean?\n${similar.map(f => ` - ${f}`).join('\n')}` |
| 188 | } |
| 189 | |
| 190 | // Show available files |
| 191 | const available = deepnoteFiles.slice(0, 5) |
| 192 | const more = deepnoteFiles.length > 5 ? `\n ... and ${deepnoteFiles.length - 5} more` : '' |
| 193 | return `\n\nAvailable .deepnote files:\n${available.map(f => ` - ${f}`).join('\n')}${more}` |
| 194 | } catch { |
| 195 | return '' |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Get a helpful hint based on the file extension. |
no outgoing calls
no test coverage detected