How to use the opentracing.Span function in opentracing

To help you get started, we’ve selected a few opentracing 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 / javascript-typescript-langserver / src / typescript-service.ts View on Github external
    public executeCodeFixCommand(fileTextChanges: ts.FileTextChanges[], span = new Span()): Observable {
        if (fileTextChanges.length === 0) {
            return Observable.throw(new Error('No changes supplied for code fix command'))
        }

        return this.projectManager
            .ensureOwnFiles(span)
            .concat(
                Observable.defer(() => {
                    // Configuration lookup uses Windows paths, FileTextChanges uses unix paths. Convert to backslashes.
                    const unixFilePath = fileTextChanges[0].fileName
                    const firstChangedFile = /^[a-z]:\//i.test(unixFilePath)
                        ? unixFilePath.replace(/\//g, '\\')
                        : unixFilePath

                    const configuration = this.projectManager.getConfiguration(firstChangedFile)
                    configuration.ensureBasicFiles(span)
github sourcegraph / javascript-typescript-langserver / src / project-manager.ts View on Github external
    public ensureBasicFiles(span = new Span()): void {
        if (this.ensuredBasicFiles) {
            return
        }

        this.init(span)

        const program = this.getProgram(span)
        if (!program) {
            return
        }

        // Add all global declaration files from the workspace and all declarations from the project
        for (const uri of this.fs.uris()) {
            const fileName = uri2path(uri)
            const unixPath = toUnixPath(fileName)
            if (isGlobalTSFile(unixPath) || this.isExpectedDeclarationFile(unixPath)) {
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
    public textDocumentDocumentSymbol(params: DocumentSymbolParams, span = new Span()): Observable {
        const uri = normalizeUri(params.textDocument.uri)

        // Ensure files needed to resolve symbols are fetched
        return this.projectManager
            .ensureReferencedFiles(uri, undefined, undefined, span)
            .toArray()
            .mergeMap(() => {
                const fileName = uri2path(uri)

                const config = this.projectManager.getConfiguration(fileName)
                config.ensureBasicFiles(span)
                const sourceFile = this._getSourceFile(config, fileName, span)
                if (!sourceFile) {
                    return []
                }
                const tree = config.getService().getNavigationTree(fileName)
github sourcegraph / javascript-typescript-langserver / src / project-manager.ts View on Github external
    private resolveReferencedFiles(uri: string, span = new Span()): Observable {
        let observable = this.referencedFiles.get(uri)
        if (observable) {
            return observable
        }
        observable = this.updater
            .ensure(uri)
            .concat(
                Observable.defer(() => {
                    const referencingFilePath = uri2path(uri)
                    const config = this.getConfiguration(referencingFilePath)
                    config.ensureBasicFiles(span)
                    const contents = this.inMemoryFs.getContent(uri)
                    const info = ts.preProcessFile(contents, true, true)
                    const compilerOpt = config.getHost().getCompilationSettings()
                    const pathResolver = referencingFilePath.includes('\\') ? path.win32 : path.posix
                    // Iterate imported files
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
    public textDocumentSignatureHelp(params: TextDocumentPositionParams, span = new Span()): Observable {
        const uri = normalizeUri(params.textDocument.uri)

        // Ensure files needed to resolve signature are fetched
        return this.projectManager
            .ensureReferencedFiles(uri, undefined, undefined, span)
            .toArray()
            .map(
                (): SignatureHelp => {
                    const filePath = uri2path(uri)
                    const configuration = this.projectManager.getConfiguration(filePath)
                    configuration.ensureBasicFiles(span)

                    const sourceFile = this._getSourceFile(configuration, filePath, span)
                    if (!sourceFile) {
                        throw new Error(`expected source file ${filePath} to exist in configuration`)
                    }
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
	protected _getHover(params: TextDocumentPositionParams, span = new Span()): Observable {
		const uri = normalizeUri(params.textDocument.uri);

		// Ensure files needed to resolve hover are fetched
		return this.projectManager.ensureReferencedFiles(uri, undefined, undefined, span)
			.toArray()
			.map((): Hover => {
				const fileName: string = uri2path(uri);
				const configuration = this.projectManager.getConfiguration(fileName);
				configuration.ensureBasicFiles(span);

				const sourceFile = this._getSourceFile(configuration, fileName, span);
				if (!sourceFile) {
					throw new Error(`Unknown text document ${uri}`);
				}
				const offset: number = ts.getPositionOfLineAndCharacter(sourceFile, params.position.line, params.position.character);
				const info = configuration.getService().getQuickInfoAtPosition(fileName, offset);
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
    public initialize(params: InitializeParams, span = new Span()): Observable {
        // tslint:disable:deprecation
        if (params.rootUri || params.rootPath) {
            this.root = params.rootPath || uri2path(params.rootUri!)
            this.rootUri = params.rootUri || path2uri(params.rootPath!)
            // tslint:enable:deprecation

            this.supportsCompletionWithSnippets =
                (params.capabilities.textDocument &&
                    params.capabilities.textDocument.completion &&
                    params.capabilities.textDocument.completion.completionItem &&
                    params.capabilities.textDocument.completion.completionItem.snippetSupport) ||
                false

            // The root URI always refers to a directory
            if (!this.rootUri.endsWith('/')) {
                this.rootUri += '/'
github sourcegraph / javascript-typescript-langserver / src / project-manager.ts View on Github external
    public ensureAllFiles(span = new Span()): void {
        if (this.ensuredAllFiles) {
            return
        }
        this.init(span)
        if (this.getHost().complete) {
            return
        }
        const program = this.getProgram(span)
        if (!program) {
            return
        }
        for (const fileName of this.expectedFilePaths) {
            const sourceFile = program.getSourceFile(fileName)
            if (!sourceFile) {
                this.getHost().addFile(fileName)
            }
github sourcegraph / sourcegraph-typescript / src / server / resources.ts View on Github external
public async exists(
        resource: URL,
        { span = new Span(), tracer = new Tracer() }: { span?: Span; tracer?: Tracer } = {}
    ): Promise {
        try {
            const headers = {
                'User-Agent': USER_AGENT,
            }
            tracer.inject(span, FORMAT_HTTP_HEADERS, headers)
            await got.head(resource, { headers })
            return true
        } catch (err) {
            if (err.statusCode === 404) {
                return false
            }
            throw err
        }
    }
github sourcegraph / javascript-typescript-langserver / src / typescript-service.ts View on Github external
	workspaceExecuteCommand(params: ExecuteCommandParams, span = new Span()): Observable {
		switch (params.command) {
			case 'codeFix':
				if (!params.arguments || params.arguments.length < 1) {
					return Observable.throw(new Error(`Command ${params.command} requires arguments`));
				}
				return this.executeCodeFixCommand(params.arguments, span);
			default:
				return Observable.throw(new Error(`Unknown command ${params.command}`));
		}
	}