From 4c55c7264ff66fcd15faecfd1c52016a337efa9e Mon Sep 17 00:00:00 2001 From: Raymond Zhao Date: Mon, 23 Nov 2020 09:02:15 -0800 Subject: [PATCH] Revert "Fix #58600, Format Emmet package.json (#110891)" This reverts commit ffacef4727ef6896823b895d5684f7e9e3df27fb. --- extensions/emmet/package.json | 891 +++++++++--------- extensions/emmet/package.nls.json | 1 - extensions/emmet/src/emmetCommon.ts | 6 +- .../browser/actions/expandAbbreviation.ts | 43 + .../emmet/browser/emmet.contribution.ts | 4 +- ...ndEmmetAbbreviation.ts => emmetActions.ts} | 64 +- ...breviation.test.ts => emmetAction.test.ts} | 52 +- 7 files changed, 544 insertions(+), 517 deletions(-) create mode 100644 src/vs/workbench/contrib/emmet/browser/actions/expandAbbreviation.ts rename src/vs/workbench/contrib/emmet/browser/{expandEmmetAbbreviation.ts => emmetActions.ts} (69%) rename src/vs/workbench/contrib/emmet/test/browser/{expandEmmetAbbreviation.test.ts => emmetAction.test.ts} (57%) diff --git a/extensions/emmet/package.json b/extensions/emmet/package.json index a0a22505f85..12178fa8b56 100644 --- a/extensions/emmet/package.json +++ b/extensions/emmet/package.json @@ -1,461 +1,446 @@ { - "name": "emmet", - "displayName": "Emmet", - "description": "%description%", - "version": "1.0.0", - "publisher": "vscode", - "license": "MIT", - "engines": { - "vscode": "^1.13.0" - }, - "icon": "images/icon.png", - "categories": [ - "Other" - ], - "repository": { - "type": "git", - "url": "https://github.com/microsoft/vscode-emmet" - }, - "activationEvents": [ - "*", - "onCommand:emmet.expandAbbreviation", - "onLanguage:html", - "onLanguage:css", - "onLanguage:scss", - "onLanguage:less" - ], - "main": "./out/node/emmetNodeMain", - "browser": "./dist/browser/emmetBrowserMain", - "contributes": { - "configuration": { - "type": "object", - "title": "Emmet", - "properties": { - "emmet.showExpandedAbbreviation": { - "type": [ - "string" - ], - "enum": [ - "never", - "always", - "inMarkupAndStylesheetFilesOnly" - ], - "default": "always", - "markdownDescription": "%emmetShowExpandedAbbreviation%" - }, - "emmet.showAbbreviationSuggestions": { - "type": "boolean", - "default": true, - "markdownDescription": "%emmetShowAbbreviationSuggestions%" - }, - "emmet.includeLanguages": { - "type": "object", - "additionalProperties": { - "type": "string" - }, - "default": {}, - "markdownDescription": "%emmetIncludeLanguages%" - }, - "emmet.variables": { - "type": "object", - "properties": { - "lang": { - "type": "string", - "default": "en" - }, - "charset": { - "type": "string", - "default": "UTF-8" - } - }, - "default": {}, - "description": "%emmetVariables%" - }, - "emmet.syntaxProfiles": { - "type": "object", - "default": {}, - "description": "%emmetSyntaxProfiles%" - }, - "emmet.excludeLanguages": { - "type": "array", - "default": [ - "markdown" - ], - "description": "%emmetExclude%" - }, - "emmet.extensionsPath": { - "type": [ - "string", - "null" - ], - "default": null, - "description": "%emmetExtensionsPath%" - }, - "emmet.triggerExpansionOnTab": { - "type": "boolean", - "default": false, - "description": "%emmetTriggerExpansionOnTab%" - }, - "emmet.preferences": { - "type": "object", - "default": {}, - "description": "%emmetPreferences%", - "properties": { - "css.intUnit": { - "type": "string", - "default": "px", - "description": "%emmetPreferencesIntUnit%" - }, - "css.floatUnit": { - "type": "string", - "default": "em", - "description": "%emmetPreferencesFloatUnit%" - }, - "css.propertyEnd": { - "type": "string", - "default": ";", - "description": "%emmetPreferencesCssAfter%" - }, - "sass.propertyEnd": { - "type": "string", - "default": "", - "description": "%emmetPreferencesSassAfter%" - }, - "stylus.propertyEnd": { - "type": "string", - "default": "", - "description": "%emmetPreferencesStylusAfter%" - }, - "css.valueSeparator": { - "type": "string", - "default": ": ", - "description": "%emmetPreferencesCssBetween%" - }, - "sass.valueSeparator": { - "type": "string", - "default": ": ", - "description": "%emmetPreferencesSassBetween%" - }, - "stylus.valueSeparator": { - "type": "string", - "default": " ", - "description": "%emmetPreferencesStylusBetween%" - }, - "bem.elementSeparator": { - "type": "string", - "default": "__", - "description": "%emmetPreferencesBemElementSeparator%" - }, - "bem.modifierSeparator": { - "type": "string", - "default": "_", - "description": "%emmetPreferencesBemModifierSeparator%" - }, - "filter.commentBefore": { - "type": "string", - "default": "", - "description": "%emmetPreferencesFilterCommentBefore%" - }, - "filter.commentAfter": { - "type": "string", - "default": "\n", - "description": "%emmetPreferencesFilterCommentAfter%" - }, - "filter.commentTrigger": { - "type": "array", - "default": [ - "id", - "class" - ], - "description": "%emmetPreferencesFilterCommentTrigger%" - }, - "format.noIndentTags": { - "type": "array", - "default": [ - "html" - ], - "description": "%emmetPreferencesFormatNoIndentTags%" - }, - "format.forceIndentationForTags": { - "type": "array", - "default": [ - "body" - ], - "description": "%emmetPreferencesFormatForceIndentTags%" - }, - "profile.allowCompactBoolean": { - "type": "boolean", - "default": false, - "description": "%emmetPreferencesAllowCompactBoolean%" - }, - "css.webkitProperties": { - "type": "string", - "default": null, - "markdownDescription": "%emmetPreferencesCssWebkitProperties%" - }, - "css.mozProperties": { - "type": "string", - "default": null, - "markdownDescription": "%emmetPreferencesCssMozProperties%" - }, - "css.oProperties": { - "type": "string", - "default": null, - "markdownDescription": "%emmetPreferencesCssOProperties%" - }, - "css.msProperties": { - "type": "string", - "default": null, - "markdownDescription": "%emmetPreferencesCssMsProperties%" - }, - "css.fuzzySearchMinScore": { - "type": "number", - "default": 0.3, - "description": "%emmetPreferencesCssFuzzySearchMinScore%" - } - } - }, - "emmet.showSuggestionsAsSnippets": { - "type": "boolean", - "default": false, - "markdownDescription": "%emmetShowSuggestionsAsSnippets%" - }, - "emmet.optimizeStylesheetParsing": { - "type": "boolean", - "default": true, - "markdownDescription": "%emmetOptimizeStylesheetParsing%" - } - } + "name": "emmet", + "displayName": "Emmet", + "description": "%description%", + "version": "1.0.0", + "publisher": "vscode", + "license": "MIT", + "engines": { + "vscode": "^1.13.0" }, - "commands": [ - { - "command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation", - "title": "%command.wrapIndividualLinesWithAbbreviation%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.wrapWithAbbreviation", - "title": "%command.wrapWithAbbreviation%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.expandAbbreviation", - "title": "%command.expandAbbreviation%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.removeTag", - "title": "%command.removeTag%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.updateTag", - "title": "%command.updateTag%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.matchTag", - "title": "%command.matchTag%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.balanceIn", - "title": "%command.balanceIn%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.balanceOut", - "title": "%command.balanceOut%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.prevEditPoint", - "title": "%command.prevEditPoint%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.nextEditPoint", - "title": "%command.nextEditPoint%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.mergeLines", - "title": "%command.mergeLines%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.selectPrevItem", - "title": "%command.selectPrevItem%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.selectNextItem", - "title": "%command.selectNextItem%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.splitJoinTag", - "title": "%command.splitJoinTag%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.toggleComment", - "title": "%command.toggleComment%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.evaluateMathExpression", - "title": "%command.evaluateMathExpression%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.updateImageSize", - "title": "%command.updateImageSize%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.incrementNumberByOneTenth", - "title": "%command.incrementNumberByOneTenth%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.incrementNumberByOne", - "title": "%command.incrementNumberByOne%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.incrementNumberByTen", - "title": "%command.incrementNumberByTen%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.decrementNumberByOneTenth", - "title": "%command.decrementNumberByOneTenth%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.decrementNumberByOne", - "title": "%command.decrementNumberByOne%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.decrementNumberByTen", - "title": "%command.decrementNumberByTen%", - "category": "Emmet" - }, - { - "command": "editor.emmet.action.reflectCSSValue", - "title": "%command.reflectCSSValue%", - "category": "Emmet" - }, - { - "command": "workbench.action.showEmmetCommands", - "title": "%command.showEmmetCommands%", - "category": "" - } + "icon": "images/icon.png", + "categories": [ + "Other" ], - "keybindings": [ - { - "key": "tab", - "command": "editor.emmet.action.expandAbbreviation", - "when": "config.emmet.triggerExpansionOnTab && editorTextFocus && !editorReadonly && !editorTabMovesFocus" - } + "repository": { + "type": "git", + "url": "https://github.com/microsoft/vscode-emmet" + }, + "activationEvents": [ + "*", + "onCommand:emmet.expandAbbreviation", + "onLanguage:html", + "onLanguage:css", + "onLanguage:scss", + "onLanguage:less" ], - "menus": { - "commandPalette": [ - { - "command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation" + "main": "./out/node/emmetNodeMain", + "browser": "./dist/browser/emmetBrowserMain", + "contributes": { + "configuration": { + "type": "object", + "title": "Emmet", + "properties": { + "emmet.showExpandedAbbreviation": { + "type": [ + "string" + ], + "enum": [ + "never", + "always", + "inMarkupAndStylesheetFilesOnly" + ], + "default": "always", + "markdownDescription": "%emmetShowExpandedAbbreviation%" + }, + "emmet.showAbbreviationSuggestions": { + "type": "boolean", + "default": true, + "markdownDescription": "%emmetShowAbbreviationSuggestions%" + }, + "emmet.includeLanguages": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "default": {}, + "markdownDescription": "%emmetIncludeLanguages%" + }, + "emmet.variables": { + "type": "object", + "properties": { + "lang": { + "type": "string", + "default": "en" + }, + "charset": { + "type": "string", + "default": "UTF-8" + } + }, + "default": {}, + "description": "%emmetVariables%" + }, + "emmet.syntaxProfiles": { + "type": "object", + "default": {}, + "description": "%emmetSyntaxProfiles%" + }, + "emmet.excludeLanguages": { + "type": "array", + "default": [ + "markdown" + ], + "description": "%emmetExclude%" + }, + "emmet.extensionsPath": { + "type": [ + "string", + "null" + ], + "default": null, + "description": "%emmetExtensionsPath%" + }, + "emmet.triggerExpansionOnTab": { + "type": "boolean", + "default": false, + "description": "%emmetTriggerExpansionOnTab%" + }, + "emmet.preferences": { + "type": "object", + "default": {}, + "description": "%emmetPreferences%", + "properties": { + "css.intUnit": { + "type": "string", + "default": "px", + "description": "%emmetPreferencesIntUnit%" + }, + "css.floatUnit": { + "type": "string", + "default": "em", + "description": "%emmetPreferencesFloatUnit%" + }, + "css.propertyEnd": { + "type": "string", + "default": ";", + "description": "%emmetPreferencesCssAfter%" + }, + "sass.propertyEnd": { + "type": "string", + "default": "", + "description": "%emmetPreferencesSassAfter%" + }, + "stylus.propertyEnd": { + "type": "string", + "default": "", + "description": "%emmetPreferencesStylusAfter%" + }, + "css.valueSeparator": { + "type": "string", + "default": ": ", + "description": "%emmetPreferencesCssBetween%" + }, + "sass.valueSeparator": { + "type": "string", + "default": ": ", + "description": "%emmetPreferencesSassBetween%" + }, + "stylus.valueSeparator": { + "type": "string", + "default": " ", + "description": "%emmetPreferencesStylusBetween%" + }, + "bem.elementSeparator": { + "type": "string", + "default": "__", + "description": "%emmetPreferencesBemElementSeparator%" + }, + "bem.modifierSeparator": { + "type": "string", + "default": "_", + "description": "%emmetPreferencesBemModifierSeparator%" + }, + "filter.commentBefore": { + "type": "string", + "default": "", + "description": "%emmetPreferencesFilterCommentBefore%" + }, + "filter.commentAfter": { + "type": "string", + "default": "\n", + "description": "%emmetPreferencesFilterCommentAfter%" + }, + "filter.commentTrigger": { + "type": "array", + "default": [ + "id", + "class" + ], + "description": "%emmetPreferencesFilterCommentTrigger%" + }, + "format.noIndentTags": { + "type": "array", + "default": [ + "html" + ], + "description": "%emmetPreferencesFormatNoIndentTags%" + }, + "format.forceIndentationForTags": { + "type": "array", + "default": [ + "body" + ], + "description": "%emmetPreferencesFormatForceIndentTags%" + }, + "profile.allowCompactBoolean": { + "type": "boolean", + "default": false, + "description": "%emmetPreferencesAllowCompactBoolean%" + }, + "css.webkitProperties": { + "type": "string", + "default": null, + "markdownDescription": "%emmetPreferencesCssWebkitProperties%" + }, + "css.mozProperties": { + "type": "string", + "default": null, + "markdownDescription": "%emmetPreferencesCssMozProperties%" + }, + "css.oProperties": { + "type": "string", + "default": null, + "markdownDescription": "%emmetPreferencesCssOProperties%" + }, + "css.msProperties": { + "type": "string", + "default": null, + "markdownDescription": "%emmetPreferencesCssMsProperties%" + }, + "css.fuzzySearchMinScore": { + "type": "number", + "default": 0.3, + "description": "%emmetPreferencesCssFuzzySearchMinScore%" + } + } + }, + "emmet.showSuggestionsAsSnippets": { + "type": "boolean", + "default": false, + "markdownDescription": "%emmetShowSuggestionsAsSnippets%" + }, + "emmet.optimizeStylesheetParsing": { + "type": "boolean", + "default": true, + "markdownDescription": "%emmetOptimizeStylesheetParsing%" + } + } }, - { - "command": "editor.emmet.action.wrapWithAbbreviation" - }, - { - "command": "editor.emmet.action.expandAbbreviation" - }, - { - "command": "editor.emmet.action.removeTag" - }, - { - "command": "editor.emmet.action.updateTag" - }, - { - "command": "editor.emmet.action.matchTag" - }, - { - "command": "editor.emmet.action.balanceIn" - }, - { - "command": "editor.emmet.action.balanceOut" - }, - { - "command": "editor.emmet.action.prevEditPoint" - }, - { - "command": "editor.emmet.action.nextEditPoint" - }, - { - "command": "editor.emmet.action.mergeLines" - }, - { - "command": "editor.emmet.action.selectPrevItem" - }, - { - "command": "editor.emmet.action.selectNextItem" - }, - { - "command": "editor.emmet.action.splitJoinTag" - }, - { - "command": "editor.emmet.action.toggleComment" - }, - { - "command": "editor.emmet.action.evaluateMathExpression" - }, - { - "command": "editor.emmet.action.updateImageSize", - "when": "resourceScheme =~ /^file$/" - }, - { - "command": "editor.emmet.action.incrementNumberByOneTenth" - }, - { - "command": "editor.emmet.action.incrementNumberByOne" - }, - { - "command": "editor.emmet.action.incrementNumberByTen" - }, - { - "command": "editor.emmet.action.decrementNumberByOneTenth" - }, - { - "command": "editor.emmet.action.decrementNumberByOne" - }, - { - "command": "editor.emmet.action.decrementNumberByTen" - }, - { - "command": "editor.emmet.action.reflectCSSValue" + "commands": [ + { + "command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation", + "title": "%command.wrapIndividualLinesWithAbbreviation%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.wrapWithAbbreviation", + "title": "%command.wrapWithAbbreviation%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.removeTag", + "title": "%command.removeTag%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.updateTag", + "title": "%command.updateTag%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.matchTag", + "title": "%command.matchTag%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.balanceIn", + "title": "%command.balanceIn%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.balanceOut", + "title": "%command.balanceOut%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.prevEditPoint", + "title": "%command.prevEditPoint%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.nextEditPoint", + "title": "%command.nextEditPoint%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.mergeLines", + "title": "%command.mergeLines%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.selectPrevItem", + "title": "%command.selectPrevItem%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.selectNextItem", + "title": "%command.selectNextItem%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.splitJoinTag", + "title": "%command.splitJoinTag%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.toggleComment", + "title": "%command.toggleComment%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.evaluateMathExpression", + "title": "%command.evaluateMathExpression%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.updateImageSize", + "title": "%command.updateImageSize%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.incrementNumberByOneTenth", + "title": "%command.incrementNumberByOneTenth%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.incrementNumberByOne", + "title": "%command.incrementNumberByOne%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.incrementNumberByTen", + "title": "%command.incrementNumberByTen%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.decrementNumberByOneTenth", + "title": "%command.decrementNumberByOneTenth%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.decrementNumberByOne", + "title": "%command.decrementNumberByOne%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.decrementNumberByTen", + "title": "%command.decrementNumberByTen%", + "category": "Emmet" + }, + { + "command": "editor.emmet.action.reflectCSSValue", + "title": "%command.reflectCSSValue%", + "category": "Emmet" + }, + { + "command": "workbench.action.showEmmetCommands", + "title": "%command.showEmmetCommands%", + "category": "" + } + ], + "menus": { + "commandPalette": [ + { + "command": "editor.emmet.action.wrapIndividualLinesWithAbbreviation" + }, + { + "command": "editor.emmet.action.wrapWithAbbreviation" + }, + { + "command": "editor.emmet.action.removeTag" + }, + { + "command": "editor.emmet.action.updateTag" + }, + { + "command": "editor.emmet.action.matchTag" + }, + { + "command": "editor.emmet.action.balanceIn" + }, + { + "command": "editor.emmet.action.balanceOut" + }, + { + "command": "editor.emmet.action.prevEditPoint" + }, + { + "command": "editor.emmet.action.nextEditPoint" + }, + { + "command": "editor.emmet.action.mergeLines" + }, + { + "command": "editor.emmet.action.selectPrevItem" + }, + { + "command": "editor.emmet.action.selectNextItem" + }, + { + "command": "editor.emmet.action.splitJoinTag" + }, + { + "command": "editor.emmet.action.toggleComment" + }, + { + "command": "editor.emmet.action.evaluateMathExpression" + }, + { + "command": "editor.emmet.action.updateImageSize", + "when": "resourceScheme =~ /^file$/" + }, + { + "command": "editor.emmet.action.incrementNumberByOneTenth" + }, + { + "command": "editor.emmet.action.incrementNumberByOne" + }, + { + "command": "editor.emmet.action.incrementNumberByTen" + }, + { + "command": "editor.emmet.action.decrementNumberByOneTenth" + }, + { + "command": "editor.emmet.action.decrementNumberByOne" + }, + { + "command": "editor.emmet.action.decrementNumberByTen" + }, + { + "command": "editor.emmet.action.reflectCSSValue" + } + ] } - ] + }, + "scripts": { + "watch": "gulp watch-extension:emmet", + "compile": "gulp compile-extension:emmet", + "deps": "yarn add vscode-emmet-helper" + }, + "devDependencies": { + "@types/node": "^12.11.7", + "mocha-junit-reporter": "^1.17.0", + "mocha-multi-reporters": "^1.1.7", + "vscode": "1.0.1" + }, + "dependencies": { + "@emmetio/css-parser": "ramya-rao-a/css-parser#vscode", + "@emmetio/html-matcher": "^0.3.3", + "@emmetio/math-expression": "^1.0.4", + "image-size": "^0.5.2", + "vscode-emmet-helper": "~2.0.0", + "vscode-html-languageservice": "^3.0.3" } - }, - "scripts": { - "watch": "gulp watch-extension:emmet", - "compile": "gulp compile-extension:emmet", - "deps": "yarn add vscode-emmet-helper" - }, - "devDependencies": { - "@types/node": "^12.11.7", - "mocha-junit-reporter": "^1.17.0", - "mocha-multi-reporters": "^1.1.7", - "vscode": "1.0.1" - }, - "dependencies": { - "@emmetio/css-parser": "ramya-rao-a/css-parser#vscode", - "@emmetio/html-matcher": "^0.3.3", - "@emmetio/math-expression": "^1.0.4", - "image-size": "^0.5.2", - "vscode-emmet-helper": "~2.0.0", - "vscode-html-languageservice": "^3.0.3" - } } diff --git a/extensions/emmet/package.nls.json b/extensions/emmet/package.nls.json index 4d4090c2b1f..2a1add8935e 100644 --- a/extensions/emmet/package.nls.json +++ b/extensions/emmet/package.nls.json @@ -2,7 +2,6 @@ "description": "Emmet support for VS Code", "command.wrapWithAbbreviation": "Wrap with Abbreviation", "command.wrapIndividualLinesWithAbbreviation": "Wrap Individual Lines with Abbreviation", - "command.expandAbbreviation": "Expand Abbreviation", "command.removeTag": "Remove Tag", "command.updateTag": "Update Tag", "command.matchTag": "Go to Matching Pair", diff --git a/extensions/emmet/src/emmetCommon.ts b/extensions/emmet/src/emmetCommon.ts index a458433057c..e768b03afd6 100644 --- a/extensions/emmet/src/emmetCommon.ts +++ b/extensions/emmet/src/emmetCommon.ts @@ -31,14 +31,10 @@ export function activateEmmetExtension(context: vscode.ExtensionContext) { wrapIndividualLinesWithAbbreviation(args); })); - context.subscriptions.push(vscode.commands.registerCommand('editor.emmet.action.expandAbbreviationInternal', (args) => { + context.subscriptions.push(vscode.commands.registerCommand('emmet.expandAbbreviation', (args) => { expandEmmetAbbreviation(args); })); - context.subscriptions.push(vscode.commands.registerCommand('editor.emmet.action.expandAbbreviation', () => { - vscode.commands.executeCommand('workbench.action.expandEmmetAbbreviation'); - })); - context.subscriptions.push(vscode.commands.registerCommand('editor.emmet.action.removeTag', () => { return removeTag(); })); diff --git a/src/vs/workbench/contrib/emmet/browser/actions/expandAbbreviation.ts b/src/vs/workbench/contrib/emmet/browser/actions/expandAbbreviation.ts new file mode 100644 index 00000000000..b6129b8a6ae --- /dev/null +++ b/src/vs/workbench/contrib/emmet/browser/actions/expandAbbreviation.ts @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +import * as nls from 'vs/nls'; +import { EmmetEditorAction } from 'vs/workbench/contrib/emmet/browser/emmetActions'; +import { registerEditorAction } from 'vs/editor/browser/editorExtensions'; +import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; +import { KeyCode } from 'vs/base/common/keyCodes'; +import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; +import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { MenuId } from 'vs/platform/actions/common/actions'; + +class ExpandAbbreviationAction extends EmmetEditorAction { + + constructor() { + super({ + id: 'editor.emmet.action.expandAbbreviation', + label: nls.localize('expandAbbreviationAction', "Emmet: Expand Abbreviation"), + alias: 'Emmet: Expand Abbreviation', + precondition: EditorContextKeys.writable, + actionName: 'expand_abbreviation', + kbOpts: { + primary: KeyCode.Tab, + kbExpr: ContextKeyExpr.and( + EditorContextKeys.editorTextFocus, + EditorContextKeys.tabDoesNotMoveFocus, + ContextKeyExpr.has('config.emmet.triggerExpansionOnTab') + ), + weight: KeybindingWeight.EditorContrib + }, + menuOpts: { + menuId: MenuId.MenubarEditMenu, + group: '5_insert', + title: nls.localize({ key: 'miEmmetExpandAbbreviation', comment: ['&& denotes a mnemonic'] }, "Emmet: E&&xpand Abbreviation"), + order: 3 + } + }); + + } +} + +registerEditorAction(ExpandAbbreviationAction); diff --git a/src/vs/workbench/contrib/emmet/browser/emmet.contribution.ts b/src/vs/workbench/contrib/emmet/browser/emmet.contribution.ts index 8d64955f6de..f29d6b2c022 100644 --- a/src/vs/workbench/contrib/emmet/browser/emmet.contribution.ts +++ b/src/vs/workbench/contrib/emmet/browser/emmet.contribution.ts @@ -3,7 +3,5 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { registerEditorCommand } from 'vs/editor/browser/editorExtensions'; -import { expandEmmetAbbreviationCommand } from './expandEmmetAbbreviation'; +import './actions/expandAbbreviation'; -registerEditorCommand(expandEmmetAbbreviationCommand); diff --git a/src/vs/workbench/contrib/emmet/browser/expandEmmetAbbreviation.ts b/src/vs/workbench/contrib/emmet/browser/emmetActions.ts similarity index 69% rename from src/vs/workbench/contrib/emmet/browser/expandEmmetAbbreviation.ts rename to src/vs/workbench/contrib/emmet/browser/emmetActions.ts index 008f63c289f..607da869cc3 100644 --- a/src/vs/workbench/contrib/emmet/browser/expandEmmetAbbreviation.ts +++ b/src/vs/workbench/contrib/emmet/browser/emmetActions.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ServicesAccessor, EditorCommand } from 'vs/editor/browser/editorExtensions'; +import { EditorAction, ServicesAccessor, IActionOptions } from 'vs/editor/browser/editorExtensions'; import { grammarsExtPoint, ITMSyntaxExtensionPoint } from 'vs/workbench/services/textMate/common/TMGrammars'; import { IModeService } from 'vs/editor/common/services/modeService'; import { IExtensionService, ExtensionPointContribution } from 'vs/workbench/services/extensions/common/extensions'; @@ -24,6 +24,7 @@ export interface ILanguageIdentifierResolver { } class GrammarContributions implements IGrammarContributions { + private static _grammars: ModeScopeMap = {}; constructor(contributions: ExtensionPointContribution[]) { @@ -47,12 +48,20 @@ class GrammarContributions implements IGrammarContributions { } } -export class ExpandEmmetAbbreviationCommand extends EditorCommand { - constructor() { - super({ id: 'workbench.action.expandEmmetAbbreviation', precondition: undefined }); +export interface IEmmetActionOptions extends IActionOptions { + actionName: string; +} + +export abstract class EmmetEditorAction extends EditorAction { + + protected emmetActionName: string; + + constructor(opts: IEmmetActionOptions) { + super(opts); + this.emmetActionName = opts.actionName; } - private static readonly emmetSupportedModes = ['html', 'xml', 'xsl', 'jsx', 'js', 'pug', 'slim', 'haml', 'css', 'sass', 'scss', 'less', 'sss', 'stylus']; + private static readonly emmetSupportedModes = ['html', 'css', 'xml', 'xsl', 'haml', 'jade', 'jsx', 'slim', 'scss', 'sass', 'less', 'stylus', 'styl', 'svg']; private _lastGrammarContributions: Promise | null = null; private _lastExtensionService: IExtensionService | null = null; @@ -66,21 +75,20 @@ export class ExpandEmmetAbbreviationCommand extends EditorCommand { return this._lastGrammarContributions || Promise.resolve(null); } - public runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: any): void | Promise { - if (!accessor) { - return; - } - + public run(accessor: ServicesAccessor, editor: ICodeEditor): Promise { const extensionService = accessor.get(IExtensionService); const modeService = accessor.get(IModeService); const commandService = accessor.get(ICommandService); return this._withGrammarContributions(extensionService).then((grammarContributions) => { - if (this.id === 'workbench.action.expandEmmetAbbreviation' && grammarContributions) { - return commandService.executeCommand('editor.emmet.action.expandAbbreviationInternal', ExpandEmmetAbbreviationCommand.getLanguage(modeService, editor, grammarContributions)); + + if (this.id === 'editor.emmet.action.expandAbbreviation' && grammarContributions) { + return commandService.executeCommand('emmet.expandAbbreviation', EmmetEditorAction.getLanguage(modeService, editor, grammarContributions)); } + return undefined; }); + } public static getLanguage(languageIdentifierResolver: ILanguageIdentifierResolver, editor: ICodeEditor, grammars: IGrammarContributions) { @@ -96,34 +104,24 @@ export class ExpandEmmetAbbreviationCommand extends EditorCommand { const languageId = model.getLanguageIdAtPosition(position.lineNumber, position.column); const languageIdentifier = languageIdentifierResolver.getLanguageIdentifier(languageId); const language = languageIdentifier ? languageIdentifier.language : ''; - let syntax = language.split('.').pop(); + const syntax = language.split('.').pop(); if (!syntax) { return null; } - // map to something Emmet understands - if (['jsx-tags', 'javascriptreact', 'typescriptreact'].includes(syntax)) { - syntax = 'jsx'; - } - - const getParentMode = (syntax: string): string => { - if (syntax === 'jsx') { - // return otherwise getGrammar gives a string that Emmet doesn't understand - return syntax; - } - - const languageGrammar = grammars.getGrammar(syntax); + let checkParentMode = (): string => { + let languageGrammar = grammars.getGrammar(syntax); if (!languageGrammar) { return syntax; } - const languages = languageGrammar.split('.'); - if (languages.length <= 1) { + let languages = languageGrammar.split('.'); + if (languages.length < 2) { return syntax; } - for (let i = languages.length - 1; i >= 1; i--) { - const language = languages[i]; - if (this.emmetSupportedModes.includes(language)) { + for (let i = 1; i < languages.length; i++) { + const language = languages[languages.length - i]; + if (this.emmetSupportedModes.indexOf(language) !== -1) { return language; } } @@ -132,9 +130,9 @@ export class ExpandEmmetAbbreviationCommand extends EditorCommand { return { language: syntax, - parentMode: getParentMode(syntax) + parentMode: checkParentMode() }; } -} -export const expandEmmetAbbreviationCommand = new ExpandEmmetAbbreviationCommand(); + +} diff --git a/src/vs/workbench/contrib/emmet/test/browser/expandEmmetAbbreviation.test.ts b/src/vs/workbench/contrib/emmet/test/browser/emmetAction.test.ts similarity index 57% rename from src/vs/workbench/contrib/emmet/test/browser/expandEmmetAbbreviation.test.ts rename to src/vs/workbench/contrib/emmet/test/browser/emmetAction.test.ts index 885e1a5064e..c56afa2d157 100644 --- a/src/vs/workbench/contrib/emmet/test/browser/expandEmmetAbbreviation.test.ts +++ b/src/vs/workbench/contrib/emmet/test/browser/emmetAction.test.ts @@ -3,11 +3,29 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IGrammarContributions, ILanguageIdentifierResolver, ExpandEmmetAbbreviationCommand } from 'vs/workbench/contrib/emmet/browser/expandEmmetAbbreviation'; +import { IGrammarContributions, ILanguageIdentifierResolver, EmmetEditorAction } from 'vs/workbench/contrib/emmet/browser/emmetActions'; import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; import * as assert from 'assert'; import { LanguageId, LanguageIdentifier } from 'vs/editor/common/modes'; +// +// To run the emmet tests only change .vscode/launch.json +// { +// "name": "Stacks Tests", +// "type": "node", +// "request": "launch", +// "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", +// "stopOnEntry": false, +// "args": [ +// "--timeout", +// "999999", +// "--colors", +// "-g", +// "Stacks" <<<--- Emmet +// ], +// Select the 'Stacks Tests' launch config and F5 +// + class MockGrammarContributions implements IGrammarContributions { private scopeName: string; @@ -15,14 +33,16 @@ class MockGrammarContributions implements IGrammarContributions { this.scopeName = scopeName; } - public getGrammar(_: string): string { + public getGrammar(mode: string): string { return this.scopeName; } } -suite('Emmet expandAbbreviation command', () => { - test('gets language mode and parent mode for Emmet', () => { +suite('Emmet', () => { + + test('Get language mode and parent mode for emmet', () => { withTestCodeEditor([], {}, (editor) => { + function testIsEnabled(mode: string, scopeName: string, expectedLanguage?: string, expectedParentLanguage?: string) { const languageIdentifier = new LanguageIdentifier(mode, 73); const languageIdentifierResolver: ILanguageIdentifierResolver = { @@ -39,13 +59,13 @@ suite('Emmet expandAbbreviation command', () => { } model.setMode(languageIdentifier); - const langOutput = ExpandEmmetAbbreviationCommand.getLanguage(languageIdentifierResolver, editor, new MockGrammarContributions(scopeName)); + let langOutput = EmmetEditorAction.getLanguage(languageIdentifierResolver, editor, new MockGrammarContributions(scopeName)); if (!langOutput) { assert.fail('langOutput not found'); } - assert.strictEqual(langOutput.language, expectedLanguage); - assert.strictEqual(langOutput.parentMode, expectedParentLanguage); + assert.equal(langOutput.language, expectedLanguage); + assert.equal(langOutput.parentMode, expectedParentLanguage); } // syntaxes mapped using the scope name of the grammar @@ -54,22 +74,10 @@ suite('Emmet expandAbbreviation command', () => { testIsEnabled('nunjucks', 'text.html.nunjucks', 'nunjucks', 'html'); testIsEnabled('laravel-blade', 'text.html.php.laravel-blade', 'laravel-blade', 'html'); - // basic syntaxes - testIsEnabled('html', 'text.html.derivative', 'html', 'html'); - testIsEnabled('css', 'source.css', 'css', 'css'); - testIsEnabled('scss', 'source.css.scss', 'scss', 'scss'); - testIsEnabled('xml', 'text.xml', 'xml', 'xml'); - testIsEnabled('xsl', 'text.xml.xsl', 'xsl', 'xsl'); + // languages that have different Language Id and scopeName + // testIsEnabled('razor', 'text.html.cshtml', 'razor', 'html'); + // testIsEnabled('HTML (Eex)', 'text.html.elixir', 'boo', 'html'); - // syntaxes that combine HTML and TS/JS - // expanding inside of HTML tags within jsx/tsx - testIsEnabled('jsx-tags', 'source.js.jsx', 'jsx', 'jsx'); - // expanding outside of HTML tags within jsx/tsx - testIsEnabled('javascriptreact', 'source.js.jsx', 'jsx', 'jsx'); - testIsEnabled('typescriptreact', 'source.tsx', 'jsx', 'jsx'); - - // syntaxes that combine HTML and some other language - testIsEnabled('razor', 'text.html.cshtml', 'razor', 'html'); }); }); });