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][] = [ + ['
hey
', 0, 8, 'hey', ''] + ]; + + 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][] = [ diff --git a/testData/snippets.json b/testData/snippets.json index 53047ec..c135d3d 100644 --- a/testData/snippets.json +++ b/testData/snippets.json @@ -6,5 +6,10 @@ }, "variables": { "lang": "fr" - } + }, + "html": { + "snippets": { + "hey": "ul>li*2>span.hello" + } + } } \ No newline at end of file