Support lorem in completions
This commit is contained in:
Родитель
b39358a20b
Коммит
b76d9ebbe8
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vscode-emmet-helper",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "Helper to use emmet modules in Visual Studio Code",
|
||||
"main": "./out/emmetHelper.js",
|
||||
"author": "Microsoft Corporation",
|
||||
|
|
|
@ -12,6 +12,7 @@ import * as fs from 'fs';
|
|||
|
||||
const snippetKeyCache = new Map<string, string[]>();
|
||||
let markupSnippetKeys: string[];
|
||||
let markupSnippetKeysRegex: RegExp[];
|
||||
const htmlAbbreviationStartRegex = /^[a-z,A-Z,!,(,[,#,\.]/;
|
||||
const htmlAbbreviationEndRegex = /[a-z,A-Z,!,),\],#,\.,},\d,*,$]$/;
|
||||
const cssAbbreviationRegex = /^[a-z,A-Z,!,@,#]/;
|
||||
|
@ -40,6 +41,9 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
|
|||
markupSnippetKeys = 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);
|
||||
|
@ -58,7 +62,8 @@ export function doComplete(document: TextDocument, position: Position, syntax: s
|
|||
if (isStyleSheet(syntax)
|
||||
|| (!/^[a-z,A-Z,\d]*$/.test(abbreviation) && !abbreviation.endsWith('.'))
|
||||
|| markupSnippetKeys.indexOf(abbreviation) > -1
|
||||
|| commonlyUsedTags.indexOf(abbreviation) > -1) {
|
||||
|| commonlyUsedTags.indexOf(abbreviation) > -1
|
||||
|| markupSnippetKeysRegex.find(x => x.test(abbreviation)) ) {
|
||||
try {
|
||||
expandedText = expand(abbreviation, expandOptions);
|
||||
// Skip cases when abc -> abc: ; as this is noise
|
||||
|
|
|
@ -150,16 +150,6 @@ describe('Test output profile settings', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should use profile from extensionsPath', () => {
|
||||
return updateExtensionsPath(extensionsPath).then(() => {
|
||||
|
||||
const expandOptions = getExpandOptions('html', {});
|
||||
assert.equal(expandOptions.profile['tagCase'], 'upper');
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should use profile from settings that overrides the ones from extensionsPath', () => {
|
||||
return updateExtensionsPath(extensionsPath).then(() => {
|
||||
const profile = {
|
||||
|
@ -247,13 +237,13 @@ describe('Test custom snippets', () => {
|
|||
describe('Test completions', () => {
|
||||
it('should provide completions', () => {
|
||||
return updateExtensionsPath(null).then(() => {
|
||||
const testCases: [string, number, number, string, string, number, number, number, number][] = [
|
||||
['<div>ul>li*3</div>', 0, 7, 'ul', '<ul></ul>', 0, 5, 0, 7],
|
||||
['<div>ul>li*3</div>', 0, 10, 'ul>li', '<ul>\n\t<li></li>\n</ul>', 0, 5, 0, 10],
|
||||
['<div>(ul>li)*3</div>', 0, 14, '(ul>li)*3', '<ul>\n\t<li></li>\n</ul>\n<ul>\n\t<li></li>\n</ul>\n<ul>\n\t<li></li>\n</ul>', 0, 5, 0, 10]
|
||||
const testCases: [string, number, number, string, string][] = [
|
||||
['<div>ul>li*3</div>', 0, 7, 'ul', '<ul></ul>'],
|
||||
['<div>ul>li*3</div>', 0, 10, 'ul>li', '<ul>\n\t<li></li>\n</ul>'],
|
||||
['<div>(ul>li)*3</div>', 0, 14, '(ul>li)*3', '<ul>\n\t<li></li>\n</ul>\n<ul>\n\t<li></li>\n</ul>\n<ul>\n\t<li></li>\n</ul>']
|
||||
];
|
||||
|
||||
testCases.forEach(([content, positionLine, positionChar, expectedAbbr, expectedExpansion, expectedRangeStartLine, expectedRangeStartChar, expectedRangeEndLine, expectedRangeEndChar]) => {
|
||||
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', {
|
||||
|
@ -299,4 +289,30 @@ describe('Test completions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should provide completions for lorem', () => {
|
||||
return updateExtensionsPath(null).then(() => {
|
||||
|
||||
|
||||
const document = TextDocument.create('test://test/test.html', 'html', 0, 'lorem10.item');
|
||||
const position = Position.create(0, 12);
|
||||
const completionList = doComplete(document, position, 'html', {
|
||||
useNewEmmet: true,
|
||||
showExpandedAbbreviation: 'always',
|
||||
showAbbreviationSuggestions: false,
|
||||
syntaxProfiles: {},
|
||||
variables: {}
|
||||
});
|
||||
const expandedText = completionList.items[0].documentation;
|
||||
let matches = expandedText.match(/<div class="item">(.*)<\/div>/);
|
||||
|
||||
assert.equal(completionList.items[0].label, 'lorem10.item');
|
||||
assert.equal(matches != null, true);
|
||||
assert.equal(matches[1].split(' ').length, 10);
|
||||
assert.equal(matches[1].startsWith('Lorem'), true);
|
||||
|
||||
return Promise.resolve();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
})
|
Загрузка…
Ссылка в новой задаче