How to use the sourcegraph.URI function in sourcegraph

To help you get started, we’ve selected a few sourcegraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / sourcegraph-go / src / convert-lsp-to-sea.ts View on Github external
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)
            )
    )
}
github sourcegraph / sourcegraph-go / src / convert-lsp-to-sea.ts View on Github external
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)
            )
    )
}
github sourcegraph / sourcegraph-typescript / extension / src / lsp-conversion.ts View on Github external
export const convertLocation = (location: Location): sourcegraph.Location => ({
    uri: new sourcegraph.URI(location.uri),
    range: convertRange(location.range),
})
github sourcegraph / sourcegraph-basic-code-intel / package / src / lsif.ts View on Github external
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
        ),
    }
}