From 7221f92ee2db8ad84581a033279d8ad7faddd273 Mon Sep 17 00:00:00 2001 From: Matthew Kwiecien Date: Sat, 9 Feb 2019 12:59:16 -0600 Subject: [PATCH 1/4] Get syntax from arguments and document editor language when wrapping. --- extensions/emmet/src/abbreviationActions.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index 4ee8e221f99c1..f332aff2e000e 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -54,7 +54,11 @@ function doWrapping(individualLines: boolean, args: any) { return; } } - const syntax = 'html'; + args = args || {}; + if (!args['language']) { + args['language'] = editor.document.languageId; + } + const syntax = getSyntaxFromArgs(args) || 'html'; const rootNode = parseDocument(editor.document, false); let inPreview = false; From 0b3c33b801672d55724c4eb8f15ecc78d4024089 Mon Sep 17 00:00:00 2001 From: Matthew Kwiecien Date: Sun, 10 Feb 2019 10:09:56 -0600 Subject: [PATCH 2/4] Adding unit tests to check for className when file is jsx. --- .../src/test/wrapWithAbbreviation.test.ts | 380 ++++++++++-------- 1 file changed, 210 insertions(+), 170 deletions(-) diff --git a/extensions/emmet/src/test/wrapWithAbbreviation.test.ts b/extensions/emmet/src/test/wrapWithAbbreviation.test.ts index 9fc924508e244..fa15a67875141 100644 --- a/extensions/emmet/src/test/wrapWithAbbreviation.test.ts +++ b/extensions/emmet/src/test/wrapWithAbbreviation.test.ts @@ -63,6 +63,22 @@ const wrapInlineElementExpectedFormatFalse = ` `; +const wrapMultiLineJsxExpected = ` + +`; + +const wrapIndividualLinesJsxExpected = ` + +`; + suite('Tests for Wrap with Abbreviations', () => { teardown(closeAllEditors); @@ -135,219 +151,219 @@ suite('Tests for Wrap with Abbreviations', () => { `; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(2, 0, 2, 0)]; - const promise = wrapWithAbbreviation({ abbreviation: 'li.hello|c' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); + return withRandomFileEditor(contents, 'html', (editor, _) => { + editor.selections = [new Selection(2, 0, 2, 0)]; + const promise = wrapWithAbbreviation({ abbreviation: 'li.hello|c' }); + if (!promise) { + assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); + return Promise.resolve(); + } + return promise.then(() => { + assert.equal(editor.document.getText(), expectedContents); + return Promise.resolve(); }); }); +}); - test('Wrap with abbreviation entire node when cursor is on opening tag', () => { - const contents = ` +test('Wrap with abbreviation entire node when cursor is on opening tag', () => { + const contents = ` + +`; + const expectedContents = ` +
- `; - const expectedContents = ` -
- -
- `; +
+`; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(1, 1, 1, 1)]; - const promise = wrapWithAbbreviation({ abbreviation: 'div' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); + return withRandomFileEditor(contents, 'html', (editor, _) => { + editor.selections = [new Selection(1, 1, 1, 1)]; + const promise = wrapWithAbbreviation({ abbreviation: 'div' }); + if (!promise) { + assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); + return Promise.resolve(); + } + return promise.then(() => { + assert.equal(editor.document.getText(), expectedContents); + return Promise.resolve(); }); }); +}); - test('Wrap with abbreviation entire node when cursor is on closing tag', () => { - const contents = ` +test('Wrap with abbreviation entire node when cursor is on closing tag', () => { + const contents = ` + +`; + const expectedContents = ` +
- `; - const expectedContents = ` -
- -
- `; +
+`; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(3, 1, 3, 1)]; - const promise = wrapWithAbbreviation({ abbreviation: 'div' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); + return withRandomFileEditor(contents, 'html', (editor, _) => { + editor.selections = [new Selection(3, 1, 3, 1)]; + const promise = wrapWithAbbreviation({ abbreviation: 'div' }); + if (!promise) { + assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); + return Promise.resolve(); + } + return promise.then(() => { + assert.equal(editor.document.getText(), expectedContents); + return Promise.resolve(); }); }); +}); - test('Wrap with multiline abbreviation doesnt add extra spaces', () => { - // Issue #29898 - const contents = ` - hello - `; - const expectedContents = ` - - `; +test('Wrap with multiline abbreviation doesnt add extra spaces', () => { + // Issue #29898 + const contents = ` +hello +`; + const expectedContents = ` + +`; - return withRandomFileEditor(contents, 'html', (editor, _) => { - editor.selections = [new Selection(1, 2, 1, 2)]; - const promise = wrapWithAbbreviation({ abbreviation: 'ul>li>a' }); - if (!promise) { - assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); - return Promise.resolve(); - } - return promise.then(() => { - assert.equal(editor.document.getText(), expectedContents); - return Promise.resolve(); - }); + return withRandomFileEditor(contents, 'html', (editor, _) => { + editor.selections = [new Selection(1, 2, 1, 2)]; + const promise = wrapWithAbbreviation({ abbreviation: 'ul>li>a' }); + if (!promise) { + assert.equal(1, 2, 'Wrap returned undefined instead of promise.'); + return Promise.resolve(); + } + return promise.then(() => { + assert.equal(editor.document.getText(), expectedContents); + return Promise.resolve(); }); }); +}); - test('Wrap individual lines with abbreviation', () => { - const contents = ` - +test('Wrap individual lines with abbreviation', () => { + const contents = ` + `; - const wrapIndividualLinesExpected = ` -