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

import * as vscode from 'vscode';
import parse from '@emmetio/html-matcher';
import Node from '@emmetio/node';
import { DocumentStreamReader } from './bufferStream';
import { isStyleSheet } from 'vscode-emmet-helper';

export const LANGUAGE_MODES: Object = {
	'html': ['!', '.', '}'],
	'jade': ['!', '.', '}'],
	'slim': ['!', '.', '}'],
	'haml': ['!', '.', '}'],
	'xml': ['.', '}'],
	'xsl': ['.', '}'],
	'javascriptreact': ['.'],
	'typescriptreact': ['.'],
	'css': [':'],
	'scss': [':'],
	'sass': [':'],
	'less': [':'],
	'stylus': [':']
};

// Explicitly map languages to their parent language to get emmet support
export const MAPPED_MODES: Object = {
	'handlebars': 'html'
};
export function validate(allowStylesheet: boolean = true): boolean {
	let editor = vscode.window.activeTextEditor;
	if (!editor) {
		vscode.window.showInformationMessage('No editor is active');
		return false;
	}
	if (!allowStylesheet && isStyleSheet(editor.document.languageId)) {
		return false;
	}
	return true;
}

export function getSyntax(document: vscode.TextDocument): string {
	if (document.languageId === 'jade') {
		return 'pug';
	}
	if (document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact') {
		return 'jsx';
	}
	return document.languageId;
}

export function getMappedModes(): any {
	let finalMappedModes = {};
	let syntaxProfileConfig = vscode.workspace.getConfiguration('emmet')['syntaxProfiles'];
	let syntaxProfiles = Object.assign({}, MAPPED_MODES, syntaxProfileConfig ? syntaxProfileConfig : {});
	Object.keys(syntaxProfiles).forEach(syntax => {
		if (typeof syntaxProfiles[syntax] === 'string' && LANGUAGE_MODES[syntaxProfiles[syntax]]) {
			finalMappedModes[syntax] = syntaxProfiles[syntax];
		}
	});
	return finalMappedModes;
}

/**
 * Returns node corresponding to given position in the given root node
 * @param root 
 * @param position 
 * @param includeNodeBoundary <commit_msg>Remove emmet autocomplete for jsx Fixes #29185<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import parse from '@emmetio/html-matcher';
import Node from '@emmetio/node';
import { DocumentStreamReader } from './bufferStream';
import { isStyleSheet } from 'vscode-emmet-helper';

export const LANGUAGE_MODES: Object = {
	'html': ['!', '.', '}'],
	'jade': ['!', '.', '}'],
	'slim': ['!', '.', '}'],
	'haml': ['!', '.', '}'],
	'xml': ['.', '}'],
	'xsl': ['.', '}'],
	'css': [':'],
	'scss': [':'],
	'sass': [':'],
	'less': [':'],
	'stylus': [':']
};

// Explicitly map languages to their parent language to get emmet completion support
export const MAPPED_MODES: Object = {
	'handlebars': 'html'
};
export function validate(allowStylesheet: boolean = true): boolean {
	let editor = vscode.window.activeTextEditor;
	if (!editor) {
		vscode.window.showInformationMessage('No editor is active');
		return false;
	}
	if (!allowStylesheet && isStyleSheet(editor.document.languageId)) {
		return false;
	}
	return true;
}

export function getSyntax(document: vscode.TextDocument): string {
	if (document.languageId === 'jade') {
		return 'pug';
	}
	return document.languageId;
}

export function getMappedModes(): any {
	let finalMappedModes = {};
	let syntaxProfileConfig = vscode.workspace.getConfiguration('emmet')['syntaxProfiles'];
	let syntaxProfiles = Object.assign({}, MAPPED_MODES, syntaxProfileConfig ? syntaxProfileConfig : {});
	Object.keys(syntaxProfiles).forEach(syntax => {
		if (typeof syntaxProfiles[syntax] === 'string' && LANGUAGE_MODES[syntaxProfiles[syntax]]) {
			finalMappedModes[syntax] = syntaxProfiles[syntax];
		}
	});
	return finalMappedModes;
}

/**
 * Returns node corresponding to given position in the given root node
 * @param root 
 * @param position 
 * @param includeNodeBoundary 
{'fraction_non_alphanumeric': 0.24493471409275103, 'fraction_numerical': 0.0011256190904997748, 'mean_word_length': 3.2476099426386233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3281439', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1339, 'n_words': 322}