How to use the sourcegraph.internal 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-basic-code-intel / package / src / lsif.ts View on Github external
if (!sourcegraph.configuration.get().get('codeIntel.lsif')) {
            console.log('LSIF is not enabled in global settings')
            return Promise.resolve(false)
        }

        if (lsifDocs.has(doc.uri)) {
            return lsifDocs.get(doc.uri)!
        }

        const repository = repositoryFromDoc(doc)
        const commit = commitFromDoc(doc)
        const file = pathFromDoc(doc)

        const url = new URL(
            '.api/lsif/exists',
            sourcegraph.internal.sourcegraphURL
        )
        url.searchParams.set('repository', repository)
        url.searchParams.set('commit', commit)
        url.searchParams.set('file', file)

        const hasLSIFPromise = (async () => {
            try {
                // Prevent leaking the name of a private repository to
                // Sourcegraph.com by relying on the Sourcegraph extension host's
                // private repository detection, which will throw an error when
                // making a GraphQL request.
                await queryGraphQL({
                    query: `query { currentUser { id } }`,
                    vars: {},
                    sourcegraph,
                })
github codecov / sourcegraph-codecov / src / extension.ts View on Github external
// Store coverage ratio (and Codecov report URL) for each file at this commit so that
            // template strings in contributions can refer to these values.
            const fileRatios = await getFileCoverageRatios(
                lastURI,
                endpoint,
                sourcegraph
            )
            for (const [path, ratio] of Object.entries(fileRatios)) {
                const uri = `git://${lastURI.repo}?${lastURI.rev}#${path}`
                context[`codecov.coverageRatio.${uri}`] = ratio.toFixed(0)
                context[`codecov.fileURL.${uri}`] = `${baseFileURL}/${path}`
            }
        } catch (err) {
            console.error(`Error loading Codecov file coverage: ${err}`)
        }
        sourcegraph.internal.updateContext(context)
    }
    sourcegraph.configuration.subscribe(() => updateContext())
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / execServer / client.ts View on Github external
'github.com/sd9org/react-router': 'github.com/ReactTraining/react-router',
        'github.com/sd9/react-loading-spinner': 'github.com/sourcegraph/react-loading-spinner',
        'github.com/sd9/graphql-dotnet': 'github.com/graphql-dotnet/graphql-dotnet',
        'github.com/sd9/taskbotjs': 'github.com/eropple/taskbotjs',
        'github.com/sd9/ReactStateMuseum': 'github.com/GantMan/ReactStateMuseum',
        'github.com/sd9/sonarqube': 'github.com/SonarSource/sonarqube',
        'github.com/sd9/ReactNativeReduxCasts': 'github.com/StephenGrider/ReactNativeReduxCasts',
        'github.com/sd9/astyanax': 'github.com/netflix/astyanax',
        'github.com/sd9/dynomite': 'github.com/netflix/astyanax',
        'github.com/sd9/functions-samples': 'github.com/firebase/functions-samples',
    }
    if (repo in MAP || sourcegraph.internal.sourcegraphURL.hostname === 'localhost') {
        return `https://sourcegraph.com/${MAP[repo] || repo}@${commit}/-/raw/`
    }
    // TODO!(sqs): requires token
    return new URL(`/${repo}@${commit}/-/raw/`, sourcegraph.internal.sourcegraphURL).toString()
}
github sourcegraph / sourcegraph-go / src / lang-go.ts View on Github external
function sourcegraphURL(): URL {
    const url =
        (sourcegraph.configuration.get().get('go.sourcegraphUrl') as string | undefined) ||
        sourcegraph.internal.sourcegraphURL.toString()
    try {
        return new URL(url)
    } catch (e) {
        if ('message' in e && /Invalid URL/.test(e.message)) {
            console.error(
                new Error(
                    [
                        `Invalid go.sourcegraphUrl ${url} in your Sourcegraph settings.`,
                        `Make sure it is set to the address of Sourcegraph from the perspective of the language server (e.g. http://sourcegraph-frontend:30080).`,
                        `Read the full documentation for more information: https://github.com/sourcegraph/sourcegraph-go`,
                    ].join('\n')
                )
            )
        }
        throw e
    }
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / rubyGemDependency / rubyBundler.ts View on Github external
commit: string
    path?: string
}

export interface BundlerExecutionResult {
    commands: {
        combinedOutput: string
        ok: boolean
        error?: string
    }[]
    files: { [path: string]: string }
}

const RUBY_BUNDLER_EXEC_SERVICE_URL = new URL(
    '/.api/extension-containers/a8n-ruby-bundler-exec',
    sourcegraph.internal.sourcegraphURL
)

/**
 * Executes a Ruby `bundle` command in a repository tree and returns the resulting contents of
 * `Gemfile` and `Gemfile.lock`.
 */
const executeBundlerCommandUncached = async ({
    commands,
    context,
}: {
    commands: string[][]
    context: BundlerExecutionContext
}): Promise => {
    const url = new URL('', RUBY_BUNDLER_EXEC_SERVICE_URL)
    url.searchParams.set(
        'params',
github sourcegraph / sourcegraph-typescript / src / extension / extension.ts View on Github external
const lsif = initLSIF()
    const basicCodeIntel = initBasicCodeIntel()

    const tracer: Tracer = config.value['lightstep.token']
        ? new LightstepTracer({ access_token: config.value['lightstep.token'], component_name: 'ext-lang-typescript' })
        : new Tracer()

    const accessToken = await getOrCreateAccessToken()
    /** The Sourcegraph endpoint contactable by the server */
    const serverSgEndpoint: SourcegraphEndpoint = {
        url: new URL(config.value['typescript.sourcegraphUrl'] || sourcegraph.internal.sourcegraphURL.toString()),
        accessToken,
    }
    /** The Sourcegraph endpoint contactable by the extension  */
    const clientSgEndpoint: SourcegraphEndpoint = {
        url: new URL(sourcegraph.internal.sourcegraphURL.toString()),
        accessToken,
    }

    const diagnosticsDecorationType = sourcegraph.app.createDecorationType()
    const codeActionsDecorationType = sourcegraph.app.createDecorationType()

    sourcegraph.commands.registerCommand('typescript.toggle', async () => {
        const config = sourcegraph.configuration.get()
        await config.update('typescript.enable', config.value['typescript.enable'] === false)
    })

    const enabled = new BehaviorSubject(config.value['typescript.enable'] !== false)
    ctx.subscriptions.add(
        from(config)
            .pipe(
                rxop.map(config => config['typescript.enable'] !== false),
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / execServer / client.ts View on Github external
export const createExecServerClient = (
    containerName: string,
    includeFiles: Params['includeFiles'] = [],
    cache = true
): ExecServerClient => {
    const baseUrl = new URL(`/.api/extension-containers/${containerName}`, sourcegraph.internal.sourcegraphURL)

    const do2: ExecServerClient = async ({ commands, dir, files, context, label }) => {
        await limiter.acquire()
        try {
            const request: Request = {
                params: {
                    archiveURL: context ? getPublicRepoArchiveUrl(context.repository, context.commit) : undefined,
                    commands,
                    dir,
                    includeFiles,
                },
                payload: { files },
            }
            const hasPayload = Boolean(
                request.payload && request.payload.files && Object.keys(request.payload.files).length > 0
            )
github sourcegraph / sourcegraph / lsif / extension / src / lsif.ts View on Github external
async function send({
    doc,
    method,
    path,
    position,
}: {
    doc: sourcegraph.TextDocument
    method: string
    path: string
    position: LSP.Position
}): Promise {
    const url = new URL('.api/lsif/request', sourcegraph.internal.sourcegraphURL)
    url.searchParams.set('repository', repositoryFromDoc(doc))
    url.searchParams.set('commit', commitFromDoc(doc))

    const response = await fetch(url.href, {
        method: 'POST',
        headers: new Headers({
            'content-type': 'application/json',
            'x-requested-with': 'Sourcegraph LSIF extension',
        }),
        body: JSON.stringify({
            method,
            path,
            position,
        }),
    })
    if (!response.ok) {
github sourcegraph / sourcegraph-typescript / src / extension / extension.ts View on Github external
const config = new BehaviorSubject(getConfig())
    ctx.subscriptions.add(sourcegraph.configuration.subscribe(() => config.next(getConfig())))

    const isLSIFAvailable = mkIsLSIFAvailable()
    const lsif = initLSIF()
    const basicCodeIntel = initBasicCodeIntel()

    const tracer: Tracer = config.value['lightstep.token']
        ? new LightstepTracer({ access_token: config.value['lightstep.token'], component_name: 'ext-lang-typescript' })
        : new Tracer()

    const accessToken = await getOrCreateAccessToken()
    /** The Sourcegraph endpoint contactable by the server */
    const serverSgEndpoint: SourcegraphEndpoint = {
        url: new URL(config.value['typescript.sourcegraphUrl'] || sourcegraph.internal.sourcegraphURL.toString()),
        accessToken,
    }
    /** The Sourcegraph endpoint contactable by the extension  */
    const clientSgEndpoint: SourcegraphEndpoint = {
        url: new URL(sourcegraph.internal.sourcegraphURL.toString()),
        accessToken,
    }

    const diagnosticsDecorationType = sourcegraph.app.createDecorationType()
    const codeActionsDecorationType = sourcegraph.app.createDecorationType()

    sourcegraph.commands.registerCommand('typescript.toggle', async () => {
        const config = sourcegraph.configuration.get()
        await config.update('typescript.enable', config.value['typescript.enable'] === false)
    })