<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { workspace, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Range, Location, CancellationToken } from 'vscode';

import * as Proto  from '../protocol';
import { ITypescriptServiceClient } from '../typescriptService';

let _kindMapping: { [kind: string]: SymbolKind } = Object.create(null);
_kindMapping['method'] = SymbolKind.Method;
_kindMapping['enum'] = SymbolKind.Enum;
_kindMapping['function'] = SymbolKind.Function;
_kindMapping['class'] = SymbolKind.Class;
_kindMapping['interface'] = SymbolKind.Interface;
_kindMapping['var'] = SymbolKind.Variable;

export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbolProvider {

	private client: ITypescriptServiceClient;
	private modeId: string;

	public constructor(client: ITypescriptServiceClient, modeId: string) {
		this.client = client;
		this.modeId = modeId;
	}

	public provideWorkspaceSymbols(search: string, token :CancellationToken): Promise<SymbolInformation[]> {
		// typescript wants to have a resource even when asking
		// general questions so we check all open documents for
		// one that is typescript'ish
		let uri: Uri;
		let documents = workspace.textDocuments;
		for (let document of documents) {
			if (document.languageId === this.modeId) {
				uri = document.uri;
				break;
			}
		}

		if (!uri) {
			return Promise.resolve<SymbolInformation[]>([]);
		}

		let args:Proto.NavtoRequestArgs = {
			file: this.client.asAbsolutePath(uri),
			searchValue: search
		};
		if (!args.file) {
			return Promise.resolve<SymbolInformation[]>([]);
		}
		return this.client.execute('navto', args, token).then((response):SymbolInformation[] => {
			let data = response.body;
			if (data) {
				let result: SymbolInformation[] = [];
				for (let item of data) {
					if (!item.containerName && item.kind === 'alias') {
						continue;<commit_msg>Fixes #8081: "Open Symbol By Name" is not working properly in multipy typescript projects.<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { workspace, window, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Range, Location, CancellationToken } from 'vscode';

import * as Proto  from '../protocol';
import { ITypescriptServiceClient } from '../typescriptService';

let _kindMapping: { [kind: string]: SymbolKind } = Object.create(null);
_kindMapping['method'] = SymbolKind.Method;
_kindMapping['enum'] = SymbolKind.Enum;
_kindMapping['function'] = SymbolKind.Function;
_kindMapping['class'] = SymbolKind.Class;
_kindMapping['interface'] = SymbolKind.Interface;
_kindMapping['var'] = SymbolKind.Variable;

export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbolProvider {

	private client: ITypescriptServiceClient;
	private modeId: string;

	public constructor(client: ITypescriptServiceClient, modeId: string) {
		this.client = client;
		this.modeId = modeId;
	}

	public provideWorkspaceSymbols(search: string, token :CancellationToken): Promise<SymbolInformation[]> {
		// typescript wants to have a resource even when asking
		// general questions so we check the active editor. If this
		// doesn't match we take the first TS document.
		let uri: Uri;
		let editor = window.activeTextEditor;
		if (editor) {
			let document = editor.document;
			if (document && document.languageId === this.modeId) {
				uri = document.uri;
			}
		}
		if (!uri) {
			let documents = workspace.textDocuments;
			for (let document of documents) {
				if (document.languageId === this.modeId) {
					uri = document.uri;
					break;
				}
			}
		}

		if (!uri) {
			return Promise.resolve<SymbolInformation[]>([]);
		}

		let args:Proto.NavtoRequestArgs = {
			file: this.client.asAbsolutePath(uri),
			searchValue: search
		};
		if (!args.file) {
			return Promise.resolve<SymbolInformation[]>([]);
		}
		return this.client.execute('navto', args, token).then((response):SymbolInformation[] => {
			let data = response.body;
			if (data) {
				let result: SymbolInformation[] = [];
				for (let item of data) {
					if (!item.containerName && item.kind === 'alias') {
						continue;
{'fraction_non_alphanumeric': 0.19008782936010038, 'fraction_numerical': 0.000836470096194061, 'mean_word_length': 3.0637213254035682, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2402578', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1265, 'n_words': 362}