<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 'vs/workbench/parts/snippets/electron-browser/snippetsService';
import 'vs/workbench/parts/snippets/electron-browser/insertSnippet';
import 'vs/workbench/parts/snippets/electron-browser/tabCompletion';

import nls = require('vs/nls');
import winjs = require('vs/base/common/winjs.base');
import paths = require('vs/base/common/paths');
import actions = require('vs/base/common/actions');
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import platform = require('vs/platform/platform');
import workbenchActionRegistry = require('vs/workbench/common/actionRegistry');
import workbenchContributions = require('vs/workbench/common/contributions');
import snippetsTracker = require('./snippetsTracker');
import tmSnippets = require('./TMSnippets');
import * as pfs from 'vs/base/node/pfs';
import errors = require('vs/base/common/errors');
import { IQuickOpenService, IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import fs = require('fs');

class OpenSnippetsAction extends actions.Action {

	public static ID = 'workbench.action.openSnippets';
	public static LABEL = nls.localize('openSnippet.label', "Open User Snippets");

	constructor(
		id: string,
		label: string,
		@IEnvironmentService private environmentService: IEnvironmentService,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@IModeService private modeService: IModeService,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(id, label);
	}

	private openFile(filePath: string): winjs.TPromise<void> {
		return this.windowsService.openWindow([filePath], { forceReuseWindow: true });
	}

	public run(): winjs.Promise {
		var modeIds = this.modeService.getRegisteredModes();
		var picks: IPickOpenEntry[] = [];
		modeIds.forEach((modeId) => {
			var name = this.modeService.getLanguageName(modeId);
			if (name) {
				picks.push({ label: name, id: modeId });
			}
		});
		picks = picks.sort((e1, e2) =>
			e1.label.localeCompare(e2.label)
		);

		return this.quickOpenService.pick(picks, { placeHolder: nls.localize('openSnippet.pickLanguage', "Select Language for Snippet") }).then((language) => {
			if (language) {
				var snippetPath = paths.join(this.environmentService.appSettingsHome, 'snippets', language.id + '.json');
				return fileExists(snippetPath).then((success) => {
					if (success) {
						return this.openFile(snippetPath);
					}
					var defaultContent = [
						'{',
						'/*',
						'\t // Place your snippets for ' + language.label + ' here. Each snippet is defined under a snippet name and has a prefix, body and ',
						'\t // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:',
						'\t // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the ',
						'\t // same ids are connected.',
						'\t // Example:',
						'\t "Print to console": {',
						'\t\t"prefix": "log",',
						'\t\t"body": [',
						'\t\t\t"console.log(\'$1\');",',
						'\t\t\t"$2"',
						'\t\t],',
						'\t\t"description": "Log output to console"',
						'\t}',
						'*/',
						'}'
					].join('\n');<commit_msg>remove mixed indentation, fixes #21173<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 'vs/workbench/parts/snippets/electron-browser/snippetsService';
import 'vs/workbench/parts/snippets/electron-browser/insertSnippet';
import 'vs/workbench/parts/snippets/electron-browser/tabCompletion';

import nls = require('vs/nls');
import winjs = require('vs/base/common/winjs.base');
import paths = require('vs/base/common/paths');
import actions = require('vs/base/common/actions');
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import platform = require('vs/platform/platform');
import workbenchActionRegistry = require('vs/workbench/common/actionRegistry');
import workbenchContributions = require('vs/workbench/common/contributions');
import snippetsTracker = require('./snippetsTracker');
import tmSnippets = require('./TMSnippets');
import * as pfs from 'vs/base/node/pfs';
import errors = require('vs/base/common/errors');
import { IQuickOpenService, IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import fs = require('fs');

class OpenSnippetsAction extends actions.Action {

	public static ID = 'workbench.action.openSnippets';
	public static LABEL = nls.localize('openSnippet.label', "Open User Snippets");

	constructor(
		id: string,
		label: string,
		@IEnvironmentService private environmentService: IEnvironmentService,
		@IQuickOpenService private quickOpenService: IQuickOpenService,
		@IModeService private modeService: IModeService,
		@IWindowsService private windowsService: IWindowsService
	) {
		super(id, label);
	}

	private openFile(filePath: string): winjs.TPromise<void> {
		return this.windowsService.openWindow([filePath], { forceReuseWindow: true });
	}

	public run(): winjs.Promise {
		var modeIds = this.modeService.getRegisteredModes();
		var picks: IPickOpenEntry[] = [];
		modeIds.forEach((modeId) => {
			var name = this.modeService.getLanguageName(modeId);
			if (name) {
				picks.push({ label: name, id: modeId });
			}
		});
		picks = picks.sort((e1, e2) =>
			e1.label.localeCompare(e2.label)
		);

		return this.quickOpenService.pick(picks, { placeHolder: nls.localize('openSnippet.pickLanguage', "Select Language for Snippet") }).then((language) => {
			if (language) {
				var snippetPath = paths.join(this.environmentService.appSettingsHome, 'snippets', language.id + '.json');
				return fileExists(snippetPath).then((success) => {
					if (success) {
						return this.openFile(snippetPath);
					}
					var defaultContent = [
						'{',
						'/*',
						'\t// Place your snippets for ' + language.label + ' here. Each snippet is defined under a snippet name and has a prefix, body and ',
						'\t// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:',
						'\t// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the ',
						'\t// same ids are connected.',
						'\t// Example:',
						'\t"Print to console": {',
						'\t\t"prefix": "log",',
						'\t\t"body": [',
						'\t\t\t"console.log(\'$1\');",',
						'\t\t\t"$2"',
						'\t\t],',
						'\t\t"description": "Log output to console"',
						'\t}',
						'*/',
						'}'
					].join('\n');
{'fraction_non_alphanumeric': 0.1851620167646691, 'fraction_numerical': 0.0033779557112473416, 'mean_word_length': 3.4044077134986224, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 13, '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': '260660', 'n_tokens_mistral': 2621, 'n_tokens_neox': 2282, 'n_words': 564}