* 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
)
| 3948 | * resurrection needs. |
| 3949 | */ |
| 3950 | getModuleImportsNamed( |
| 3951 | dir: string, |
| 3952 | name: string |
| 3953 | ): Array<Edge & { edgeId: number; targetFilePath: string; sourceFilePath: string; sourceLanguage: Language }> { |
| 3954 | const base = dir ? `${dir}/${name}` : name; |
| 3955 | // `x.` up to `x/` and `x/index.` up to `x/index/` ('/' is the byte after '.'). |
| 3956 | const rows = this.db |
| 3957 | .prepare( |
| 3958 | `SELECT e.*, tgt.file_path AS target_file_path, src.file_path AS source_file_path, src.language AS source_language |
| 3959 | FROM nodes tgt |
| 3960 | JOIN edges e ON e.target = tgt.id AND e.kind = 'imports' |
| 3961 | JOIN nodes src ON src.id = e.source |
| 3962 | WHERE tgt.kind = 'file' |
| 3963 | AND ((tgt.file_path >= ? AND tgt.file_path < ?) OR (tgt.file_path >= ? AND tgt.file_path < ?) OR tgt.file_path = ?)` |
| 3964 | ) |
| 3965 | .all(`${base}.`, `${base}/`, `${base}/index.`, `${base}/index/`, `${base}/__init__.py`) as Array< |
| 3966 | EdgeRow & { target_file_path: string; source_file_path: string; source_language: Language } |
| 3967 | >; |
| 3968 | return rows |
| 3969 | // Not a deeper path that only shares the prefix (`dir/name.d/x.ts`). |
| 3970 | .filter((row) => { |
| 3971 | const file = row.target_file_path; |
| 3972 | if (file === `${base}/__init__.py`) return true; |
| 3973 | const index = `${base}/index.`; |
| 3974 | return !(file.startsWith(index) ? file.slice(index.length) : file.slice(base.length + 1)).includes('/'); |
| 3975 | }) |
| 3976 | .map((row) => ({ |
| 3977 | ...rowToEdge(row), |
| 3978 | edgeId: row.id, |
| 3979 | targetFilePath: row.target_file_path, |
| 3980 | sourceFilePath: row.source_file_path, |
| 3981 | sourceLanguage: row.source_language, |
| 3982 | })); |
| 3983 | } |
| 3984 | |
| 3985 | /** The files with a resolution edge into one of `targetIds`. */ |
| 3986 | getFilesWithEdgesInto(targetIds: string[]): string[] { |
no test coverage detected