MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveHop

Function resolveHop

src/ui-server/api/trails.ts:145–205  ·  view source on GitHub ↗
(cg: CodeGraph, hop: StoredHop)

Source from the content-addressed store, hash-verified

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

Callers 1

resolveTrailFunction · 0.85

Calls 3

getNodeMethod · 0.80
matchesFunction · 0.70

Tested by

no test coverage detected