Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d (#5949)

* Merge from vscode 81d7885dc2e9dc617e1522697a2966bc4025a45d

* Fix vs unit tests and hygiene issue

* Fix strict null check issue
This commit is contained in:
Chris LaFreniere
2019-06-10 18:27:09 -07:00
committed by GitHub
parent ff38bc8143
commit d15a3fcc98
926 changed files with 19529 additions and 11383 deletions

View File

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