mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Merge pull request #208423 from microsoft/aiday/indentationTestsAccrossDifferentLanguages
Adding indentation tests for different languages
This commit is contained in:
commit
28fecb9490
|
@ -18,12 +18,15 @@ import { NullState } from 'vs/editor/common/languages/nullTokenize';
|
|||
import { AutoIndentOnPaste, IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/editor/contrib/indentation/browser/indentation';
|
||||
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
import { javascriptIndentationRules } from 'vs/editor/test/common/modes/supports/javascriptIndentationRules';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
import { goIndentationRules, javascriptIndentationRules, phpIndentationRules, rubyIndentationRules } from 'vs/editor/test/common/modes/supports/indentationRules';
|
||||
import { cppOnEnterRules, javascriptOnEnterRules, phpOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
|
||||
|
||||
enum Language {
|
||||
TypeScript,
|
||||
Ruby
|
||||
Ruby,
|
||||
PHP,
|
||||
Go,
|
||||
CPP
|
||||
}
|
||||
|
||||
function testIndentationToSpacesCommand(lines: string[], selection: Selection, tabSize: number, expectedLines: string[], expectedSelection: Selection): void {
|
||||
|
@ -47,6 +50,7 @@ function registerLanguageConfiguration(instantiationService: TestInstantiationSe
|
|||
case Language.TypeScript:
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['${', '}'],
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
|
@ -66,10 +70,38 @@ function registerLanguageConfiguration(instantiationService: TestInstantiationSe
|
|||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
indentationRules: {
|
||||
decreaseIndentPattern: /^\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif)\b|(in|when)\s)/,
|
||||
increaseIndentPattern: /^\s*((begin|class|(private|protected)\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\sdo\b)|([^#]*=\s*(case|if|unless)))\b([^#\{;]|(\"|'|\/).*\4)*(#.*)?$/,
|
||||
},
|
||||
indentationRules: rubyIndentationRules,
|
||||
}));
|
||||
break;
|
||||
case Language.PHP:
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
indentationRules: phpIndentationRules,
|
||||
onEnterRules: phpOnEnterRules
|
||||
}));
|
||||
break;
|
||||
case Language.Go:
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
indentationRules: goIndentationRules
|
||||
}));
|
||||
break;
|
||||
case Language.CPP:
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
onEnterRules: cppOnEnterRules
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
@ -599,6 +631,45 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
|
|||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test.skip('issue #201420: incorrect indentation when first line is comment', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/201420
|
||||
|
||||
const model = createTextModel([
|
||||
'function bar() {',
|
||||
'',
|
||||
'}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
|
||||
const tokens = [
|
||||
[{ startIndex: 0, value: 0 }, { startIndex: 8, value: 0 }, { startIndex: 9, value: 0 }, { startIndex: 12, value: 0 }, { startIndex: 13, value: 0 }, { startIndex: 14, value: 0 }, { startIndex: 15, value: 0 }, { startIndex: 16, value: 0 }],
|
||||
[{ startIndex: 0, value: 1 }, { startIndex: 2, value: 1 }, { startIndex: 3, value: 1 }, { startIndex: 10, value: 1 }],
|
||||
[{ startIndex: 0, value: 0 }, { startIndex: 5, value: 0 }, { startIndex: 6, value: 0 }, { startIndex: 9, value: 0 }, { startIndex: 10, value: 0 }, { startIndex: 11, value: 0 }, { startIndex: 12, value: 0 }, { startIndex: 14, value: 0 }],
|
||||
[{ startIndex: 0, value: 0 }, { startIndex: 1, value: 0 }]
|
||||
];
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
registerTokens(instantiationService, tokens, languageId, disposables);
|
||||
|
||||
editor.setSelection(new Selection(2, 1, 2, 1));
|
||||
const text = [
|
||||
'// comment',
|
||||
'const foo = 42',
|
||||
].join('\n');
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
viewModel.paste(text, true, undefined, 'keyboard');
|
||||
autoIndentOnPasteController.trigger(new Range(2, 1, 3, 15));
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function bar() {',
|
||||
' // comment',
|
||||
' const foo = 42',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Auto Indent On Type - TypeScript/JavaScript', () => {
|
||||
|
@ -774,61 +845,25 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// Failing tests...
|
||||
test('issue #43244: indent when lambda arrow function is detected, outdent when end is reached', () => {
|
||||
|
||||
test.skip('issue #40115: keep indentation when added', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/40115
|
||||
|
||||
const model = createTextModel('function foo() {}', languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
|
||||
editor.setSelection(new Selection(1, 17, 1, 17));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function foo() {',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n'));
|
||||
editor.setSelection(new Selection(2, 5, 2, 5));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function foo() {',
|
||||
' ',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test.skip('issue #193875: incorrect indentation on enter', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/193875
|
||||
// https://github.com/microsoft/vscode/issues/43244
|
||||
|
||||
const model = createTextModel([
|
||||
'{',
|
||||
' for(;;)',
|
||||
' for(;;) {}',
|
||||
'}',
|
||||
'const array = [1, 2, 3, 4, 5];',
|
||||
'array.map(_)'
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(3, 14, 3, 14));
|
||||
editor.setSelection(new Selection(2, 12, 2, 12));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'{',
|
||||
' for(;;)',
|
||||
' for(;;) {',
|
||||
' ',
|
||||
' }',
|
||||
'}',
|
||||
'const array = [1, 2, 3, 4, 5];',
|
||||
'array.map(_',
|
||||
' ',
|
||||
')'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
@ -868,6 +903,8 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
// Failing tests...
|
||||
|
||||
test.skip('issue #208232: incorrect indentation inside of comments', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/208232
|
||||
|
@ -1041,25 +1078,60 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('issue #43244: indent when lambda arrow function is detected, outdent when end is reached', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/43244
|
||||
test.skip('issue #40115: keep indentation when added', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/40115
|
||||
|
||||
const model = createTextModel('function foo() {}', languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
|
||||
editor.setSelection(new Selection(1, 17, 1, 17));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function foo() {',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n'));
|
||||
editor.setSelection(new Selection(2, 5, 2, 5));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'function foo() {',
|
||||
' ',
|
||||
' ',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
test.skip('issue #193875: incorrect indentation on enter', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/193875
|
||||
|
||||
const model = createTextModel([
|
||||
'const array = [1, 2, 3, 4, 5];',
|
||||
'array.map(_)'
|
||||
'{',
|
||||
' for(;;)',
|
||||
' for(;;) {}',
|
||||
'}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.TypeScript, disposables);
|
||||
editor.setSelection(new Selection(2, 12, 2, 12));
|
||||
editor.setSelection(new Selection(3, 14, 3, 14));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'const array = [1, 2, 3, 4, 5];',
|
||||
'array.map(_',
|
||||
' ',
|
||||
')'
|
||||
'{',
|
||||
' for(;;)',
|
||||
' for(;;) {',
|
||||
' ',
|
||||
' }',
|
||||
'}',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
@ -1110,4 +1182,157 @@ suite('Auto Indent On Type - Ruby', () => {
|
|||
assert.strictEqual(model.getValue(), " # in ");
|
||||
});
|
||||
});
|
||||
|
||||
// Failing tests...
|
||||
|
||||
test.skip('issue #199846: in or when incorrectly match non keywords for Ruby', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/199846
|
||||
// explanation: happening because the # is detected probably as a comment
|
||||
|
||||
const model = createTextModel("", languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.Ruby, disposables);
|
||||
|
||||
viewModel.type("method('#foo') do");
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
"method('#foo') do",
|
||||
" "
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Auto Indent On Type - PHP', () => {
|
||||
|
||||
const languageId = "php-test";
|
||||
let disposables: DisposableStore;
|
||||
|
||||
setup(() => {
|
||||
disposables = new DisposableStore();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
disposables.dispose();
|
||||
});
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
test('temp issue because there should be at least one passing test in a suite', () => {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
test.skip('issue #199050: should not indent after { detected in a string', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/199050
|
||||
|
||||
const model = createTextModel("$phrase = preg_replace('#(\{1|%s).*#su', '', $phrase);", languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
|
||||
registerLanguage(instantiationService, languageId, Language.PHP, disposables);
|
||||
editor.setSelection(new Selection(1, 54, 1, 54));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
"$phrase = preg_replace('#(\{1|%s).*#su', '', $phrase);",
|
||||
""
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Auto Indent On Paste - Go', () => {
|
||||
|
||||
const languageId = "go-test";
|
||||
let disposables: DisposableStore;
|
||||
|
||||
setup(() => {
|
||||
disposables = new DisposableStore();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
disposables.dispose();
|
||||
});
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
test('temp issue because there should be at least one passing test in a suite', () => {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
test.skip('issue #199050: should not indent after { detected in a string', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/199050
|
||||
|
||||
const model = createTextModel([
|
||||
'var s = `',
|
||||
'quick brown',
|
||||
'fox',
|
||||
'`',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.Go, disposables);
|
||||
editor.setSelection(new Selection(3, 1, 3, 1));
|
||||
const text = ' ';
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
viewModel.paste(text, true, undefined, 'keyboard');
|
||||
autoIndentOnPasteController.trigger(new Range(3, 1, 3, 3));
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'var s = `',
|
||||
'quick brown',
|
||||
' fox',
|
||||
'`',
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Auto Indent On Type - CPP', () => {
|
||||
|
||||
const languageId = "cpp-test";
|
||||
let disposables: DisposableStore;
|
||||
|
||||
setup(() => {
|
||||
disposables = new DisposableStore();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
disposables.dispose();
|
||||
});
|
||||
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
test('temp issue because there should be at least one passing test in a suite', () => {
|
||||
assert.ok(true);
|
||||
});
|
||||
|
||||
test.skip('issue #178334: incorrect outdent of } when signature spans multiple lines', () => {
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/178334
|
||||
|
||||
const model = createTextModel([
|
||||
'int WINAPI WinMain(bool instance,',
|
||||
' int nshowcmd) {}',
|
||||
].join('\n'), languageId, {});
|
||||
disposables.add(model);
|
||||
|
||||
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
|
||||
registerLanguage(instantiationService, languageId, Language.CPP, disposables);
|
||||
editor.setSelection(new Selection(2, 20, 2, 20));
|
||||
viewModel.type("\n", 'keyboard');
|
||||
assert.strictEqual(model.getValue(), [
|
||||
'int WINAPI WinMain(bool instance,',
|
||||
' int nshowcmd) {',
|
||||
' ',
|
||||
'}'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ import { BracketSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/bro
|
|||
import { provideSelectionRanges } from 'vs/editor/contrib/smartSelect/browser/smartSelect';
|
||||
import { WordSelectionRangeProvider } from 'vs/editor/contrib/smartSelect/browser/wordSelections';
|
||||
import { createModelServices } from 'vs/editor/test/common/testTextModel';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
|
||||
import { LanguageFeatureRegistry } from 'vs/editor/common/languageFeatureRegistry';
|
||||
import { ILanguageSelection, ILanguageService } from 'vs/editor/common/languages/language';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
|
|
|
@ -14,7 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection';
|
|||
import { ILanguageService } from 'vs/editor/common/languages/language';
|
||||
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
|
||||
import { getEditOperation, testCommand } from 'vs/editor/test/browser/testCommand';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
|
||||
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
|
||||
import { withEditorModel } from 'vs/editor/test/common/testTextModel';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
|
27
src/vs/editor/test/common/modes/supports/indentationRules.ts
Normal file
27
src/vs/editor/test/common/modes/supports/indentationRules.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export const javascriptIndentationRules = {
|
||||
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
||||
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/,
|
||||
// e.g. * ...| or */| or *-----*/|
|
||||
unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
|
||||
indentNextLinePattern: /^((.*=>\s*)|((.*[^\w]+|\s*)(if|while|for)\s*\(.*\)\s*))$/,
|
||||
};
|
||||
|
||||
export const rubyIndentationRules = {
|
||||
decreaseIndentPattern: /^\s*([}\]]([,)]?\s*(#|$)|\.[a-zA-Z_]\w*\b)|(end|rescue|ensure|else|elsif)\b|(in|when)\s)/,
|
||||
increaseIndentPattern: /^\s*((begin|class|(private|protected)\s+def|def|else|elsif|ensure|for|if|module|rescue|unless|until|when|in|while|case)|([^#]*\sdo\b)|([^#]*=\s*(case|if|unless)))\b([^#\{;]|(\"|'|\/).*\4)*(#.*)?$/,
|
||||
};
|
||||
|
||||
export const phpIndentationRules = {
|
||||
increaseIndentPattern: /({(?!.*}).*|\(|\[|((else(\s)?)?if|else|for(each)?|while|switch|case).*:)\s*((\/[/*].*|)?$|\?>)/,
|
||||
decreaseIndentPattern: /^(.*\*\/)?\s*((\})|(\)+[;,])|(\]\)*[;,])|\b(else:)|\b((end(if|for(each)?|while|switch));))/,
|
||||
};
|
||||
|
||||
export const goIndentationRules = {
|
||||
decreaseIndentPattern: /^\s*(\bcase\b.*:|\bdefault\b:|}[)}]*[),]?|\)[,]?)$/,
|
||||
increaseIndentPattern: /^.*(\bcase\b.*:|\bdefault\b:|(\b(func|if|else|switch|select|for|struct)\b.*)?{[^}"'`]*|\([^)"'`]*)$/,
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
export const javascriptIndentationRules = {
|
||||
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
||||
increaseIndentPattern: /^((?!\/\/).)*(\{([^}"'`]*|(\t|[ ])*\/\/.*)|\([^)"'`]*|\[[^\]"'`]*)$/,
|
||||
// e.g. * ...| or */| or *-----*/|
|
||||
unIndentedLinePattern: /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$|^(\t|[ ])*[ ]\*\/\s*$|^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
|
||||
indentNextLinePattern: /^((.*=>\s*)|((.*[^\w]+|\s*)(if|while|for)\s*\(.*\)\s*))$/,
|
||||
};
|
|
@ -5,7 +5,7 @@
|
|||
import * as assert from 'assert';
|
||||
import { CharacterPair, IndentAction } from 'vs/editor/common/languages/languageConfiguration';
|
||||
import { OnEnterSupport } from 'vs/editor/common/languages/supports/onEnter';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
|
||||
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/onEnterRules';
|
||||
import { EditorAutoIndentStrategy } from 'vs/editor/common/config/editorOptions';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
|
||||
|
||||
|
|
|
@ -59,3 +59,68 @@ export const javascriptOnEnterRules = [
|
|||
action: { indentAction: IndentAction.IndentOutdent, appendText: '\t' }
|
||||
},
|
||||
];
|
||||
|
||||
export const phpOnEnterRules = [
|
||||
{
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
afterText: /^\s*\*\/$/,
|
||||
action: {
|
||||
indentAction: IndentAction.IndentOutdent,
|
||||
appendText: ' * ',
|
||||
}
|
||||
},
|
||||
{
|
||||
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
|
||||
action: {
|
||||
indentAction: IndentAction.None,
|
||||
appendText: ' * ',
|
||||
}
|
||||
},
|
||||
{
|
||||
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
|
||||
action: {
|
||||
indentAction: IndentAction.None,
|
||||
appendText: '* ',
|
||||
}
|
||||
},
|
||||
{
|
||||
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
|
||||
action: {
|
||||
indentAction: IndentAction.None,
|
||||
removeText: 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
|
||||
action: {
|
||||
indentAction: IndentAction.None,
|
||||
removeText: 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
|
||||
previousLineText: /^\s*(((else ?)?if|for(each)?|while)\s*\(.*\)\s*|else\s*)$/,
|
||||
action: {
|
||||
indentAction: IndentAction.Outdent
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
export const cppOnEnterRules = [
|
||||
{
|
||||
previousLineText: /^\s*(((else ?)?if|for|while)\s*\(.*\)\s*|else\s*)$/,
|
||||
beforeText: /^\s+([^{i\s]|i(?!f\b))/,
|
||||
action: {
|
||||
indentAction: IndentAction.Outdent
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
/*
|
||||
export enum IndentAction {
|
||||
None = 0,
|
||||
Indent = 1,
|
||||
IndentOutdent = 2,
|
||||
Outdent = 3
|
||||
}
|
||||
*/
|
Loading…
Reference in a new issue