* The module edges (`imports` edges into a file node) into the files an * import of `dir/name` can find instead of a file added there: `dir/name.*` * under another extension, and the folder's own entry, `dir/name/index.*` * or `dir/name/__init__.py`. With the source file and language a *
(
dir: string,
name: string
)
| 4059 | * resurrection needs. |
| 4060 | */ |
| 4061 | getModuleImportsNamed( |
| 4062 | dir: string, |
| 4063 | name: string |
| 4064 | ): Array<Edge & { edgeId: number; targetFilePath: string; sourceFilePath: string; sourceLanguage: Language }> { |
| 4065 | const base = dir ? `${dir}/${name}` : name; |
| 4066 | // `x.` up to `x/` and `x/index.` up to `x/index/` ('/' is the byte after '.'). |
| 4067 | const rows = this.db |
| 4068 | .prepare( |
| 4069 | `SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language |
| 4070 | FROM nodes tgt |
| 4071 | JOIN edges e ON e.target = tgt.id AND e.kind = 'imports' |
| 4072 | JOIN nodes src ON src.id = e.source |
| 4073 | WHERE tgt.kind = 'file' |
| 4074 | AND ((tgt.file_path >= ? AND tgt.file_path < ?) OR (tgt.file_path >= ? AND tgt.file_path < ?) OR tgt.file_path = ?)` |
| 4075 | ) |
| 4076 | .all(`${base}.`, `${base}/`, `${base}/index.`, `${base}/index/`, `${base}/__init__.py`) as Array< |
| 4077 | EdgeRow & { target_file_path: string; source_file_path: string; source_language: Language } |
| 4078 | >; |
| 4079 | return rows |
| 4080 | // Not a deeper path that only shares the prefix (`dir/name.d/x.ts`). |
| 4081 | .filter((row) => { |
| 4082 | const file = row.target_file_path; |
| 4083 | if (file === `${base}/__init__.py`) return true; |
| 4084 | const index = `${base}/index.`; |
| 4085 | return !(file.startsWith(index) ? file.slice(index.length) : file.slice(base.length + 1)).includes('/'); |
| 4086 | }) |
| 4087 | .map((row) => ({ |
| 4088 | ...rowToEdge(row), |
| 4089 | edgeId: row.id, |
| 4090 | targetFilePath: row.target_file_path, |
| 4091 | sourceFilePath: row.source_file_path, |
| 4092 | sourceLanguage: row.source_language, |
| 4093 | })); |
| 4094 | } |
| 4095 | |
| 4096 | /** The files with a resolution edge into one of `targetIds`. */ |
| 4097 | getFilesWithEdgesInto(targetIds: string[]): string[] { |
no test coverage detected