Skip to content

Commit

Permalink
fix html custom snippets loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Aug 2, 2017
1 parent 8d1df93 commit 4394c04
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vscode-emmet-helper",
"version": "1.0.7",
"version": "1.0.8",
"description": "Helper to use emmet modules in Visual Studio Code",
"main": "./out/emmetHelper.js",
"author": "Microsoft Corporation",
Expand Down
21 changes: 12 additions & 9 deletions src/emmetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
}

if (!isStyleSheet(syntax)) {
if (!snippetKeyCache.has(syntax)) {
if (!snippetKeyCache.has(syntax) || !markupSnippetKeysRegex || markupSnippetKeysRegex.length === 0) {
let registry = customSnippetRegistry[syntax] ? customSnippetRegistry[syntax] : createSnippetsRegistry(syntax);
markupSnippetKeys = registry.all({ type: 'string' }).map(snippet => {
return snippet.key;
});
markupSnippetKeysRegex = registry.all({ type: 'regexp' }).map(snippet => {

if (!snippetKeyCache.has(syntax)) {
snippetKeyCache.set(syntax, registry.all({ type: 'string' }).map(snippet => {
return snippet.key;
}));
}

markupSnippetKeysRegex = registry.all({ type: 'regexp' }).map(snippet => {
return snippet.key;
});
snippetKeyCache.set(syntax, markupSnippetKeys);
} else {
markupSnippetKeys = snippetKeyCache.get(syntax);

}
markupSnippetKeys = snippetKeyCache.get(syntax);
}

let expandedAbbr: CompletionItem;
Expand All @@ -63,7 +66,7 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
|| (!/^[a-z,A-Z,\d]*$/.test(abbreviation) && !abbreviation.endsWith('.'))
|| markupSnippetKeys.indexOf(abbreviation) > -1
|| commonlyUsedTags.indexOf(abbreviation) > -1
|| markupSnippetKeysRegex.find(x => x.test(abbreviation)) ) {
|| markupSnippetKeysRegex.find(x => x.test(abbreviation))) {
try {
expandedText = expand(abbreviation, expandOptions);
// Skip cases when abc -> abc: ; as this is noise
Expand Down
29 changes: 29 additions & 0 deletions src/emmetHelperTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,35 @@ describe('Test completions', () => {
});
});

it('should provide completions using custom snippets', () => {
return updateExtensionsPath(extensionsPath).then(() => {
const testCases: [string, number, number, string, string][] = [
['<div>hey</div>', 0, 8, 'hey', '<ul>\n\t<li><span class="hello">|</span></li>\n\t<li><span class="hello">|</span></li>\n</ul>']
];

testCases.forEach(([content, positionLine, positionChar, expectedAbbr, expectedExpansion]) => {
const document = TextDocument.create('test://test/test.html', 'html', 0, content);
const position = Position.create(positionLine, positionChar);
const completionList = doComplete(document, position, 'html', {
useNewEmmet: true,
showExpandedAbbreviation: 'always',
showAbbreviationSuggestions: false,
syntaxProfiles: {
'html': {
'tag_case': 'lower'
}
},
variables: {}
});

assert.equal(completionList.items[0].label, expectedAbbr);
assert.equal(completionList.items[0].documentation, expectedExpansion);
});
return Promise.resolve();

});
});

it('should not provide completions', () => {
return updateExtensionsPath(null).then(() => {
const testCases: [string, number, number][] = [
Expand Down
7 changes: 6 additions & 1 deletion testData/snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
},
"variables": {
"lang": "fr"
}
},
"html": {
"snippets": {
"hey": "ul>li*2>span.hello"
}
}
}

0 comments on commit 4394c04

Please sign in to comment.