Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for markup attributes in vue #92

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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