Revert "Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d (#5949)" (#5983)

This reverts commit d15a3fcc98.
This commit is contained in:
Karl Burtram
2019-06-11 12:35:58 -07:00
committed by GitHub
parent 95a50b7892
commit 5a7562a37b
926 changed files with 11394 additions and 19540 deletions

View File

@@ -3,34 +3,22 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
import { TextModel } from 'vs/editor/common/model/textModel';
import * as modes from 'vs/editor/common/modes';
import { CodeAction, CodeActionContext, CodeActionProvider, CodeActionProviderRegistry, Command, LanguageIdentifier, ResourceTextEdit, WorkspaceEdit } from 'vs/editor/common/modes';
import { getCodeActions } from 'vs/editor/contrib/codeAction/codeAction';
import { CodeActionKind } from 'vs/editor/contrib/codeAction/codeActionTrigger';
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { CancellationToken } from 'vs/base/common/cancellation';
function staticCodeActionProvider(...actions: modes.CodeAction[]): modes.CodeActionProvider {
return new class implements modes.CodeActionProvider {
provideCodeActions(): modes.CodeActionList {
return {
actions: actions,
dispose: () => { }
};
}
};
}
suite('CodeAction', () => {
let langId = new modes.LanguageIdentifier('fooLang', 17);
let langId = new LanguageIdentifier('fooLang', 17);
let uri = URI.parse('untitled:path');
let model: TextModel;
const disposables = new DisposableStore();
let disposables: IDisposable[] = [];
let testData = {
diagnostics: {
abc: {
@@ -58,7 +46,7 @@ suite('CodeAction', () => {
},
command: {
abc: {
command: new class implements modes.Command {
command: new class implements Command {
id: '1';
title: 'abc';
},
@@ -68,8 +56,8 @@ suite('CodeAction', () => {
spelling: {
bcd: {
diagnostics: <IMarkerData[]>[],
edit: new class implements modes.WorkspaceEdit {
edits: modes.ResourceTextEdit[];
edit: new class implements WorkspaceEdit {
edits: ResourceTextEdit[];
},
title: 'abc'
}
@@ -91,27 +79,30 @@ suite('CodeAction', () => {
};
setup(function () {
disposables.clear();
model = TextModel.createFromString('test1\ntest2\ntest3', undefined, langId, uri);
disposables.add(model);
disposables = [model];
});
teardown(function () {
disposables.clear();
dispose(disposables);
});
test('CodeActions are sorted by type, #38623', async function () {
const provider = staticCodeActionProvider(
testData.command.abc,
testData.diagnostics.bcd,
testData.spelling.bcd,
testData.tsLint.bcd,
testData.tsLint.abc,
testData.diagnostics.abc
);
const provider = new class implements CodeActionProvider {
provideCodeActions() {
return [
testData.command.abc,
testData.diagnostics.bcd,
testData.spelling.bcd,
testData.tsLint.bcd,
testData.tsLint.abc,
testData.diagnostics.abc
];
}
};
disposables.add(modes.CodeActionProviderRegistry.register('fooLang', provider));
disposables.push(CodeActionProviderRegistry.register('fooLang', provider));
const expected = [
// CodeActions with a diagnostics array are shown first ordered by diagnostics.message
@@ -131,13 +122,17 @@ suite('CodeAction', () => {
});
test('getCodeActions should filter by scope', async function () {
const provider = staticCodeActionProvider(
{ title: 'a', kind: 'a' },
{ title: 'b', kind: 'b' },
{ title: 'a.b', kind: 'a.b' }
);
const provider = new class implements CodeActionProvider {
provideCodeActions(): CodeAction[] {
return [
{ title: 'a', kind: 'a' },
{ title: 'b', kind: 'b' },
{ title: 'a.b', kind: 'a.b' }
];
}
};
disposables.add(modes.CodeActionProviderRegistry.register('fooLang', provider));
disposables.push(CodeActionProviderRegistry.register('fooLang', provider));
{
const { actions } = await getCodeActions(model, new Range(1, 1, 2, 1), { type: 'auto', filter: { kind: new CodeActionKind('a') } }, CancellationToken.None);
@@ -159,18 +154,15 @@ suite('CodeAction', () => {
});
test('getCodeActions should forward requested scope to providers', async function () {
const provider = new class implements modes.CodeActionProvider {
provideCodeActions(_model: any, _range: Range, context: modes.CodeActionContext, _token: any): modes.CodeActionList {
return {
actions: [
{ title: context.only || '', kind: context.only }
],
dispose: () => { }
};
const provider = new class implements CodeActionProvider {
provideCodeActions(_model: any, _range: Range, context: CodeActionContext, _token: any): CodeAction[] {
return [
{ title: context.only || '', kind: context.only }
];
}
};
disposables.add(modes.CodeActionProviderRegistry.register('fooLang', provider));
disposables.push(CodeActionProviderRegistry.register('fooLang', provider));
const { actions } = await getCodeActions(model, new Range(1, 1, 2, 1), { type: 'auto', filter: { kind: new CodeActionKind('a') } }, CancellationToken.None);
assert.equal(actions.length, 1);
@@ -178,12 +170,16 @@ suite('CodeAction', () => {
});
test('getCodeActions should not return source code action by default', async function () {
const provider = staticCodeActionProvider(
{ title: 'a', kind: CodeActionKind.Source.value },
{ title: 'b', kind: 'b' }
);
const provider = new class implements CodeActionProvider {
provideCodeActions(): CodeAction[] {
return [
{ title: 'a', kind: CodeActionKind.Source.value },
{ title: 'b', kind: 'b' }
];
}
};
disposables.add(modes.CodeActionProviderRegistry.register('fooLang', provider));
disposables.push(CodeActionProviderRegistry.register('fooLang', provider));
{
const { actions } = await getCodeActions(model, new Range(1, 1, 2, 1), { type: 'auto' }, CancellationToken.None);
@@ -200,16 +196,16 @@ suite('CodeAction', () => {
test('getCodeActions should not invoke code action providers filtered out by providedCodeActionKinds', async function () {
let wasInvoked = false;
const provider = new class implements modes.CodeActionProvider {
provideCodeActions(): modes.CodeActionList {
const provider = new class implements CodeActionProvider {
provideCodeActions() {
wasInvoked = true;
return { actions: [], dispose: () => { } };
return [];
}
providedCodeActionKinds = [CodeActionKind.Refactor.value];
};
disposables.add(modes.CodeActionProviderRegistry.register('fooLang', provider));
disposables.push(CodeActionProviderRegistry.register('fooLang', provider));
const { actions } = await getCodeActions(model, new Range(1, 1, 2, 1), {
type: 'auto',