Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
location: { range, uri: uriFromLangServer },
}: {
currentDocURI: string
location: lsp.Location
}): sourcegraph.Location => {
let definitionURI: sourcegraph.URI
if (/^file:\/\/\//.test(uriFromLangServer)) {
// The definition is in a file in the same repo
const docURL = new URL(currentDocURI)
docURL.hash = uriFromLangServer.slice('file:///'.length)
definitionURI = new sourcegraph.URI(docURL.href)
} else {
definitionURI = new sourcegraph.URI(uriFromLangServer)
}
return new sourcegraph.Location(
definitionURI,
range &&
new sourcegraph.Range(
new sourcegraph.Position(range.start.line, range.start.character),
new sourcegraph.Position(range.end.line, range.end.character)
)
)
}
const diagnostics: sourcegraph.Diagnostic[] = clones.map(c => {
const numLines = c.duplicationA.end.line - c.duplicationA.start.line
return {
resource: new URL(c.duplicationA.sourceId),
range: duplicationRange(c.duplicationA),
message: `Duplicated code (${numLines} line${numLines !== 1 ? 's' : ''})`,
source: 'codeDuplication',
severity: sourcegraph.DiagnosticSeverity.Information,
relatedInformation: [
{
location: new sourcegraph.Location(
new URL(c.duplicationB.sourceId),
duplicationRange(c.duplicationB)
),
message: 'Duplicated here',
},
],
data: JSON.stringify(c),
tags: [c.format],
check: CHECK_CODE_DUPLICATION,
} as sourcegraph.Diagnostic
})
return diagnostics