Using service collection in the test file (#215962)

using service collection in the tests
This commit is contained in:
Aiday Marlen Kyzy 2024-06-17 16:59:13 +02:00 committed by GitHub
parent 1fd1f389d2
commit b8d1155b90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 204 additions and 129 deletions

View file

@ -23,6 +23,9 @@ import { cppOnEnterRules, htmlOnEnterRules, javascriptOnEnterRules, phpOnEnterRu
import { TypeOperations } from 'vs/editor/common/cursor/cursorTypeOperations';
import { cppBracketRules, goBracketRules, htmlBracketRules, latexBracketRules, luaBracketRules, phpBracketRules, rubyBracketRules, typescriptBracketRules, vbBracketRules } from 'vs/editor/test/common/modes/supports/bracketRules';
import { latexAutoClosingPairsRules } from 'vs/editor/test/common/modes/supports/autoClosingPairsRules';
import { LanguageService } from 'vs/editor/common/services/languageService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
export enum Language {
TypeScript = 'ts-test',
@ -44,16 +47,11 @@ function testIndentationToTabsCommand(lines: string[], selection: Selection, tab
testCommand(lines, null, selection, (accessor, sel) => new IndentationToTabsCommand(sel, tabSize), expectedLines, expectedSelection);
}
export function registerLanguage(instantiationService: TestInstantiationService, language: Language): IDisposable {
const disposables = new DisposableStore();
const languageService = instantiationService.get(ILanguageService);
disposables.add(registerLanguageConfiguration(instantiationService, language));
disposables.add(languageService.registerLanguage({ id: language }));
return disposables;
export function registerLanguage(languageService: ILanguageService, language: Language): IDisposable {
return languageService.registerLanguage({ id: language });
}
export function registerLanguageConfiguration(instantiationService: TestInstantiationService, language: Language): IDisposable {
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
export function registerLanguageConfiguration(languageConfigurationService: ILanguageConfigurationService, language: Language): IDisposable {
switch (language) {
case Language.TypeScript:
return languageConfigurationService.register(language, {
@ -317,9 +315,20 @@ suite('Indent With Tab - TypeScript/JavaScript', () => {
const languageId = Language.TypeScript;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -343,9 +352,7 @@ suite('Indent With Tab - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(1, 1, 3, 5));
editor.executeCommands('editor.action.indentLines', TypeOperations.indent(viewModel.cursorConfig, editor.getModel(), editor.getSelections()));
assert.strictEqual(model.getValue(), [
@ -369,9 +376,7 @@ suite('Indent With Tab - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(1, 1, 5, 2));
editor.executeCommands('editor.action.indentLines', TypeOperations.indent(viewModel.cursorConfig, editor.getModel(), editor.getSelections()));
assert.strictEqual(model.getValue(), [
@ -389,9 +394,20 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const languageId = Language.TypeScript;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -405,7 +421,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
const pasteText = [
'/**',
' * JSDoc',
@ -439,7 +455,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
{ startIndex: 15, standardTokenType: StandardTokenType.Other },
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(pasteText, true, undefined, 'keyboard');
@ -453,7 +468,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
// no need for tokenization because there are no comments
const pasteText = [
@ -470,7 +485,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
'}'
].join('\n');
disposables.add(registerLanguage(instantiationService, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(pasteText, true, undefined, 'keyboard');
autoIndentOnPasteController.trigger(new Range(1, 1, 11, 2));
@ -488,8 +502,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(2, 6, 2, 6));
const text = ', null';
viewModel.paste(text, true, undefined, 'keyboard');
@ -516,8 +529,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(5, 24, 5, 34));
const text = 'IMacLinuxKeyMapping';
viewModel.paste(text, true, undefined, 'keyboard');
@ -541,8 +553,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel('', languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
const text = [
'/*----------------',
' * Copyright (c) ',
@ -569,7 +580,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel(initialText, languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
@ -582,7 +593,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
{ startIndex: 0, standardTokenType: StandardTokenType.String },
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
editor.setSelection(new Selection(2, 10, 2, 15));
@ -602,7 +612,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
const text = [
'/**',
' * @typedef {',
@ -634,7 +644,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
{ startIndex: 3, standardTokenType: StandardTokenType.Other },
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(text, true, undefined, 'keyboard');
@ -654,7 +663,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(2, 1, 2, 1));
const text = [
'() => {',
@ -662,7 +671,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
'}',
''
].join('\n');
disposables.add(registerLanguage(instantiationService, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(text, true, undefined, 'keyboard');
autoIndentOnPasteController.trigger(new Range(2, 1, 5, 1));
@ -696,7 +704,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(2, 5, 2, 5));
const text = [
'() => {',
@ -704,7 +712,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
'}',
' '
].join('\n');
disposables.add(registerLanguage(instantiationService, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(text, true, undefined, 'keyboard');
// todo@aiday-mar, make sure range is correct, and make test work as in real life
@ -727,7 +734,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
const model = createTextModel('', languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(2, 5, 2, 5));
const text = [
'function makeSub(a,b) {',
@ -735,7 +742,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
'return subsent;',
'}',
].join('\n');
disposables.add(registerLanguage(instantiationService, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(text, true, undefined, 'keyboard');
// todo@aiday-mar, make sure range is correct, and make test work as in real life
@ -760,7 +766,7 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: 'full', serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
@ -791,7 +797,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
{ startIndex: 1, standardTokenType: StandardTokenType.Other }]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
editor.setSelection(new Selection(2, 1, 2, 1));
@ -799,7 +804,6 @@ suite('Auto Indent On Paste - TypeScript/JavaScript', () => {
'// comment',
'const foo = 42',
].join('\n');
disposables.add(registerLanguage(instantiationService, languageId));
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
viewModel.paste(text, true, undefined, 'keyboard');
autoIndentOnPasteController.trigger(new Range(2, 1, 3, 15));
@ -817,9 +821,20 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
const languageId = Language.TypeScript;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -837,8 +852,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
viewModel.type('const add1 = (n) =>');
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -859,8 +873,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(3, 9, 3, 9));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -879,10 +892,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
viewModel.type([
'const add1 = (n) =>',
' n + 1;',
@ -908,9 +918,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(3, 1, 3, 1));
viewModel.type('\n', 'keyboard');
assert.strictEqual(model.getValue(), [
@ -939,8 +947,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: 'advanced', serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(7, 6, 7, 6));
viewModel.type('\n', 'keyboard');
assert.strictEqual(model.getValue(),
@ -970,8 +977,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: 'advanced' }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: 'advanced', serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(1, 4, 1, 4));
viewModel.type('\n', 'keyboard');
assert.strictEqual(model.getValue(),
@ -996,8 +1002,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 12, 2, 12));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1020,9 +1025,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 19, 2, 19));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1055,9 +1058,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[{ startIndex: 0, standardTokenType: StandardTokenType.Comment }],
[{ startIndex: 0, standardTokenType: StandardTokenType.Comment }],
@ -1090,8 +1091,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(1, 14, 1, 14));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1114,8 +1114,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 7, 2, 7));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1138,8 +1137,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 7, 2, 7));
viewModel.type("\n", 'keyboard');
viewModel.type(".");
@ -1163,8 +1161,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 24, 2, 24));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1189,8 +1186,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(3, 5, 3, 5));
viewModel.type(".");
assert.strictEqual(model.getValue(), [
@ -1213,8 +1209,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 25, 2, 25));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1233,10 +1228,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
const model = createTextModel('function foo() {}', languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(1, 17, 1, 17));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1267,9 +1259,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(3, 14, 3, 14));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1295,9 +1285,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(4, 1, 4, 1));
viewModel.type("}", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1319,16 +1307,13 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 5, 2, 5));
viewModel.type("{}", 'keyboard');
assert.strictEqual(model.getValue(), [
'if (true)',
'{}',
].join('\n'));
editor.setSelection(new Selection(2, 2, 2, 2));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1350,8 +1335,7 @@ suite('Auto Indent On Type - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "keep" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "keep", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 5, 2, 5));
viewModel.type("}", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1366,9 +1350,20 @@ suite('Auto Indent On Type - Ruby', () => {
const languageId = Language.Ruby;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1384,10 +1379,7 @@ suite('Auto Indent On Type - Ruby', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
viewModel.type("def foo\n i");
viewModel.type("n", 'keyboard');
assert.strictEqual(model.getValue(), "def foo\n in");
@ -1412,10 +1404,7 @@ suite('Auto Indent On Type - Ruby', () => {
const model = createTextModel("", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
viewModel.type("method('#foo') do");
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1430,9 +1419,20 @@ suite('Auto Indent On Type - PHP', () => {
const languageId = Language.PHP;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1448,9 +1448,7 @@ suite('Auto Indent On Type - PHP', () => {
const model = createTextModel("preg_replace('{');", languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
@ -1473,9 +1471,20 @@ suite('Auto Indent On Paste - Go', () => {
const languageId = Language.Go;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1500,8 +1509,7 @@ suite('Auto Indent On Paste - Go', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(3, 1, 3, 1));
const text = ' ';
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
@ -1521,9 +1529,20 @@ suite('Auto Indent On Type - CPP', () => {
const languageId = Language.CPP;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1546,8 +1565,7 @@ suite('Auto Indent On Type - CPP', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 20, 2, 20));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1569,8 +1587,7 @@ suite('Auto Indent On Type - CPP', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(1, 20, 1, 20));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1591,9 +1608,7 @@ suite('Auto Indent On Type - CPP', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "none" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "none", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 3, 2, 3));
viewModel.type("}", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1609,9 +1624,20 @@ suite('Auto Indent On Type - HTML', () => {
const languageId = Language.HTML;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1635,8 +1661,7 @@ suite('Auto Indent On Type - HTML', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 48, 2, 48));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1653,9 +1678,20 @@ suite('Auto Indent On Type - Visual Basic', () => {
const languageId = Language.VB;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1679,8 +1715,7 @@ suite('Auto Indent On Type - Visual Basic', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
editor.setSelection(new Selection(3, 10, 3, 10));
viewModel.type("f", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1697,9 +1732,20 @@ suite('Auto Indent On Type - Latex', () => {
const languageId = Language.Latex;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1722,8 +1768,7 @@ suite('Auto Indent On Type - Latex', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(2, 9, 2, 9));
viewModel.type("{", 'keyboard');
assert.strictEqual(model.getValue(), [
@ -1738,9 +1783,20 @@ suite('Auto Indent On Type - Lua', () => {
const languageId = Language.Lua;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -1762,8 +1818,7 @@ suite('Auto Indent On Type - Lua', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
disposables.add(registerLanguage(instantiationService, languageId));
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel) => {
editor.setSelection(new Selection(1, 28, 1, 28));
viewModel.type("\n", 'keyboard');
assert.strictEqual(model.getValue(), [

View file

@ -8,18 +8,33 @@ import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/uti
import { StandardTokenType } from 'vs/editor/common/encodedTokenAttributes';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { IndentationContextProcessor, ProcessedIndentRulesSupport } from 'vs/editor/common/languages/supports/indentationLineProcessor';
import { Language, registerLanguage, registerTokenizationSupport, StandardTokenTypeData } from 'vs/editor/contrib/indentation/test/browser/indentation.test';
import { Language, registerLanguage, registerLanguageConfiguration, registerTokenizationSupport, StandardTokenTypeData } from 'vs/editor/contrib/indentation/test/browser/indentation.test';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
import { createTextModel } from 'vs/editor/test/common/testTextModel';
import { Range } from 'vs/editor/common/core/range';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { LanguageService } from 'vs/editor/common/services/languageService';
import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService';
import { ILanguageService } from 'vs/editor/common/languages/language';
suite('Indentation Context Processor - TypeScript/JavaScript', () => {
const languageId = Language.TypeScript;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -35,13 +50,12 @@ suite('Indentation Context Processor - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
{ startIndex: 16, standardTokenType: StandardTokenType.String },
{ startIndex: 28, standardTokenType: StandardTokenType.String }
]];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationContextProcessor = new IndentationContextProcessor(model, languageConfigurationService);
@ -60,7 +74,7 @@ suite('Indentation Context Processor - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
@ -72,7 +86,6 @@ suite('Indentation Context Processor - TypeScript/JavaScript', () => {
{ startIndex: 46, standardTokenType: StandardTokenType.Other },
{ startIndex: 47, standardTokenType: StandardTokenType.String }
]];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationContextProcessor = new IndentationContextProcessor(model, languageConfigurationService);
@ -91,7 +104,7 @@ suite('Indentation Context Processor - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other },
@ -104,7 +117,6 @@ suite('Indentation Context Processor - TypeScript/JavaScript', () => {
{ startIndex: 44, standardTokenType: StandardTokenType.Other },
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationContextProcessor = new IndentationContextProcessor(model, languageConfigurationService);
@ -120,9 +132,20 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
const languageId = Language.TypeScript;
let disposables: DisposableStore;
let serviceCollection: ServiceCollection;
setup(() => {
disposables = new DisposableStore();
const languageService = new LanguageService();
const languageConfigurationService = new TestLanguageConfigurationService();
disposables.add(languageService);
disposables.add(languageConfigurationService);
disposables.add(registerLanguage(languageService, languageId));
disposables.add(registerLanguageConfiguration(languageConfigurationService, languageId));
serviceCollection = new ServiceCollection(
[ILanguageService, languageService],
[ILanguageConfigurationService, languageConfigurationService]
);
});
teardown(() => {
@ -140,7 +163,7 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other }
@ -154,7 +177,6 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
{ startIndex: 17, standardTokenType: StandardTokenType.Comment },
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;
@ -177,13 +199,12 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[{ startIndex: 0, standardTokenType: StandardTokenType.Other }],
[{ startIndex: 0, standardTokenType: StandardTokenType.String }],
[{ startIndex: 0, standardTokenType: StandardTokenType.Comment }]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;
@ -206,7 +227,7 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
].join('\n'), languageId, {});
disposables.add(model);
withTestCodeEditor(model, { autoIndent: "full" }, (editor, viewModel, instantiationService) => {
withTestCodeEditor(model, { autoIndent: "full", serviceCollection }, (editor, viewModel, instantiationService) => {
const tokens: StandardTokenTypeData[][] = [
[
{ startIndex: 0, standardTokenType: StandardTokenType.Other }
@ -220,7 +241,6 @@ suite('Processed Indent Rules Support - TypeScript/JavaScript', () => {
{ startIndex: 18, standardTokenType: StandardTokenType.RegEx }
]
];
disposables.add(registerLanguage(instantiationService, languageId));
disposables.add(registerTokenizationSupport(instantiationService, tokens, languageId));
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
const indentationRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;