mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Add pinning test for bracket completions
This commit is contained in:
@@ -18,27 +18,37 @@ suite('TypeScript Completions', () => {
|
|||||||
return vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
return vscode.commands.executeCommand('workbench.action.closeAllEditors');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should insert backets when completing dot properties with spaces in name', async () => {
|
||||||
|
await wait(100);
|
||||||
|
|
||||||
|
await createTestEditor(testDocumentUri,
|
||||||
|
'const x = { "hello world": 1 };',
|
||||||
|
'x.$0'
|
||||||
|
);
|
||||||
|
|
||||||
|
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||||
|
assert.strictEqual(
|
||||||
|
document.getText(),
|
||||||
|
joinLines(
|
||||||
|
'const x = { "hello world": 1 };',
|
||||||
|
'x["hello world"]'
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
test('Should not prioritize bracket accessor completions. #63100', async () => {
|
test('Should not prioritize bracket accessor completions. #63100', async () => {
|
||||||
await wait(100);
|
await wait(100);
|
||||||
|
|
||||||
// 'a' should be first entry in completion list
|
// 'a' should be first entry in completion list
|
||||||
await createTestEditor(joinLines(
|
await createTestEditor(testDocumentUri,
|
||||||
'const x = { "z-z": 1, a: 1 };',
|
'const x = { "z-z": 1, a: 1 };',
|
||||||
'x.'
|
'x.$0'
|
||||||
));
|
);
|
||||||
|
|
||||||
const didChangeDocument = onChangedDocument(testDocumentUri, _disposables);
|
const document = await acceptFirstSuggestion(testDocumentUri, _disposables);
|
||||||
const didSuggest = onDidSuggest(_disposables);
|
|
||||||
|
|
||||||
await vscode.commands.executeCommand('editor.action.triggerSuggest');
|
|
||||||
await didSuggest;
|
|
||||||
await vscode.commands.executeCommand('acceptSelectedSuggestion');
|
|
||||||
|
|
||||||
const document = await didChangeDocument;
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
document.getText(),
|
document.getText(),
|
||||||
joinLines(
|
joinLines(
|
||||||
'const x = { "a": 1, "z-z": 2 };',
|
'const x = { "z-z": 1, a: 1 };',
|
||||||
'x.a'
|
'x.a'
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
@@ -48,6 +58,15 @@ const joinLines = (...args: string[]) => args.join('\n');
|
|||||||
|
|
||||||
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
async function acceptFirstSuggestion(uri: vscode.Uri, _disposables: vscode.Disposable[]) {
|
||||||
|
const didChangeDocument = onChangedDocument(uri, _disposables);
|
||||||
|
const didSuggest = onDidSuggest(_disposables);
|
||||||
|
await vscode.commands.executeCommand('editor.action.triggerSuggest');
|
||||||
|
await didSuggest;
|
||||||
|
await vscode.commands.executeCommand('acceptSelectedSuggestion');
|
||||||
|
return await didChangeDocument;
|
||||||
|
}
|
||||||
|
|
||||||
function onChangedDocument(documentUri: vscode.Uri, disposables: vscode.Disposable[]) {
|
function onChangedDocument(documentUri: vscode.Uri, disposables: vscode.Disposable[]) {
|
||||||
return new Promise<vscode.TextDocument>(resolve => vscode.workspace.onDidChangeTextDocument(e => {
|
return new Promise<vscode.TextDocument>(resolve => vscode.workspace.onDidChangeTextDocument(e => {
|
||||||
if (e.document.uri.toString() === documentUri.toString()) {
|
if (e.document.uri.toString() === documentUri.toString()) {
|
||||||
@@ -56,15 +75,15 @@ function onChangedDocument(documentUri: vscode.Uri, disposables: vscode.Disposab
|
|||||||
}, undefined, disposables));
|
}, undefined, disposables));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createTestEditor(contents: string) {
|
async function createTestEditor(uri: vscode.Uri, ...lines: string[]) {
|
||||||
const document = await vscode.workspace.openTextDocument(testDocumentUri);
|
const document = await vscode.workspace.openTextDocument(uri);
|
||||||
await vscode.window.showTextDocument(document);
|
await vscode.window.showTextDocument(document);
|
||||||
const activeEditor = vscode.window.activeTextEditor;
|
const activeEditor = vscode.window.activeTextEditor;
|
||||||
if (!activeEditor) {
|
if (!activeEditor) {
|
||||||
throw new Error('no active editor');
|
throw new Error('no active editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
await activeEditor.insertSnippet(new vscode.SnippetString(contents));
|
await activeEditor.insertSnippet(new vscode.SnippetString(joinLines(...lines)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDidSuggest(disposables: vscode.Disposable[]) {
|
function onDidSuggest(disposables: vscode.Disposable[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user