How to use the sourcegraph.configuration 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 / src / extension.ts View on Github external
function enabledOrNull(provider: () => T): T | null {
    let value = sourcegraph.configuration.get().value[
        'basicCodeIntel.enabled'
    ]
    if (value === undefined) {
        value = true // default true
    }
    if (!value) {
        return null
    }
    return provider()
}
github sourcegraph / sourcegraph-typescript / src / extension / extension.ts View on Github external
export async function activate(ctx: sourcegraph.ExtensionContext): Promise {
    logger.log('TypeScript extension activated')

    // Cancel everything whene extension is deactivated
    const cancellationTokenSource = new CancellationTokenSource()
    ctx.subscriptions.add(() => cancellationTokenSource.cancel())
    const token = cancellationTokenSource.token

    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  */
github sourcegraph / sourcegraph-basic-code-intel / package / src / lsif.ts View on Github external
) => async (
        doc: sourcegraph.TextDocument,
        pos: sourcegraph.Position
    ): Promise> => {
        if (!sourcegraph.configuration.get().get('codeIntel.lsif')) {
            console.log('LSIF is not enabled in global settings')
            return undefined
        }

        if (noLSIFData.has(doc.uri)) {
            return undefined
        }

        const result = await f(doc, pos)
        if (result === undefined) {
            noLSIFData.add(doc.uri)
        }

        return result
    }
github sourcegraph / sourcegraph-go / src / lang-go.ts View on Github external
rootURI: rootURIFromDoc(doc),
            requestType: new lspProtocol.RequestType('textDocument/xdefinition') as any,
            request: positionParams(doc, pos),
            useCache: true,
        })) as lspext.Xdefinition[] | null
        if (!definitions) {
            console.error('No response to xdefinition')
            return Promise.reject()
        }
        if (definitions.length === 0) {
            console.error('No definitions')
            return Promise.reject()
        }
        const definition = definitions[0]
        const limit = sourcegraph.configuration.get().get('go.maxExternalReferenceRepos') || 20
        const gddoURL = sourcegraph.configuration.get().get('go.gddoURL')
        const corsAnywhereURL = sourcegraph.configuration.get().get('go.corsAnywhereURL')
        function composeForward(f: (a: A) => B, g: (b: B) => C): (a: A) => C {
            return a => g(f(a))
        }
        function identity<a>(a: A): A {
            return a
        }
        function mkBuildGDDOURL(gddoURL: string): (path: string) =&gt; string {
            return composeForward(
                (path: string): string =&gt; {
                    const importersURL = new URL(gddoURL)
                    importersURL.pathname = 'importers/' + path
                    return importersURL.href
                },
                corsAnywhereURL ? (url: string): string =&gt; corsAnywhereURL + url : (identity as (url: string) =&gt; string)
            )</a>
github sourcegraph / sourcegraph-typescript / src / extension / auth.ts View on Github external
return undefined
    }
    const currentUserId: string = currentUser.id
    const result = await queryGraphQL(
        gql`
            mutation CreateAccessToken($user: ID!, $scopes: [String!]!, $note: String!) {
                createAccessToken(user: $user, scopes: $scopes, note: $note) {
                    id
                    token
                }
            }
        `,
        { user: currentUserId, scopes: ['user:all'], note: 'lang-typescript' }
    )
    const token: string = result.createAccessToken.token
    await sourcegraph.configuration.get().update('typescript.accessToken', token)
    return token
}
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / util.ts View on Github external
sourcegraph.configuration.subscribe(() =&gt; {
            subscriber.next(sourcegraph.configuration.get().value)
        })
    )
github sourcegraph / sourcegraph / extensions / enterprise / sandbox / src / util.ts View on Github external
new Observable(subscriber =&gt;
        sourcegraph.configuration.subscribe(() =&gt; {
            subscriber.next(sourcegraph.configuration.get().value)
        })
    )
github sourcegraph / sourcegraph / extensions / enterprise / check-search / src / util.ts View on Github external
new Observable(subscriber =&gt;
        sourcegraph.configuration.subscribe(() =&gt; {
            subscriber.next(sourcegraph.configuration.get().value)
        })
    )
github sourcegraph / sourcegraph-basic-code-intel / src / extension.ts View on Github external
const settingsSubscribable = new Observable(sub =&gt; {
    sub.next(sourcegraph.configuration.get().value)
    return sourcegraph.configuration.subscribe(() =&gt;
        sub.next(sourcegraph.configuration.get().value)
    )
})