@codingame/monaco-vscode-emmet-service-override 2.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/emmet.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { IEditorOverrideServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
2
+
3
+ declare function getServiceOverride(): IEditorOverrideServices;
4
+
5
+ export { getServiceOverride as default };
package/emmet.js ADDED
@@ -0,0 +1,7 @@
1
+ import './vscode/src/vs/workbench/contrib/emmet/browser/actions/expandAbbreviation.js';
2
+
3
+ function getServiceOverride() {
4
+ return {};
5
+ }
6
+
7
+ export { getServiceOverride as default };
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './emmet.js';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from './emmet.js';
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@codingame/monaco-vscode-emmet-service-override",
3
+ "version": "2.2.0-next.1",
4
+ "keywords": [],
5
+ "author": {
6
+ "name": "CodinGame",
7
+ "url": "http://www.codingame.com"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:CodinGame/monaco-vscode-api.git"
13
+ },
14
+ "type": "module",
15
+ "private": false,
16
+ "description": "VSCode public API plugged on the monaco editor - emmet service-override",
17
+ "main": "index.js",
18
+ "module": "index.js",
19
+ "types": "index.d.ts",
20
+ "dependencies": {
21
+ "vscode": "npm:@codingame/monaco-vscode-api@2.2.0-next.1"
22
+ }
23
+ }
@@ -0,0 +1,42 @@
1
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
2
+ import { EmmetEditorAction } from '../emmetActions.js';
3
+ import { registerEditorAction } from 'vscode/vscode/vs/editor/browser/editorExtensions';
4
+ import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
5
+ import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
6
+ import { MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
7
+
8
+ class ExpandAbbreviationAction extends EmmetEditorAction {
9
+ constructor() {
10
+ super({
11
+ id: 'editor.emmet.action.expandAbbreviation',
12
+ label: ( localizeWithPath(
13
+ 'vs/workbench/contrib/emmet/browser/actions/expandAbbreviation',
14
+ 'expandAbbreviationAction',
15
+ "Emmet: Expand Abbreviation"
16
+ )),
17
+ alias: 'Emmet: Expand Abbreviation',
18
+ precondition: EditorContextKeys.writable,
19
+ actionName: 'expand_abbreviation',
20
+ kbOpts: {
21
+ primary: 2 ,
22
+ kbExpr: ( ContextKeyExpr.and(
23
+ EditorContextKeys.editorTextFocus,
24
+ EditorContextKeys.tabDoesNotMoveFocus,
25
+ ( ContextKeyExpr.has('config.emmet.triggerExpansionOnTab'))
26
+ )),
27
+ weight: 100
28
+ },
29
+ menuOpts: {
30
+ menuId: MenuId.MenubarEditMenu,
31
+ group: '5_insert',
32
+ title: ( localizeWithPath(
33
+ 'vs/workbench/contrib/emmet/browser/actions/expandAbbreviation',
34
+ { key: 'miEmmetExpandAbbreviation', comment: ['&& denotes a mnemonic'] },
35
+ "Emmet: E&&xpand Abbreviation"
36
+ )),
37
+ order: 3
38
+ }
39
+ });
40
+ }
41
+ }
42
+ registerEditorAction(ExpandAbbreviationAction);
@@ -0,0 +1,90 @@
1
+ import { EditorAction } from 'vscode/vscode/vs/editor/browser/editorExtensions';
2
+ import { grammarsExtPoint } from 'vscode/vscode/vs/workbench/services/textMate/common/TMGrammars';
3
+ import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions';
4
+ import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands';
5
+
6
+ class GrammarContributions {
7
+ static { this._grammars = {}; }
8
+ constructor(contributions) {
9
+ if (!( Object.keys(GrammarContributions._grammars)).length) {
10
+ this.fillModeScopeMap(contributions);
11
+ }
12
+ }
13
+ fillModeScopeMap(contributions) {
14
+ contributions.forEach((contribution) => {
15
+ contribution.value.forEach((grammar) => {
16
+ if (grammar.language && grammar.scopeName) {
17
+ GrammarContributions._grammars[grammar.language] = grammar.scopeName;
18
+ }
19
+ });
20
+ });
21
+ }
22
+ getGrammar(mode) {
23
+ return GrammarContributions._grammars[mode];
24
+ }
25
+ }
26
+ class EmmetEditorAction extends EditorAction {
27
+ constructor(opts) {
28
+ super(opts);
29
+ this._lastGrammarContributions = null;
30
+ this._lastExtensionService = null;
31
+ this.emmetActionName = opts.actionName;
32
+ }
33
+ static { this.emmetSupportedModes = ['html', 'css', 'xml', 'xsl', 'haml', 'jade', 'jsx', 'slim', 'scss', 'sass', 'less', 'stylus', 'styl', 'svg']; }
34
+ _withGrammarContributions(extensionService) {
35
+ if (this._lastExtensionService !== extensionService) {
36
+ this._lastExtensionService = extensionService;
37
+ this._lastGrammarContributions = extensionService.readExtensionPointContributions(grammarsExtPoint).then((contributions) => {
38
+ return ( new GrammarContributions(contributions));
39
+ });
40
+ }
41
+ return this._lastGrammarContributions || Promise.resolve(null);
42
+ }
43
+ run(accessor, editor) {
44
+ const extensionService = accessor.get(IExtensionService);
45
+ const commandService = accessor.get(ICommandService);
46
+ return this._withGrammarContributions(extensionService).then((grammarContributions) => {
47
+ if (this.id === 'editor.emmet.action.expandAbbreviation' && grammarContributions) {
48
+ return commandService.executeCommand('emmet.expandAbbreviation', EmmetEditorAction.getLanguage(editor, grammarContributions));
49
+ }
50
+ return undefined;
51
+ });
52
+ }
53
+ static getLanguage(editor, grammars) {
54
+ const model = editor.getModel();
55
+ const selection = editor.getSelection();
56
+ if (!model || !selection) {
57
+ return null;
58
+ }
59
+ const position = selection.getStartPosition();
60
+ model.tokenization.tokenizeIfCheap(position.lineNumber);
61
+ const languageId = model.getLanguageIdAtPosition(position.lineNumber, position.column);
62
+ const syntax = languageId.split('.').pop();
63
+ if (!syntax) {
64
+ return null;
65
+ }
66
+ const checkParentMode = () => {
67
+ const languageGrammar = grammars.getGrammar(syntax);
68
+ if (!languageGrammar) {
69
+ return syntax;
70
+ }
71
+ const languages = languageGrammar.split('.');
72
+ if (languages.length < 2) {
73
+ return syntax;
74
+ }
75
+ for (let i = 1; i < languages.length; i++) {
76
+ const language = languages[languages.length - i];
77
+ if (this.emmetSupportedModes.indexOf(language) !== -1) {
78
+ return language;
79
+ }
80
+ }
81
+ return syntax;
82
+ };
83
+ return {
84
+ language: syntax,
85
+ parentMode: checkParentMode()
86
+ };
87
+ }
88
+ }
89
+
90
+ export { EmmetEditorAction };