Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const location = ({
currentDocURI,
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)
)
)
}
export const location = ({
currentDocURI,
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)
)
)
}
export const convertLocation = (location: Location): sourcegraph.Location => ({
uri: new sourcegraph.URI(location.uri),
range: convertRange(location.range),
})
function nodeToLocation(node: LocationConnectionNode): sourcegraph.Location {
return {
uri: new sourcegraph.URI(
`git://${node.resource.repository.name}?${node.resource.commit.oid}#${node.resource.path}`
),
range: new sourcegraph.Range(
node.range.start.line,
node.range.start.character,
node.range.end.line,
node.range.end.character
),
}
}