Skip to content

Commit

Permalink
Add support for markup attributes in vue (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
nurbek0298 committed Apr 5, 2024
1 parent ea184b3 commit a6ba695
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/configCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export function parseSnippets(snippets: SnippetsMap): SnippetsMap {
* List of all known syntaxes
*/
export const syntaxes = {
markup: ['html', 'xml', 'xsl', 'jsx', 'js', 'pug', 'slim', 'haml'],
markup: ['html', 'xml', 'xsl', 'jsx', 'js', 'pug', 'slim', 'haml', 'vue'],
stylesheet: ['css', 'sass', 'scss', 'less', 'sss', 'stylus']
};
25 changes: 25 additions & 0 deletions src/emmetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,31 @@ export function getExpandOptions(syntax: string, emmetConfig?: VSCodeEmmetConfig
}
}

if (syntax === 'vue') {
// Ref https://github.com/emmetio/emmet/blob/master/src/config.ts#L404
const defaultMarkupAttributeOptions = {
'class*': ':class',
};

const defaultMarkupValuePrefixOptions = {
'class*': '$style'
};

if (profile['markup.attributes']) {
userPreferenceOptions['markup.attributes'] = {
...defaultMarkupAttributeOptions,
...profile['markup.attributes']
};
}

if (profile['markup.valuePrefix']) {
userPreferenceOptions['markup.valuePrefix'] = {
...defaultMarkupValuePrefixOptions,
...profile['markup.valuePrefix']
};
}
}

const combinedOptions: any = {};
[...Object.keys(defaultVSCodeOptions), ...Object.keys(userPreferenceOptions)].forEach(key => {
const castKey = key as keyof Options;
Expand Down
21 changes: 21 additions & 0 deletions src/test/emmetHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,27 @@ describe('Test Basic Expand Options', () => {
assert.strictEqual(expandOptions.options['markup.valuePrefix']!['class'], 'valuePrefix');
assert.strictEqual(expandOptions.options['markup.attributes']!['class'], 'attributePrefix');
})

it('should support vue markup attributes', () => {
const syntax = 'vue';
const emmetConfig = {
syntaxProfiles: {
vue: {
'markup.attributes': {
'class': 'attributePrefix'
},
'markup.valuePrefix': {
'class': 'valuePrefix'
}
}
}
};
const expandOptions = getExpandOptions(syntax, emmetConfig);
assert.ok(expandOptions.options['markup.valuePrefix']);
assert.ok(expandOptions.options['markup.attributes']);
assert.strictEqual(expandOptions.options['markup.valuePrefix']!['class'], 'valuePrefix');
assert.strictEqual(expandOptions.options['markup.attributes']!['class'], 'attributePrefix');
})
});

describe('Test addons in Expand Options', () => {
Expand Down
15 changes: 14 additions & 1 deletion src/test/expand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,20 @@ describe('Expand Abbreviations', () => {
// https://github.com/microsoft/vscode/issues/180689
testExpandWithCompletion('jsx', '.bar', '<div className="bar">${0}</div>', { 'syntaxProfiles': { 'jsx': { 'jsx.enabled': true }}});
testExpandWithCompletion('jsx', '..bar', '<div styleName={styles.bar}>${0}</div>', { 'syntaxProfiles': { 'jsx': { 'jsx.enabled': true }}});

testExpandWithCompletion(
'vue',
'..bar',
'<div :class="\\$style.bar">${0}</div>',
{
syntaxProfiles: {
vue: {
'markup.valuePrefix': {
"class*": "$style"
}
}
}
}
);
// https://github.com/microsoft/vscode/issues/137240
// testExpandWithCompletion('css', 'dn!important', 'display: none !important;');

Expand Down

0 comments on commit a6ba695

Please sign in to comment.