From 5769bebb3c4ad190ccc65ae9c04bf0ecbe24262e Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 29 Aug 2017 18:50:04 -0700 Subject: [PATCH] Enable the use of comment filter in emmet --- extensions/emmet/npm-shrinkwrap.json | 6 ++-- extensions/emmet/package.json | 2 +- extensions/emmet/src/abbreviationActions.ts | 28 +++++++++---------- .../emmet/src/test/abbreviationAction.test.ts | 13 +-------- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/extensions/emmet/npm-shrinkwrap.json b/extensions/emmet/npm-shrinkwrap.json index 9c9d4fc3dfe..ccd35725a77 100644 --- a/extensions/emmet/npm-shrinkwrap.json +++ b/extensions/emmet/npm-shrinkwrap.json @@ -38,9 +38,9 @@ "resolved": "https://registry.npmjs.org/image-size/-/image-size-0.5.5.tgz" }, "vscode-emmet-helper": { - "version": "1.1.0", - "from": "vscode-emmet-helper@>=1.1.0 <2.0.0", - "resolved": "https://registry.npmjs.org/vscode-emmet-helper/-/vscode-emmet-helper-1.1.0.tgz" + "version": "1.1.1", + "from": "vscode-emmet-helper@>=1.1.1 <2.0.0", + "resolved": "https://registry.npmjs.org/vscode-emmet-helper/-/vscode-emmet-helper-1.1.1.tgz" }, "vscode-languageserver-types": { "version": "3.3.0", diff --git a/extensions/emmet/package.json b/extensions/emmet/package.json index 7a6cbbbca3c..068c18879a1 100644 --- a/extensions/emmet/package.json +++ b/extensions/emmet/package.json @@ -259,7 +259,7 @@ "@emmetio/html-matcher": "^0.3.1", "@emmetio/css-parser": "ramya-rao-a/css-parser#vscode", "@emmetio/math-expression": "^0.1.1", - "vscode-emmet-helper": "^1.1.0", + "vscode-emmet-helper": "^1.1.1", "vscode-languageserver-types": "^3.0.3", "image-size": "^0.5.2", "vscode-nls": "2.0.2" diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index e54f932744f..016140b256c 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -15,7 +15,7 @@ interface ExpandAbbreviationInput { abbreviation: string; rangeToReplace: vscode.Range; textToWrap?: string[]; - filters?: string[]; + filter?: string; } export function wrapWithAbbreviation(args) { @@ -73,13 +73,13 @@ export function wrapIndividualLinesWithAbbreviation(args) { return; } - let { abbreviation, filters } = extractedResults; + let { abbreviation, filter } = extractedResults; let input: ExpandAbbreviationInput = { syntax, abbreviation, rangeToReplace: editor.selection, textToWrap: lines, - filters + filter }; return expandAbbreviationInRange(editor, [input], true); @@ -106,15 +106,15 @@ export function expandEmmetAbbreviation(args): Thenable { let firstAbbreviation: string; let allAbbreviationsSame: boolean = true; - let getAbbreviation = (document: vscode.TextDocument, selection: vscode.Selection, position: vscode.Position, syntax: string): [vscode.Range, string, string[]] => { + let getAbbreviation = (document: vscode.TextDocument, selection: vscode.Selection, position: vscode.Position, syntax: string): [vscode.Range, string, string] => { let rangeToReplace: vscode.Range = selection; let abbr = document.getText(rangeToReplace); if (!rangeToReplace.isEmpty) { let extractedResults = extractAbbreviationFromText(abbr); if (extractedResults) { - return [rangeToReplace, extractedResults.abbreviation, extractedResults.filters]; + return [rangeToReplace, extractedResults.abbreviation, extractedResults.filter]; } - return [null, '', []]; + return [null, '', '']; } const currentLine = editor.document.lineAt(position.line).text; @@ -127,21 +127,21 @@ export function expandEmmetAbbreviation(args): Thenable { if (matches) { abbr = matches[1]; rangeToReplace = new vscode.Range(position.translate(0, -(abbr.length + 1)), position); - return [rangeToReplace, abbr, []]; + return [rangeToReplace, abbr, '']; } } let extractedResults = extractAbbreviation(editor.document, position, false); if (!extractedResults) { - return [null, '', []]; + return [null, '', '']; } - let { abbreviationRange, abbreviation, filters } = extractedResults; - return [new vscode.Range(abbreviationRange.start.line, abbreviationRange.start.character, abbreviationRange.end.line, abbreviationRange.end.character), abbreviation, filters]; + let { abbreviationRange, abbreviation, filter } = extractedResults; + return [new vscode.Range(abbreviationRange.start.line, abbreviationRange.start.character, abbreviationRange.end.line, abbreviationRange.end.character), abbreviation, filter]; }; editor.selections.forEach(selection => { let position = selection.isReversed ? selection.anchor : selection.active; - let [rangeToReplace, abbreviation, filters] = getAbbreviation(editor.document, selection, position, syntax); + let [rangeToReplace, abbreviation, filter] = getAbbreviation(editor.document, selection, position, syntax); if (!rangeToReplace) { return; } @@ -160,7 +160,7 @@ export function expandEmmetAbbreviation(args): Thenable { allAbbreviationsSame = false; } - abbreviationList.push({ syntax, abbreviation, rangeToReplace, filters }); + abbreviationList.push({ syntax, abbreviation, rangeToReplace, filter }); }); return expandAbbreviationInRange(editor, abbreviationList, allAbbreviationsSame).then(success => { @@ -272,11 +272,11 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex */ function expandAbbr(input: ExpandAbbreviationInput): string { const emmetConfig = vscode.workspace.getConfiguration('emmet'); - const expandOptions = getExpandOptions(input.syntax, emmetConfig, input.filters); + const expandOptions = getExpandOptions(input.syntax, emmetConfig, input.filter); if (input.textToWrap) { - if (input.filters && input.filters.indexOf('t') > -1) { + if (input.filter && input.filter.indexOf('t') > -1) { input.textToWrap = input.textToWrap.map(line => { return line.replace(trimRegex, '').trim(); }); diff --git a/extensions/emmet/src/test/abbreviationAction.test.ts b/extensions/emmet/src/test/abbreviationAction.test.ts index f3e0aec1456..64060a5970e 100644 --- a/extensions/emmet/src/test/abbreviationAction.test.ts +++ b/extensions/emmet/src/test/abbreviationAction.test.ts @@ -40,12 +40,6 @@ const scssContents = ` } ` -const bemFilterExample = 'ul.search-form._wide>li.-querystring+li.-btn_large|bem'; -const expectedBemFilterOutput = `
    -
  • -
  • -
`; - const htmlContents = `