提交 e6b61067 编写于 作者: R Ramya Achutha Rao

Validate surrounding text before providing emmet completions in jsx/xml Fixes #47612

上级 0940ea62
......@@ -37,7 +37,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
let rootNode: Stylesheet | undefined = undefined;
if (context.triggerKind !== vscode.CompletionTriggerKind.TriggerForIncompleteCompletions) {
validateLocation = syntax === 'html' || isStyleSheet(document.languageId);
validateLocation = syntax === 'html' || syntax === 'jsx' || syntax === 'xml' || isStyleSheet(document.languageId);
// If document can be css parsed, get currentNode
if (isStyleSheet(document.languageId)) {
let usePartialParsing = vscode.workspace.getConfiguration('emmet')['optimizeStylesheetParsing'] === true;
......
......@@ -336,6 +336,46 @@ suite('Tests for jsx, xml and xsl', () => {
});
});
test('No expanding text inside open tag in completion list (jsx)', () => {
return withRandomFileEditor(htmlContents, 'jsx', (editor, doc) => {
editor.selection = new Selection(2, 4, 2, 4);
const cancelSrc = new CancellationTokenSource();
const completionPromise = completionProvider.provideCompletionItems(editor.document, editor.selection.active, cancelSrc.token, { triggerKind: CompletionTriggerKind.Invoke });
assert.equal(!completionPromise, true, `Got unexpected comapletion promise instead of undefined`);
return Promise.resolve();
});
});
test('No expanding tag that is opened, but not closed in completion list (jsx)', () => {
return withRandomFileEditor(htmlContents, 'jsx', (editor, doc) => {
editor.selection = new Selection(9, 6, 9, 6);
const cancelSrc = new CancellationTokenSource();
const completionPromise = completionProvider.provideCompletionItems(editor.document, editor.selection.active, cancelSrc.token, { triggerKind: CompletionTriggerKind.Invoke });
assert.equal(!completionPromise, true, `Got unexpected comapletion promise instead of undefined`);
return Promise.resolve();
});
});
test('No expanding text inside open tag when there is no closing tag in completion list (jsx)', () => {
return withRandomFileEditor(htmlContents, 'jsx', (editor, doc) => {
editor.selection = new Selection(9, 8, 9, 8);
const cancelSrc = new CancellationTokenSource();
const completionPromise = completionProvider.provideCompletionItems(editor.document, editor.selection.active, cancelSrc.token, { triggerKind: CompletionTriggerKind.Invoke });
assert.equal(!completionPromise, true, `Got unexpected comapletion promise instead of undefined`);
return Promise.resolve();
});
});
test('No expanding text in completion list inside open tag when there is no closing tag when there is no parent node (jsx)', () => {
const fileContents = '<img s';
return withRandomFileEditor(fileContents, 'jsx', (editor, doc) => {
editor.selection = new Selection(0, 6, 0, 6);
const cancelSrc = new CancellationTokenSource();
const completionPromise = completionProvider.provideCompletionItems(editor.document, editor.selection.active, cancelSrc.token, { triggerKind: CompletionTriggerKind.Invoke });
assert.equal(!completionPromise, true, `Got unexpected comapletion promise instead of undefined`);
return Promise.resolve();
});
});
});
function testExpandAbbreviation(syntax: string, selection: Selection, abbreviation: string, expandedText: string, shouldFail?: boolean): Thenable<any> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册