mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-25 14:20:30 -04:00
Merge from master
This commit is contained in:
@@ -2,40 +2,38 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { ISuggestResult, ISuggestSupport, ISuggestion, SuggestionType } from 'vs/editor/common/modes';
|
||||
import { CompletionList, CompletionItemProvider, CompletionItem, CompletionItemKind } from 'vs/editor/common/modes';
|
||||
import { CompletionModel } from 'vs/editor/contrib/suggest/completionModel';
|
||||
import { ISuggestionItem, getSuggestionComparator } from 'vs/editor/contrib/suggest/suggest';
|
||||
import { ISuggestionItem, getSuggestionComparator, ensureLowerCaseVariants } from 'vs/editor/contrib/suggest/suggest';
|
||||
import { WordDistance } from 'vs/editor/contrib/suggest/wordDistance';
|
||||
|
||||
export function createSuggestItem(label: string, overwriteBefore: number, type: SuggestionType = 'property', incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }): ISuggestionItem {
|
||||
export function createSuggestItem(label: string, overwriteBefore: number, kind = CompletionItemKind.Property, incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }): ISuggestionItem {
|
||||
|
||||
return new class implements ISuggestionItem {
|
||||
|
||||
position = position;
|
||||
|
||||
suggestion: ISuggestion = {
|
||||
suggestion: CompletionItem = {
|
||||
label,
|
||||
overwriteBefore,
|
||||
range: { startLineNumber: position.lineNumber, startColumn: position.column - overwriteBefore, endLineNumber: position.lineNumber, endColumn: position.column },
|
||||
insertText: label,
|
||||
type
|
||||
kind
|
||||
};
|
||||
|
||||
container: ISuggestResult = {
|
||||
container: CompletionList = {
|
||||
incomplete,
|
||||
suggestions: [this.suggestion]
|
||||
};
|
||||
|
||||
support: ISuggestSupport = {
|
||||
support: CompletionItemProvider = {
|
||||
provideCompletionItems(): any {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
resolve(): TPromise<void> {
|
||||
resolve(): Promise<void> {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -54,7 +52,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 'foo',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
});
|
||||
|
||||
test('filtering - cached', function () {
|
||||
@@ -75,7 +73,7 @@ suite('CompletionModel', function () {
|
||||
});
|
||||
|
||||
|
||||
test('complete/incomplete', function () {
|
||||
test('complete/incomplete', () => {
|
||||
|
||||
assert.equal(model.incomplete.size, 0);
|
||||
|
||||
@@ -85,16 +83,16 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 'foo',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
assert.equal(incompleteModel.incomplete.size, 1);
|
||||
});
|
||||
|
||||
test('replaceIncomplete', function () {
|
||||
test('replaceIncomplete', () => {
|
||||
|
||||
const completeItem = createSuggestItem('foobar', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const incompleteItem = createSuggestItem('foofoo', 1, undefined, true, { lineNumber: 1, column: 2 });
|
||||
|
||||
const model = new CompletionModel([completeItem, incompleteItem], 2, { leadingLineContent: 'f', characterCountDelta: 0 });
|
||||
const model = new CompletionModel([completeItem, incompleteItem], 2, { leadingLineContent: 'f', characterCountDelta: 0 }, WordDistance.None);
|
||||
assert.equal(model.incomplete.size, 1);
|
||||
assert.equal(model.items.length, 2);
|
||||
|
||||
@@ -123,7 +121,7 @@ suite('CompletionModel', function () {
|
||||
completeItem4,
|
||||
completeItem5,
|
||||
incompleteItem1,
|
||||
], 2, { leadingLineContent: 'f', characterCountDelta: 0 }
|
||||
], 2, { leadingLineContent: 'f', characterCountDelta: 0 }, WordDistance.None
|
||||
);
|
||||
assert.equal(model.incomplete.size, 1);
|
||||
assert.equal(model.items.length, 6);
|
||||
@@ -147,7 +145,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: ' <',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
assert.equal(model.items.length, 4);
|
||||
|
||||
@@ -161,13 +159,13 @@ suite('CompletionModel', function () {
|
||||
test('keep snippet sorting with prefix: top, #25495', function () {
|
||||
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('Snippet1', 1, 'snippet'),
|
||||
createSuggestItem('tnippet2', 1, 'snippet'),
|
||||
createSuggestItem('semver', 1, 'property'),
|
||||
createSuggestItem('Snippet1', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('semver', 1, CompletionItemKind.Property),
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
}, WordDistance.None, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, shareSuggestSelections: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -180,13 +178,13 @@ suite('CompletionModel', function () {
|
||||
test('keep snippet sorting with prefix: bottom, #25495', function () {
|
||||
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('snippet1', 1, 'snippet'),
|
||||
createSuggestItem('tnippet2', 1, 'snippet'),
|
||||
createSuggestItem('Semver', 1, 'property'),
|
||||
createSuggestItem('snippet1', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('Semver', 1, CompletionItemKind.Property),
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
}, WordDistance.None, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, shareSuggestSelections: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -198,13 +196,13 @@ suite('CompletionModel', function () {
|
||||
test('keep snippet sorting with prefix: inline, #25495', function () {
|
||||
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('snippet1', 1, 'snippet'),
|
||||
createSuggestItem('tnippet2', 1, 'snippet'),
|
||||
createSuggestItem('Semver', 1, 'property'),
|
||||
createSuggestItem('snippet1', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('tnippet2', 1, CompletionItemKind.Snippet),
|
||||
createSuggestItem('Semver', 1),
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
}, WordDistance.None, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true, localityBonus: false, shareSuggestSelections: false });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -215,14 +213,14 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('filterText seems ignored in autocompletion, #26874', function () {
|
||||
|
||||
const item1 = createSuggestItem('Map - java.util', 1, 'property');
|
||||
const item1 = createSuggestItem('Map - java.util', 1);
|
||||
item1.suggestion.filterText = 'Map';
|
||||
const item2 = createSuggestItem('Map - java.util', 1, 'property');
|
||||
const item2 = createSuggestItem('Map - java.util', 1);
|
||||
|
||||
model = new CompletionModel([item1, item2], 1, {
|
||||
leadingLineContent: 'M',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
|
||||
@@ -235,20 +233,23 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('Vscode 1.12 no longer obeys \'sortText\' in completion items (from language server), #26096', function () {
|
||||
|
||||
const item1 = createSuggestItem('<- groups', 2, 'property', false, { lineNumber: 1, column: 3 });
|
||||
const item1 = createSuggestItem('<- groups', 2, CompletionItemKind.Property, false, { lineNumber: 1, column: 3 });
|
||||
item1.suggestion.filterText = ' groups';
|
||||
item1.suggestion.sortText = '00002';
|
||||
|
||||
const item2 = createSuggestItem('source', 0, 'property', false, { lineNumber: 1, column: 3 });
|
||||
const item2 = createSuggestItem('source', 0, CompletionItemKind.Property, false, { lineNumber: 1, column: 3 });
|
||||
item2.suggestion.filterText = 'source';
|
||||
item2.suggestion.sortText = '00001';
|
||||
|
||||
ensureLowerCaseVariants(item1.suggestion);
|
||||
ensureLowerCaseVariants(item2.suggestion);
|
||||
|
||||
const items = [item1, item2].sort(getSuggestionComparator('inline'));
|
||||
|
||||
model = new CompletionModel(items, 3, {
|
||||
leadingLineContent: ' ',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
|
||||
@@ -259,15 +260,15 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('Score only filtered items when typing more, score all when typing less', function () {
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('console', 0, 'property'),
|
||||
createSuggestItem('co_new', 0, 'property'),
|
||||
createSuggestItem('bar', 0, 'property'),
|
||||
createSuggestItem('car', 0, 'property'),
|
||||
createSuggestItem('foo', 0, 'property'),
|
||||
createSuggestItem('console', 0),
|
||||
createSuggestItem('co_new', 0),
|
||||
createSuggestItem('bar', 0),
|
||||
createSuggestItem('car', 0),
|
||||
createSuggestItem('foo', 0),
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
assert.equal(model.items.length, 5);
|
||||
|
||||
@@ -286,15 +287,15 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('Have more relaxed suggest matching algorithm #15419', function () {
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('result', 0, 'property'),
|
||||
createSuggestItem('replyToUser', 0, 'property'),
|
||||
createSuggestItem('randomLolut', 0, 'property'),
|
||||
createSuggestItem('car', 0, 'property'),
|
||||
createSuggestItem('foo', 0, 'property'),
|
||||
createSuggestItem('result', 0),
|
||||
createSuggestItem('replyToUser', 0),
|
||||
createSuggestItem('randomLolut', 0),
|
||||
createSuggestItem('car', 0),
|
||||
createSuggestItem('foo', 0),
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
// query gets longer, narrow down the narrow-down'ed-set from before
|
||||
model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 };
|
||||
@@ -308,15 +309,15 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('Emmet suggestion not appearing at the top of the list in jsx files, #39518', function () {
|
||||
model = new CompletionModel([
|
||||
createSuggestItem('from', 0, 'property'),
|
||||
createSuggestItem('form', 0, 'property'),
|
||||
createSuggestItem('form:get', 0, 'property'),
|
||||
createSuggestItem('testForeignMeasure', 0, 'property'),
|
||||
createSuggestItem('fooRoom', 0, 'property'),
|
||||
createSuggestItem('from', 0),
|
||||
createSuggestItem('form', 0),
|
||||
createSuggestItem('form:get', 0),
|
||||
createSuggestItem('testForeignMeasure', 0),
|
||||
createSuggestItem('fooRoom', 0),
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
}, WordDistance.None);
|
||||
|
||||
model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 };
|
||||
assert.equal(model.items.length, 5);
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { SuggestRegistry } from 'vs/editor/common/modes';
|
||||
import { CompletionProviderRegistry, CompletionItemKind } from 'vs/editor/common/modes';
|
||||
import { provideSuggestionItems } from 'vs/editor/contrib/suggest/suggest';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
@@ -21,21 +19,21 @@ suite('Suggest', function () {
|
||||
setup(function () {
|
||||
|
||||
model = TextModel.createFromString('FOO\nbar\BAR\nfoo', undefined, undefined, URI.parse('foo:bar/path'));
|
||||
registration = SuggestRegistry.register({ pattern: 'bar/path', scheme: 'foo' }, {
|
||||
registration = CompletionProviderRegistry.register({ pattern: 'bar/path', scheme: 'foo' }, {
|
||||
provideCompletionItems() {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: 'aaa',
|
||||
type: 'snippet',
|
||||
kind: CompletionItemKind.Snippet,
|
||||
insertText: 'aaa'
|
||||
}, {
|
||||
label: 'zzz',
|
||||
type: 'snippet',
|
||||
kind: CompletionItemKind.Snippet,
|
||||
insertText: 'zzz'
|
||||
}, {
|
||||
label: 'fff',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'fff'
|
||||
}]
|
||||
};
|
||||
@@ -48,38 +46,34 @@ suite('Suggest', function () {
|
||||
model.dispose();
|
||||
});
|
||||
|
||||
test('sort - snippet inline', function () {
|
||||
return provideSuggestionItems(model, new Position(1, 1), 'inline').then(items => {
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'aaa');
|
||||
assert.equal(items[1].suggestion.label, 'fff');
|
||||
assert.equal(items[2].suggestion.label, 'zzz');
|
||||
});
|
||||
test('sort - snippet inline', async function () {
|
||||
const items = await provideSuggestionItems(model, new Position(1, 1), 'inline');
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'aaa');
|
||||
assert.equal(items[1].suggestion.label, 'fff');
|
||||
assert.equal(items[2].suggestion.label, 'zzz');
|
||||
});
|
||||
|
||||
test('sort - snippet top', function () {
|
||||
return provideSuggestionItems(model, new Position(1, 1), 'top').then(items => {
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'aaa');
|
||||
assert.equal(items[1].suggestion.label, 'zzz');
|
||||
assert.equal(items[2].suggestion.label, 'fff');
|
||||
});
|
||||
test('sort - snippet top', async function () {
|
||||
const items = await provideSuggestionItems(model, new Position(1, 1), 'top');
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'aaa');
|
||||
assert.equal(items[1].suggestion.label, 'zzz');
|
||||
assert.equal(items[2].suggestion.label, 'fff');
|
||||
});
|
||||
|
||||
test('sort - snippet bottom', function () {
|
||||
return provideSuggestionItems(model, new Position(1, 1), 'bottom').then(items => {
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'fff');
|
||||
assert.equal(items[1].suggestion.label, 'aaa');
|
||||
assert.equal(items[2].suggestion.label, 'zzz');
|
||||
});
|
||||
test('sort - snippet bottom', async function () {
|
||||
const items = await provideSuggestionItems(model, new Position(1, 1), 'bottom');
|
||||
assert.equal(items.length, 3);
|
||||
assert.equal(items[0].suggestion.label, 'fff');
|
||||
assert.equal(items[1].suggestion.label, 'aaa');
|
||||
assert.equal(items[2].suggestion.label, 'zzz');
|
||||
});
|
||||
|
||||
test('sort - snippet none', function () {
|
||||
return provideSuggestionItems(model, new Position(1, 1), 'none').then(items => {
|
||||
assert.equal(items.length, 1);
|
||||
assert.equal(items[0].suggestion.label, 'fff');
|
||||
});
|
||||
test('sort - snippet none', async function () {
|
||||
const items = await provideSuggestionItems(model, new Position(1, 1), 'none');
|
||||
assert.equal(items.length, 1);
|
||||
assert.equal(items[0].suggestion.label, 'fff');
|
||||
});
|
||||
|
||||
test('only from', function () {
|
||||
@@ -98,7 +92,7 @@ suite('Suggest', function () {
|
||||
};
|
||||
}
|
||||
};
|
||||
const registration = SuggestRegistry.register({ pattern: 'bar/path', scheme: 'foo' }, foo);
|
||||
const registration = CompletionProviderRegistry.register({ pattern: 'bar/path', scheme: 'foo' }, foo);
|
||||
|
||||
provideSuggestionItems(model, new Position(1, 1), undefined, [foo]).then(items => {
|
||||
registration.dispose();
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { LRUMemory, NoMemory, PrefixMemory, Memory } from 'vs/editor/contrib/suggest/suggestMemory';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
@@ -68,7 +66,7 @@ suite('SuggestMemories', function () {
|
||||
assert.equal(new PrefixMemory().select(buffer, pos, items), 1);
|
||||
});
|
||||
|
||||
test('NoMemory', function () {
|
||||
test('NoMemory', () => {
|
||||
|
||||
const mem = new NoMemory();
|
||||
|
||||
@@ -79,7 +77,7 @@ suite('SuggestMemories', function () {
|
||||
mem.memorize(buffer, pos, null);
|
||||
});
|
||||
|
||||
test('LRUMemory', function () {
|
||||
test('LRUMemory', () => {
|
||||
|
||||
pos = { lineNumber: 2, column: 6 };
|
||||
|
||||
@@ -116,7 +114,7 @@ suite('SuggestMemories', function () {
|
||||
assert.equal(mem.select(buffer, { lineNumber: 3, column: 6 }, items), 1); // foo: ,|
|
||||
});
|
||||
|
||||
test('PrefixMemory', function () {
|
||||
test('PrefixMemory', () => {
|
||||
|
||||
const mem = new PrefixMemory();
|
||||
buffer.setValue('constructor');
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
@@ -15,7 +13,7 @@ import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { TokenizationResult2 } from 'vs/editor/common/core/token';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { IState, ISuggestResult, ISuggestSupport, LanguageIdentifier, MetadataConsts, SuggestRegistry, SuggestTriggerKind, TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { IState, CompletionList, CompletionItemProvider, LanguageIdentifier, MetadataConsts, CompletionProviderRegistry, CompletionTriggerKind, TokenizationRegistry, CompletionItemKind } from 'vs/editor/common/modes';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
|
||||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
@@ -25,16 +23,26 @@ import { ISelectedSuggestion } from 'vs/editor/contrib/suggest/suggestWidget';
|
||||
import { TestCodeEditor, createTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { IStorageService, NullStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IStorageService, InMemoryStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
|
||||
|
||||
export interface Ctor<T> {
|
||||
new(): T;
|
||||
}
|
||||
|
||||
export function mock<T>(): Ctor<T> {
|
||||
return function () { } as any;
|
||||
}
|
||||
|
||||
|
||||
function createMockEditor(model: TextModel): TestCodeEditor {
|
||||
let editor = createTestCodeEditor({
|
||||
model: model,
|
||||
serviceCollection: new ServiceCollection(
|
||||
[ITelemetryService, NullTelemetryService],
|
||||
[IStorageService, NullStorageService]
|
||||
[IStorageService, new InMemoryStorageService()]
|
||||
),
|
||||
});
|
||||
editor.registerAndInstantiateContribution(SnippetController2);
|
||||
@@ -55,7 +63,7 @@ suite('SuggestModel - Context', function () {
|
||||
tokenize: undefined,
|
||||
tokenize2: (line: string, state: IState): TokenizationResult2 => {
|
||||
const tokensArr: number[] = [];
|
||||
let prevLanguageId: LanguageIdentifier = undefined;
|
||||
let prevLanguageId: LanguageIdentifier | undefined = undefined;
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const languageId = (line.charAt(i) === 'x' ? INNER_LANGUAGE_ID : OUTER_LANGUAGE_ID);
|
||||
if (prevLanguageId !== languageId) {
|
||||
@@ -132,8 +140,8 @@ suite('SuggestModel - Context', function () {
|
||||
suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
|
||||
const alwaysEmptySupport: ISuggestSupport = {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
const alwaysEmptySupport: CompletionItemProvider = {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: []
|
||||
@@ -141,13 +149,13 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
}
|
||||
};
|
||||
|
||||
const alwaysSomethingSupport: ISuggestSupport = {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
const alwaysSomethingSupport: CompletionItemProvider = {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: doc.getWordUntilPosition(pos).word,
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foofoo'
|
||||
}]
|
||||
};
|
||||
@@ -167,7 +175,12 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const editor = createMockEditor(model);
|
||||
const oracle = new SuggestModel(editor);
|
||||
const oracle = new SuggestModel(editor, new class extends mock<IEditorWorkerService>() {
|
||||
computeWordRanges() {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
});
|
||||
disposables.push(oracle, editor);
|
||||
|
||||
try {
|
||||
@@ -243,7 +256,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('events - suggest/empty', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysEmptySupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysEmptySupport));
|
||||
|
||||
return withOracle(model => {
|
||||
return Promise.all([
|
||||
@@ -265,7 +278,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('trigger - on type', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
return withOracle((model, editor) => {
|
||||
return assertEvent(model.onDidSuggest, () => {
|
||||
@@ -284,13 +297,13 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('#17400: Keep filtering suggestModel.ts after space', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: 'My Table',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'My Table'
|
||||
}]
|
||||
};
|
||||
@@ -333,30 +346,33 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('#21484: Trigger character always force a new completion session', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: 'foo.bar',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foo.bar',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}]
|
||||
};
|
||||
}
|
||||
}));
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
triggerCharacters: ['.'],
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{
|
||||
label: 'boom',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'boom',
|
||||
overwriteBefore: doc.getLineContent(pos.lineNumber)[pos.column - 2] === '.' ? 0 : pos.column - 1
|
||||
range: Range.fromPositions(
|
||||
pos.delta(0, doc.getLineContent(pos.lineNumber)[pos.column - 2] === '.' ? 0 : -1),
|
||||
pos
|
||||
)
|
||||
}]
|
||||
};
|
||||
}
|
||||
@@ -392,7 +408,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Intellisense Completion doesn\'t respect space after equal sign (.html file), #29353 [1/2]', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
return withOracle((model, editor) => {
|
||||
|
||||
@@ -417,7 +433,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Intellisense Completion doesn\'t respect space after equal sign (.html file), #29353 [2/2]', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
return withOracle((model, editor) => {
|
||||
|
||||
@@ -442,15 +458,15 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Incomplete suggestion results cause re-triggering when typing w/o further context, #28400 (1/2)', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{
|
||||
label: 'foo',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foo',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}]
|
||||
};
|
||||
}
|
||||
@@ -479,15 +495,15 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Incomplete suggestion results cause re-triggering when typing w/o further context, #28400 (2/2)', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{
|
||||
label: 'foo;',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foo',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}]
|
||||
};
|
||||
}
|
||||
@@ -522,19 +538,19 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Trigger character is provided in suggest context', function () {
|
||||
let triggerCharacter = '';
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
triggerCharacters: ['.'],
|
||||
provideCompletionItems(doc, pos, context): ISuggestResult {
|
||||
assert.equal(context.triggerKind, SuggestTriggerKind.TriggerCharacter);
|
||||
provideCompletionItems(doc, pos, context): CompletionList {
|
||||
assert.equal(context.triggerKind, CompletionTriggerKind.TriggerCharacter);
|
||||
triggerCharacter = context.triggerCharacter;
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [
|
||||
{
|
||||
label: 'foo.bar',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'foo.bar',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -555,20 +571,20 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
});
|
||||
|
||||
test('Mac press and hold accent character insertion does not update suggestions, #35269', function () {
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{
|
||||
label: 'abc',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'abc',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}, {
|
||||
label: 'äbc',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'äbc',
|
||||
overwriteBefore: pos.column - 1
|
||||
range: Range.fromPositions(pos.with(undefined, 1), pos)
|
||||
}]
|
||||
};
|
||||
}
|
||||
@@ -598,7 +614,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
});
|
||||
|
||||
test('Backspace should not always cancel code completion, #36491', function () {
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
return withOracle(async (model, editor) => {
|
||||
await assertEvent(model.onDidSuggest, () => {
|
||||
@@ -627,15 +643,15 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
});
|
||||
|
||||
test('Text changes for completion CodeAction are affected by the completion #39893', function () {
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): ISuggestResult {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos): CompletionList {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{
|
||||
label: 'bar',
|
||||
type: 'property',
|
||||
kind: CompletionItemKind.Property,
|
||||
insertText: 'bar',
|
||||
overwriteBefore: 2,
|
||||
range: Range.fromPositions(pos.delta(0, -2), pos),
|
||||
additionalTextEdits: [{
|
||||
text: ', bar',
|
||||
range: { startLineNumber: 1, endLineNumber: 1, startColumn: 17, endColumn: 17 }
|
||||
@@ -650,7 +666,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
return withOracle(async (sugget, editor) => {
|
||||
class TestCtrl extends SuggestController {
|
||||
_onDidSelectItem(item: ISelectedSuggestion) {
|
||||
super._onDidSelectItem(item);
|
||||
super._onDidSelectItem(item, false, true);
|
||||
}
|
||||
}
|
||||
const ctrl = <TestCtrl>editor.registerAndInstantiateContribution(TestCtrl);
|
||||
@@ -677,7 +693,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
test('Completion unexpectedly triggers on second keypress of an edit group in a snippet #43523', function () {
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
return withOracle((model, editor) => {
|
||||
return assertEvent(model.onDidSuggest, () => {
|
||||
@@ -701,20 +717,20 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
let disposeA = 0;
|
||||
let disposeB = 0;
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{ type: 'folder', label: 'CompleteNot', insertText: 'Incomplete', sortText: 'a', overwriteBefore: pos.column - 1 }],
|
||||
suggestions: [{ kind: CompletionItemKind.Folder, label: 'CompleteNot', insertText: 'Incomplete', sortText: 'a', overwriteBefore: pos.column - 1 }],
|
||||
dispose() { disposeA += 1; }
|
||||
};
|
||||
}
|
||||
}));
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
disposables.push(CompletionProviderRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{ type: 'folder', label: 'Complete', insertText: 'Complete', sortText: 'z', overwriteBefore: pos.column - 1 }],
|
||||
suggestions: [{ kind: CompletionItemKind.Folder, label: 'Complete', insertText: 'Complete', sortText: 'z', overwriteBefore: pos.column - 1 }],
|
||||
dispose() { disposeB += 1; }
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user