diff --git a/package.json b/package.json index 505f2bd..0a69dd5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/emmetHelper.ts b/src/emmetHelper.ts index 7938a3f..14e5cfa 100644 --- a/src/emmetHelper.ts +++ b/src/emmetHelper.ts @@ -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; @@ -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 diff --git a/src/emmetHelperTest.ts b/src/emmetHelperTest.ts index 8c68d4f..9c07ecc 100644 --- a/src/emmetHelperTest.ts +++ b/src/emmetHelperTest.ts @@ -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][] = [ + ['