Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
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 */
) => 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
}
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) => string {
return composeForward(
(path: string): string => {
const importersURL = new URL(gddoURL)
importersURL.pathname = 'importers/' + path
return importersURL.href
},
corsAnywhereURL ? (url: string): string => corsAnywhereURL + url : (identity as (url: string) => string)
)</a>
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
}
sourcegraph.configuration.subscribe(() => {
subscriber.next(sourcegraph.configuration.get().value)
})
)
new Observable(subscriber =>
sourcegraph.configuration.subscribe(() => {
subscriber.next(sourcegraph.configuration.get().value)
})
)
new Observable(subscriber =>
sourcegraph.configuration.subscribe(() => {
subscriber.next(sourcegraph.configuration.get().value)
})
)
const settingsSubscribable = new Observable(sub => {
sub.next(sourcegraph.configuration.get().value)
return sourcegraph.configuration.subscribe(() =>
sub.next(sourcegraph.configuration.get().value)
)
})