@codingame/monaco-vscode-emmet-service-override 4.1.0 → 4.1.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.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-emmet-service-override",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.1.
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.1.1"
|
|
22
22
|
}
|
|
23
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 };
|