(cg: CodeGraph, hop: StoredHop)
| 141 | * stranger in the middle of somebody's explanation. |
| 142 | */ |
| 143 | export function resolveHop(cg: CodeGraph, hop: StoredHop): WireTrailHop { |
| 144 | const base = { |
| 145 | dir: hop.dir, |
| 146 | name: hop.name, |
| 147 | qualifiedName: hop.qualifiedName, |
| 148 | kind: hop.kind, |
| 149 | savedFile: hop.file, |
| 150 | savedLine: hop.line, |
| 151 | }; |
| 152 | |
| 153 | const byId = hop.id ? cg.getNode(hop.id) : null; |
| 154 | if (byId && matches(byId, hop)) { |
| 155 | return { ...base, status: 'ok', id: byId.id, file: byId.filePath, line: byId.startLine, note: null }; |
| 156 | } |
| 157 | |
| 158 | const candidates = cg |
| 159 | .getNodesByQualifiedName(hop.qualifiedName) |
| 160 | .filter((node) => hop.kind === '' || node.kind === hop.kind); |
| 161 | |
| 162 | if (candidates.length === 0) { |
| 163 | return { |
| 164 | ...base, |
| 165 | status: 'missing', |
| 166 | id: null, |
| 167 | file: null, |
| 168 | line: null, |
| 169 | note: `no longer in the index — moved or renamed since this trail was saved`, |
| 170 | }; |
| 171 | } |
| 172 | |
| 173 | const sameFile = candidates.filter((node) => node.filePath === hop.file); |
| 174 | if (sameFile.length === 1) { |
| 175 | const node = sameFile[0] as Node; |
| 176 | return { ...base, status: 'ok', id: node.id, file: node.filePath, line: node.startLine, note: null }; |
| 177 | } |
| 178 | |
| 179 | if (candidates.length === 1) { |
| 180 | const node = candidates[0] as Node; |
| 181 | return { |
| 182 | ...base, |
| 183 | status: 'moved', |
| 184 | id: node.id, |
| 185 | file: node.filePath, |
| 186 | line: node.startLine, |
| 187 | note: `moved from ${hop.file || 'an unrecorded file'} to ${node.filePath}`, |
| 188 | }; |
| 189 | } |
| 190 | |
| 191 | // Several symbols carry this name and none of them is where it used to be. |
| 192 | // The best guess is offered — a row nobody can open is not more honest, it |
| 193 | // is just less useful — but it is labelled as a guess. |
| 194 | const pick = (sameFile[0] ?? candidates[0]) as Node; |
| 195 | return { |
| 196 | ...base, |
| 197 | status: 'ambiguous', |
| 198 | id: pick.id, |
| 199 | file: pick.filePath, |
| 200 | line: pick.startLine, |
no test coverage detected