How to use the sourcegraph.Location 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
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 / extensions / enterprise / check-search / src / codeDuplication.ts View on Github external
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