Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 */
const clientSgEndpoint: SourcegraphEndpoint = {
url: new URL(sourcegraph.internal.sourcegraphURL.toString()),
accessToken,
}
const diagnosticsDecorationType = sourcegraph.app.createDecorationType()
const codeActionsDecorationType = sourcegraph.app.createDecorationType()
} from './resources'
import { sanitizeTsConfigs } from './tsconfig'
import { relativeUrl, URLMap, URLSet } from './uri'
import { install } from './yarn'
const globalLogger = new RedactingLogger(console)
process.on('uncaughtException', err => {
globalLogger.error('Uncaught exception:', err)
process.exit(1)
})
const CACHE_DIR = process.env.CACHE_DIR || fs.realpathSync(tmpdir())
globalLogger.log(`Using CACHE_DIR ${CACHE_DIR}`)
let tracer = new Tracer()
if (process.env.LIGHTSTEP_ACCESS_TOKEN) {
globalLogger.log('LightStep tracing enabled')
tracer = new LightstepTracer({
access_token: process.env.LIGHTSTEP_ACCESS_TOKEN,
component_name: 'lang-typescript',
})
}
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080
let httpServer: http.Server | https.Server
if (process.env.TLS_CERT && process.env.TLS_KEY) {
globalLogger.log('TLS encryption enabled')
httpServer = https.createServer({
cert: process.env.TLS_CERT,
key: process.env.TLS_KEY,
beforeEach(function () {
tracer = new Tracer()
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
}
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
})
beforeEach(function () {
tracer = new Tracer()
mockRootSpan = {
setTag: this.sandbox.spy()
}
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
}
this.sandbox.stub(cls, 'getRootSpan').callsFake(() => mockRootSpan)
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
instrumentation.patch(express, [tracer])
})
beforeEach(function (done) {
tracer = new Tracer()
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
}
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
instrumentation.patch(mongodbCore, [tracer])
db = monk('localhost/mydb', done)
dbSites = db.get('sites')
})
beforeEach(function () {
tracer = new Tracer()
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
}
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
instrumentation.patch(pg, [tracer])
db = knex({
client: 'pg',
connection: process.env.PG_URI
})
})
parseInt
)
.option('-t, --trace', 'print all requests and responses')
.option('-l, --logfile [file]', 'log to this file')
.option('-j, --enable-jaeger', 'enable OpenTracing through Jaeger')
.parse(process.argv)
const options: ServeOptions & TypeScriptServiceOptions = {
clusterSize: program.cluster || numCPUs,
lspPort: program.port || defaultLspPort,
strict: program.strict,
logMessages: program.trace,
logger: program.logfile ? new FileLogger(program.logfile) : new StdioLogger(),
tracer: program.enableJaeger
? initTracer({ serviceName: 'javascript-typescript-langserver', sampler: { type: 'const', param: 1 } })
: new Tracer(),
}
serve(options, client => new TypeScriptService(client, options))
function createNoopTracer() {
return new opentracing.Tracer();
}
function createNonReportingTracer() {
beforeEach(function () {
tracer = new Tracer()
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
}
this.sandbox.stub(cls, 'startChildSpan').callsFake(() => mockChildSpan)
instrumentation.patch(redis, [tracer])
client = redis.createClient()
})
export async function findClosestPackageJson(
resource: URL,
pickResourceRetriever: ResourceRetrieverPicker,
rootUri = Object.assign(new URL(resource.href), { pathname: '' }),
{
span = new Span(),
tracer = new Tracer(),
}: {
span?: Span
tracer?: Tracer
} = {}
): Promise<[URL, PackageJson]> {
return await tracePromise(
'Find closest package.json',
tracer,
span,
async (span): Promise<[URL, PackageJson]> => {
for (const parent of walkUp(resource)) {
if (!parent.href.startsWith(rootUri.href)) {
break
}
const packageJsonUri = new URL('package.json', parent.href)
try {