提交 05b254dc 编写于 作者: R Ramya Achutha Rao

Support variable customization in emmet snippets

上级 5e2d92d2
......@@ -21,7 +21,7 @@
"contributes": {
"configuration": {
"type": "object",
"title": "Emmet configuration",
"title": "Emmet",
"properties": {
"emmet.showExpandedAbbreviation": {
"type": "boolean",
......@@ -32,6 +32,39 @@
"type": "boolean",
"default": true,
"description": "Shows possible emmet abbreviations as suggestions"
},
"emmet.variables":{
"type": "object",
"properties": {
"lang": {
"type": "string",
"default": "en"
},
"locale": {
"type": "string",
"default": "en-US"
},
"charset": {
"type": "string",
"default": "UTF-8"
},
"indentation": {
"type": "string",
"default": "\t"
},
"newline": {
"type": "string",
"default": "\n"
}
},
"default":{
"lang": "en",
"locale": "en-US",
"charset": "UTF-8",
"indentation": "\t",
"newline": "\n"
},
"description": "Variables to be used in emmet snippets"
}
}
}
......
......@@ -27,17 +27,10 @@ export function wrapWithAbbreviation() {
}
let textToReplace = editor.document.getText(rangeToReplace);
let syntax = getSyntax(editor.document);
let options = {
field: field,
syntax: syntax,
profile: getProfile(getSyntax(editor.document)),
text: textToReplace,
addons: syntax === 'jsx' ? { 'jsx': syntax === 'jsx' } : null
};
vscode.window.showInputBox({ prompt: 'Enter Abbreviation' }).then(abbr => {
if (!abbr || !abbr.trim()) { return; }
let expandedText = expand(abbr, options);
let expandedText = expand(abbr, getExpandOptions(syntax, textToReplace));
editor.insertSnippet(new vscode.SnippetString(expandedText), rangeToReplace);
});
}
......@@ -96,14 +89,7 @@ export function expandAbbreviationHelper(syntax: string, document: vscode.TextDo
[abbreviationRange, abbreviation] = extractAbbreviation(document, abbreviationRange.start);
}
let options = {
field: field,
syntax: syntax,
profile: getProfile(syntax),
addons: syntax === 'jsx' ? { 'jsx': true } : null
};
let expandedText = expand(abbreviation, options);
let expandedText = expand(abbreviation, getExpandOptions(syntax));
return { expandedText, abbreviationRange, abbreviation, syntax };
}
......@@ -153,4 +139,15 @@ function isValidLocationForEmmetAbbreviation(currentNode: Node, syntax: string,
}
return false;
}
function getExpandOptions(syntax: string, textToReplace?: string) {
return {
field: field,
syntax: syntax,
profile: getProfile(syntax),
addons: syntax === 'jsx' ? { 'jsx': true } : null,
variables: vscode.workspace.getConfiguration('emmet')['variables'],
text: textToReplace ? textToReplace : ''
};
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册