mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Fixing TS completion tests
The current method of verifying when suggestions have been shown is not reliable so switch to use a delay instead :(
This commit is contained in:
@@ -29,12 +29,14 @@ async function updateConfig(newConfig: VsCodeConfiguration): Promise<VsCodeConfi
|
||||
namespace Config {
|
||||
export const suggestSelection = 'editor.suggestSelection';
|
||||
export const completeFunctionCalls = 'typescript.suggest.completeFunctionCalls';
|
||||
export const autoClosingBrackets = 'editor.autoClosingBrackets';
|
||||
}
|
||||
|
||||
suite('TypeScript Completions', () => {
|
||||
const configDefaults: VsCodeConfiguration = Object.freeze({
|
||||
[Config.suggestSelection]: 'first',
|
||||
[Config.completeFunctionCalls]: false,
|
||||
[Config.autoClosingBrackets]: 'always',
|
||||
});
|
||||
|
||||
const _disposables: vscode.Disposable[] = [];
|
||||
@@ -165,7 +167,7 @@ suite('TypeScript Completions', () => {
|
||||
`f('abc.abc$0')`
|
||||
);
|
||||
|
||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables, { useLineRange: true });
|
||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||
assert.strictEqual(
|
||||
document.getText(),
|
||||
joinLines(
|
||||
|
||||
@@ -29,14 +29,14 @@ suite('JSDoc Completions', () => {
|
||||
`function abcdef(x, y) { }`,
|
||||
);
|
||||
|
||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables, { useLineRange: true});
|
||||
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||
assert.strictEqual(
|
||||
document.getText(),
|
||||
joinLines(
|
||||
`/**`,
|
||||
` *`,
|
||||
` * @param {*} x `,
|
||||
` * @param {*} y `,
|
||||
` * `,
|
||||
` * @param x `,
|
||||
` * @param y `,
|
||||
` */`,
|
||||
`function abcdef(x, y) { }`,
|
||||
));
|
||||
|
||||
@@ -7,23 +7,18 @@ import 'mocha';
|
||||
import * as vscode from 'vscode';
|
||||
import { wait } from './testUtils';
|
||||
|
||||
export async function acceptFirstSuggestion(uri: vscode.Uri, _disposables: vscode.Disposable[], options?: { useLineRange?: boolean }) {
|
||||
export async function acceptFirstSuggestion(uri: vscode.Uri, _disposables: vscode.Disposable[]) {
|
||||
const didChangeDocument = onChangedDocument(uri, _disposables);
|
||||
const didSuggest = onDidSuggest(_disposables, options);
|
||||
await vscode.commands.executeCommand('editor.action.triggerSuggest');
|
||||
await didSuggest;
|
||||
// TODO: depends on reverting fix for https://github.com/Microsoft/vscode/issues/64257
|
||||
// Make sure we have time to resolve the suggestion because `acceptSelectedSuggestion` doesn't
|
||||
await wait(40);
|
||||
await wait(1000); // Give time for suggestions to show
|
||||
await vscode.commands.executeCommand('acceptSelectedSuggestion');
|
||||
return await didChangeDocument;
|
||||
return didChangeDocument;
|
||||
}
|
||||
|
||||
export async function typeCommitCharacter(uri: vscode.Uri, character: string, _disposables: vscode.Disposable[]) {
|
||||
const didChangeDocument = onChangedDocument(uri, _disposables);
|
||||
const didSuggest = onDidSuggest(_disposables);
|
||||
await vscode.commands.executeCommand('editor.action.triggerSuggest');
|
||||
await didSuggest;
|
||||
await wait(1000); // Give time for suggestions to show
|
||||
await vscode.commands.executeCommand('type', { text: character });
|
||||
return await didChangeDocument;
|
||||
}
|
||||
@@ -35,29 +30,3 @@ export function onChangedDocument(documentUri: vscode.Uri, disposables: vscode.D
|
||||
}
|
||||
}, undefined, disposables));
|
||||
}
|
||||
|
||||
|
||||
function onDidSuggest(disposables: vscode.Disposable[], options?: { useLineRange?: boolean }) {
|
||||
return new Promise(resolve =>
|
||||
disposables.push(vscode.languages.registerCompletionItemProvider('typescript', new class implements vscode.CompletionItemProvider {
|
||||
provideCompletionItems(doc: vscode.TextDocument, position: vscode.Position): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
|
||||
// Return a fake item that will come first
|
||||
const range = options && options.useLineRange
|
||||
? new vscode.Range(new vscode.Position(position.line, 0), position)
|
||||
: doc.getWordRangeAtPosition(position.translate({ characterDelta: -1 }));
|
||||
return [{
|
||||
label: '🦄',
|
||||
insertText: doc.getText(range),
|
||||
filterText: doc.getText(range),
|
||||
preselect: true,
|
||||
sortText: 'a',
|
||||
range: range
|
||||
}];
|
||||
}
|
||||
async resolveCompletionItem(item: vscode.CompletionItem) {
|
||||
await vscode.commands.executeCommand('selectNextSuggestion');
|
||||
resolve();
|
||||
return item;
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user