[css] split extension (for #45900)

This commit is contained in:
Pine Wu
2018-03-20 14:57:58 -07:00
parent 18146e8c71
commit c52149e7a3
32 changed files with 784 additions and 766 deletions

View File

@@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'mocha';
import * as assert from 'assert';
import * as path from 'path';
import Uri from 'vscode-uri';
import { TextDocument, CompletionList } from 'vscode-languageserver-types';
import { WorkspaceFolder } from 'vscode-languageserver-protocol';
import { getPathCompletionParticipant } from '../pathCompletion';
import { getCSSLanguageService } from 'vscode-css-languageservice';
export interface ItemDescription {
label: string;
resultText?: string;
}
suite('Completions', () => {
const cssLanguageService = getCSSLanguageService();
let assertCompletion = function (completions: CompletionList, expected: ItemDescription, document: TextDocument, offset: number) {
let matches = completions.items.filter(completion => {
return completion.label === expected.label;
});
assert.equal(matches.length, 1, `${expected.label} should only existing once: Actual: ${completions.items.map(c => c.label).join(', ')}`);
let match = matches[0];
if (expected.resultText && match.textEdit) {
assert.equal(TextDocument.applyEdits(document, [match.textEdit]), expected.resultText);
}
};
function assertCompletions(value: string, expected: { count?: number, items?: ItemDescription[] }, testUri: string, workspaceFolders?: WorkspaceFolder[]): void {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
const document = TextDocument.create(testUri, 'css', 0, value);
const position = document.positionAt(offset);
if (!workspaceFolders) {
workspaceFolders = [{ name: 'x', uri: path.dirname(testUri) }];
}
let participantResult = CompletionList.create([]);
cssLanguageService.setCompletionParticipants([getPathCompletionParticipant(document, workspaceFolders, participantResult)]);
const stylesheet = cssLanguageService.parseStylesheet(document);
let list = cssLanguageService.doComplete!(document, position, stylesheet);
list.items = list.items.concat(participantResult.items);
if (expected.count) {
assert.equal(list.items.length, expected.count);
}
if (expected.items) {
for (let item of expected.items) {
assertCompletion(list, item, document, offset);
}
}
}
test('CSS Path completion', function () {
let testUri = Uri.file(path.resolve(__dirname, '../../test/pathCompletionFixtures/about/about.css')).fsPath;
assertCompletions('html { background-image: url("./|")', {
items: [
{ label: 'about.html', resultText: 'html { background-image: url("./about.html")' }
]
}, testUri);
assertCompletions(`html { background-image: url('../|')`, {
items: [
{ label: 'about/', resultText: `html { background-image: url('../about/')` },
{ label: 'index.html', resultText: `html { background-image: url('../index.html')` },
{ label: 'src/', resultText: `html { background-image: url('../src/')` }
]
}, testUri);
});
});

View File

@@ -0,0 +1,71 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'mocha';
import * as assert from 'assert';
import { getCSSLanguageService, getSCSSLanguageService } from 'vscode-css-languageservice/lib/umd/cssLanguageService';
import { TextDocument, CompletionList } from 'vscode-languageserver-types';
import { getEmmetCompletionParticipants } from 'vscode-emmet-helper';
suite('CSS Emmet Support', () => {
const cssLanguageService = getCSSLanguageService();
const scssLanguageService = getSCSSLanguageService();
function assertCompletions(syntax: string, value: string, expectedProposal: string, expectedProposalDoc: string): void {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
const document = TextDocument.create('test://test/test.' + syntax, syntax, 0, value);
const position = document.positionAt(offset);
const emmetCompletionList: CompletionList = {
isIncomplete: true,
items: undefined
};
const languageService = syntax === 'scss' ? scssLanguageService : cssLanguageService;
languageService.setCompletionParticipants([getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList)]);
const stylesheet = languageService.parseStylesheet(document);
const list = languageService.doComplete!(document, position, stylesheet);
assert.ok(list);
assert.ok(emmetCompletionList);
if (expectedProposal && expectedProposalDoc) {
let actualLabels = (emmetCompletionList!.items || []).map(c => c.label).sort();
let actualDocs = (emmetCompletionList!.items || []).map(c => c.documentation).sort();
assert.ok(actualLabels.indexOf(expectedProposal) !== -1, 'Not found:' + expectedProposal + ' is ' + actualLabels.join(', '));
assert.ok(actualDocs.indexOf(expectedProposalDoc) !== -1, 'Not found:' + expectedProposalDoc + ' is ' + actualDocs.join(', '));
} else {
assert.ok(!emmetCompletionList || !emmetCompletionList.items);
}
}
test('Css Emmet Completions', function (): any {
this.skip(); // disabled again (see #29113)
assertCompletions('css', '.foo { display: none; m10| }', 'margin: 10px;', 'margin: 10px;');
assertCompletions('css', 'foo { display: none; pos:f| }', 'position: fixed;', 'position: fixed;');
assertCompletions('css', 'foo { display: none; margin: a| }', null, null);
assertCompletions('css', 'foo| { display: none; }', null, null);
assertCompletions('css', 'foo {| display: none; }', null, null);
assertCompletions('css', 'foo { display: none;| }', null, null);
assertCompletions('css', 'foo { display: none|; }', null, null);
assertCompletions('css', '.foo { display: none; -m-m10| }', 'margin: 10px;', '-moz-margin: 10px;\nmargin: 10px;');
});
test('Scss Emmet Completions', function (): any {
this.skip(); // disabled again (see #29113)
assertCompletions('scss', '.foo { display: none; .bar { m10| } }', 'margin: 10px;', 'margin: 10px;');
assertCompletions('scss', 'foo { display: none; .bar { pos:f| } }', 'position: fixed;', 'position: fixed;');
assertCompletions('scss', 'foo { display: none; margin: a| .bar {}}', null, null);
assertCompletions('scss', 'foo| { display: none; }', null, null);
assertCompletions('scss', 'foo {| display: none; }', null, null);
assertCompletions('scss', 'foo { display: none;| }', null, null);
assertCompletions('scss', 'foo { display: none|; }', null, null);
assertCompletions('scss', '.foo { display: none; -m-m10| }', 'margin: 10px;', '-moz-margin: 10px;\nmargin: 10px;');
});
});