mirror of
https://github.com/langgenius/dify.git
synced 2026-11-13 06:41:07 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
25 lines
915 B
JavaScript
25 lines
915 B
JavaScript
/** Read explicitly labeled backend links; leave other hover documentation links alone. */
|
|
function backendLocations(contents) {
|
|
const locations = new Map()
|
|
for (const content of contents) {
|
|
const markdown = typeof content === 'string' ? content : content.value
|
|
if (typeof markdown !== 'string') continue
|
|
for (const match of markdown.matchAll(
|
|
/\[Open backend implementation\]\((file:\/\/[^\s)]+)#L([1-9]\d*)\)/g,
|
|
)) {
|
|
const line = Number(match[2])
|
|
if (!Number.isSafeInteger(line)) continue
|
|
try {
|
|
const url = new URL(match[1])
|
|
if (url.protocol !== 'file:' || url.search || url.hash) continue
|
|
locations.set(`${url.href}#${line}`, { uri: url.href, line })
|
|
} catch {
|
|
// Malformed optional metadata must not interfere with normal TS navigation.
|
|
}
|
|
}
|
|
}
|
|
return [...locations.values()]
|
|
}
|
|
|
|
module.exports = { backendLocations }
|