diff --git a/extensions/ruby/language-configuration.json b/extensions/ruby/language-configuration.json index b508561c897..fe8a5e9e2ac 100644 --- a/extensions/ruby/language-configuration.json +++ b/extensions/ruby/language-configuration.json @@ -21,5 +21,9 @@ ["(", ")"], ["\"", "\""], ["'", "'"] - ] + ], + "indentationRules": { + "increaseIndentPattern": "^\\s*((begin|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while)|(.*\\sdo\\b))\\b[^\\{;]*$", + "decreaseIndentPattern": "^\\s*([}\\]]([,)]?\\s*(#|$)|\\.[a-zA-Z_]\\w*\\b)|(end|rescue|ensure|else|elsif|when)\\b)" + } } \ No newline at end of file diff --git a/extensions/ruby/package.json b/extensions/ruby/package.json index 0599300ca04..827722f1683 100644 --- a/extensions/ruby/package.json +++ b/extensions/ruby/package.json @@ -1,10 +1,8 @@ { "name": "ruby", - "version": "0.2.0", + "version": "0.2.1", "publisher": "vscode", "engines": { "vscode": "*" }, - "activationEvents": ["onLanguage:ruby"], - "main": "./out/rubyMain", "contributes": { "languages": [{ "id": "ruby", @@ -19,10 +17,5 @@ "scopeName": "source.ruby", "path": "./syntaxes/ruby.tmLanguage.json" }] - }, - "scripts": { - "compile": "gulp compile-extension:ruby", - "watch": "gulp watch-extension:ruby", - "update-grammar": "node ../../build/npm/update-grammar.js textmate/ruby.tmbundle Syntaxes/Ruby.plist ./syntaxes/ruby.tmLanguage.json" } } diff --git a/extensions/ruby/src/rubyMain.ts b/extensions/ruby/src/rubyMain.ts deleted file mode 100644 index fd899f545e3..00000000000 --- a/extensions/ruby/src/rubyMain.ts +++ /dev/null @@ -1,15 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 { ExtensionContext, languages } from 'vscode'; - -export function activate(context: ExtensionContext): any { - languages.setLanguageConfiguration('ruby', { - indentationRules: { - increaseIndentPattern: /^\s*((begin|class|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|while)|(.*\sdo\b))\b[^\{;]*$/, - decreaseIndentPattern: /^\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif|when)\b)/ - } - }); -} diff --git a/extensions/ruby/src/typings/ref.d.ts b/extensions/ruby/src/typings/ref.d.ts deleted file mode 100644 index 531d3c037dd..00000000000 --- a/extensions/ruby/src/typings/ref.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -/// \ No newline at end of file diff --git a/extensions/ruby/tsconfig.json b/extensions/ruby/tsconfig.json deleted file mode 100644 index efe5568f2b5..00000000000 --- a/extensions/ruby/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "outDir": "./out", - "lib": [ - "es2015" - ], - "sourceMap": true - }, - "include": [ - "src/**/*" - ] -} \ No newline at end of file diff --git a/src/vs/workbench/parts/codeEditor/electron-browser/languageConfiguration/languageConfigurationExtensionPoint.ts b/src/vs/workbench/parts/codeEditor/electron-browser/languageConfiguration/languageConfigurationExtensionPoint.ts index b34d5b5937c..e36b6f9e85c 100644 --- a/src/vs/workbench/parts/codeEditor/electron-browser/languageConfiguration/languageConfigurationExtensionPoint.ts +++ b/src/vs/workbench/parts/codeEditor/electron-browser/languageConfiguration/languageConfigurationExtensionPoint.ts @@ -7,7 +7,7 @@ import * as nls from 'vs/nls'; import { parse, ParseError } from 'vs/base/common/json'; import { readFile } from 'vs/base/node/pfs'; -import { CharacterPair, LanguageConfiguration, IAutoClosingPair, IAutoClosingPairConditional, CommentRule } from 'vs/editor/common/modes/languageConfiguration'; +import { CharacterPair, LanguageConfiguration, IAutoClosingPair, IAutoClosingPairConditional, IndentationRule, CommentRule } from 'vs/editor/common/modes/languageConfiguration'; import { IModeService } from 'vs/editor/common/services/modeService'; import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry'; import { Extensions, IJSONContributionRegistry } from 'vs/platform/jsonschemas/common/jsonContributionRegistry'; @@ -21,12 +21,20 @@ interface IRegExp { flags?: string; } +interface IIndentationRules { + decreaseIndentPattern: string | IRegExp; + increaseIndentPattern: string | IRegExp; + indentNextLinePattern?: string | IRegExp; + unIndentedLinePattern?: string | IRegExp; +} + interface ILanguageConfiguration { comments?: CommentRule; brackets?: CharacterPair[]; autoClosingPairs?: (CharacterPair | IAutoClosingPairConditional)[]; surroundingPairs?: (CharacterPair | IAutoClosingPair)[]; wordPattern?: string | IRegExp; + indentationRules?: IIndentationRules; } export class LanguageConfigurationFileHandler { @@ -92,28 +100,63 @@ export class LanguageConfigurationFileHandler { } if (configuration.wordPattern) { - let pattern = ''; - let flags = ''; - - if (typeof configuration.wordPattern === 'string') { - pattern = configuration.wordPattern; - } else if (typeof configuration.wordPattern === 'object') { - pattern = configuration.wordPattern.pattern; - flags = configuration.wordPattern.flags; - } - - if (pattern) { - try { - richEditConfig.wordPattern = new RegExp(pattern, flags); - } catch (error) { - // Malformed regexes are ignored + try { + let wordPattern = this._parseRegex(configuration.wordPattern); + if (wordPattern) { + richEditConfig.wordPattern = wordPattern; } + } catch (error) { + // Malformed regexes are ignored + } + } + + if (configuration.indentationRules) { + let indentationRules = this._mapIndentationRules(configuration.indentationRules); + if (indentationRules) { + richEditConfig.indentationRules = indentationRules; } } LanguageConfigurationRegistry.register(languageIdentifier, richEditConfig); } + private _parseRegex(value: string | IRegExp) { + if (typeof value === 'string') { + return new RegExp(value, ''); + } else if (typeof value === 'object') { + return new RegExp(value.pattern, value.flags); + } + + return null; + } + + private _mapIndentationRules(indentationRules: IIndentationRules): IndentationRule { + try { + let increaseIndentPattern = this._parseRegex(indentationRules.increaseIndentPattern); + let decreaseIndentPattern = this._parseRegex(indentationRules.decreaseIndentPattern); + + if (increaseIndentPattern && decreaseIndentPattern) { + let result: IndentationRule = { + increaseIndentPattern: increaseIndentPattern, + decreaseIndentPattern: decreaseIndentPattern + }; + + if (indentationRules.indentNextLinePattern) { + result.indentNextLinePattern = this._parseRegex(indentationRules.indentNextLinePattern); + } + if (indentationRules.unIndentedLinePattern) { + result.unIndentedLinePattern = this._parseRegex(indentationRules.unIndentedLinePattern); + } + + return result; + } + } catch (error) { + // Malformed regexes are ignored + } + + return null; + } + private _mapCharacterPairs(pairs: (CharacterPair | IAutoClosingPairConditional)[]): IAutoClosingPairConditional[] { return pairs.map(pair => { if (Array.isArray(pair)) { @@ -252,6 +295,88 @@ const schema: IJSONSchema = { patternErrorMessage: nls.localize('schema.wordPattern.flags.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.') } } + }, + indentationRules: { + default: { + increaseIndentPattern: '', + decreaseIndentPattern: '' + }, + description: nls.localize('schema.indentationRules', 'The language\'s indentation settings.'), + type: 'object', + properties: { + increaseIndentPattern: { + type: ['string', 'object'], + description: nls.localize('schema.indentationRules.increaseIndentPattern', 'If a line matches this pattern, then all the lines after it should be indented once (until another rule matches).'), + properties: { + pattern: { + type: 'string', + description: nls.localize('schema.indentationRules.increaseIndentPattern.pattern', 'The RegExp pattern for increaseIndentPattern.'), + default: '', + }, + flags: { + type: 'string', + description: nls.localize('schema.indentationRules.increaseIndentPattern.flags', 'The RegExp flags for increaseIndentPattern.'), + default: '', + pattern: '^([gimuy]+)$', + patternErrorMessage: nls.localize('schema.indentationRules.increaseIndentPattern.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.') + } + } + }, + decreaseIndentPattern: { + type: ['string', 'object'], + description: nls.localize('schema.indentationRules.decreaseIndentPattern', 'If a line matches this pattern, then all the lines after it should be unindendented once (until another rule matches).'), + properties: { + pattern: { + type: 'string', + description: nls.localize('schema.indentationRules.decreaseIndentPattern.pattern', 'The RegExp pattern for decreaseIndentPattern.'), + default: '', + }, + flags: { + type: 'string', + description: nls.localize('schema.indentationRules.decreaseIndentPattern.flags', 'The RegExp flags for decreaseIndentPattern.'), + default: '', + pattern: '^([gimuy]+)$', + patternErrorMessage: nls.localize('schema.indentationRules.decreaseIndentPattern.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.') + } + } + }, + indentNextLinePattern: { + type: ['string', 'object'], + description: nls.localize('schema.indentationRules.indentNextLinePattern', 'If a line matches this pattern, then **only the next line** after it should be indented once.'), + properties: { + pattern: { + type: 'string', + description: nls.localize('schema.indentationRules.indentNextLinePattern.pattern', 'The RegExp pattern for indentNextLinePattern.'), + default: '', + }, + flags: { + type: 'string', + description: nls.localize('schema.indentationRules.indentNextLinePattern.flags', 'The RegExp flags for indentNextLinePattern.'), + default: '', + pattern: '^([gimuy]+)$', + patternErrorMessage: nls.localize('schema.indentationRules.indentNextLinePattern.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.') + } + } + }, + unIndentedLinePattern: { + type: ['string', 'object'], + description: nls.localize('schema.indentationRules.unIndentedLinePattern', 'If a line matches this pattern, then its indentation should not be changed and it should not be evaluated against the other rules.'), + properties: { + pattern: { + type: 'string', + description: nls.localize('schema.indentationRules.unIndentedLinePattern.pattern', 'The RegExp pattern for unIndentedLinePattern.'), + default: '', + }, + flags: { + type: 'string', + description: nls.localize('schema.indentationRules.unIndentedLinePattern.flags', 'The RegExp flags for unIndentedLinePattern.'), + default: '', + pattern: '^([gimuy]+)$', + patternErrorMessage: nls.localize('schema.indentationRules.unIndentedLinePattern.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.') + } + } + } + } } } };