volar-service-emmet 0.0.0
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/out/empty.d.ts +3 -0
- package/out/empty.js +5 -0
- package/out/index.d.ts +3 -0
- package/out/index.js +90 -0
- package/package.json +31 -0
package/out/empty.d.ts
ADDED
package/out/empty.js
ADDED
package/out/index.d.ts
ADDED
package/out/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const emmet = __importStar(require("@vscode/emmet-helper"));
|
|
27
|
+
const volar_service_html_1 = require("volar-service-html");
|
|
28
|
+
exports.default = () => (context) => {
|
|
29
|
+
// https://docs.emmet.io/abbreviations/syntax/
|
|
30
|
+
const triggerCharacters = '>+^*()#.[]$@-{}'.split('');
|
|
31
|
+
if (!context) {
|
|
32
|
+
return { triggerCharacters };
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
triggerCharacters,
|
|
36
|
+
isAdditionalCompletion: true,
|
|
37
|
+
async provideCompletionItems(textDocument, position) {
|
|
38
|
+
const syntax = emmet.getEmmetMode(textDocument.languageId === 'vue' ? 'html' : textDocument.languageId);
|
|
39
|
+
if (!syntax)
|
|
40
|
+
return;
|
|
41
|
+
// fix https://github.com/vuejs/language-tools/issues/1329
|
|
42
|
+
if (syntax === 'html') {
|
|
43
|
+
const htmlDocument = (0, volar_service_html_1.getHtmlDocument)(textDocument);
|
|
44
|
+
const node = htmlDocument.findNodeAt(textDocument.offsetAt(position));
|
|
45
|
+
if (node.tag) {
|
|
46
|
+
let insideBlock = false;
|
|
47
|
+
if (node.startTagEnd !== undefined && node.endTagStart !== undefined) {
|
|
48
|
+
insideBlock = textDocument.offsetAt(position) >= node.startTagEnd && textDocument.offsetAt(position) <= node.endTagStart;
|
|
49
|
+
}
|
|
50
|
+
if (!insideBlock) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// monkey fix https://github.com/johnsoncodehk/volar/issues/1105
|
|
56
|
+
if (syntax === 'jsx')
|
|
57
|
+
return;
|
|
58
|
+
const emmetConfig = await getEmmetConfig(syntax);
|
|
59
|
+
return emmet.doComplete(textDocument, position, syntax, emmetConfig);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
async function getEmmetConfig(syntax) {
|
|
63
|
+
const emmetConfig = await context?.env.getConfiguration?.('emmet') ?? {};
|
|
64
|
+
const syntaxProfiles = Object.assign({}, emmetConfig['syntaxProfiles'] || {});
|
|
65
|
+
const preferences = Object.assign({}, emmetConfig['preferences'] || {});
|
|
66
|
+
// jsx, xml and xsl syntaxes need to have self closing tags unless otherwise configured by user
|
|
67
|
+
if (syntax === 'jsx' || syntax === 'xml' || syntax === 'xsl') {
|
|
68
|
+
syntaxProfiles[syntax] = syntaxProfiles[syntax] || {};
|
|
69
|
+
if (typeof syntaxProfiles[syntax] === 'object'
|
|
70
|
+
&& !syntaxProfiles[syntax].hasOwnProperty('self_closing_tag') // Old Emmet format
|
|
71
|
+
&& !syntaxProfiles[syntax].hasOwnProperty('selfClosingStyle') // Emmet 2.0 format
|
|
72
|
+
) {
|
|
73
|
+
syntaxProfiles[syntax] = {
|
|
74
|
+
...syntaxProfiles[syntax],
|
|
75
|
+
selfClosingStyle: 'xml'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
preferences,
|
|
81
|
+
showExpandedAbbreviation: emmetConfig['showExpandedAbbreviation'],
|
|
82
|
+
showAbbreviationSuggestions: emmetConfig['showAbbreviationSuggestions'],
|
|
83
|
+
syntaxProfiles,
|
|
84
|
+
variables: emmetConfig['variables'],
|
|
85
|
+
excludeLanguages: emmetConfig['excludeLanguages'],
|
|
86
|
+
showSuggestionsAsSnippets: emmetConfig['showSuggestionsAsSnippets']
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "volar-service-emmet",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"main": "out/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"out/**/*.js",
|
|
8
|
+
"out/**/*.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/volarjs/services.git",
|
|
13
|
+
"directory": "packages/emmet"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@vscode/emmet-helper": "^2.8.6",
|
|
17
|
+
"volar-service-html": "0.0.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@volar/language-service": "*"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"@volar/language-service": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"browser": {
|
|
28
|
+
"./out/index.js": "./out/empty.js"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "1011561ac4bbf79c53c3b80c27692569bf861519"
|
|
31
|
+
}
|