mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
[html] move path completion inside html mode
This commit is contained in:
@@ -7,10 +7,9 @@
|
||||
import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
// import Uri from 'vscode-uri';
|
||||
import Uri from 'vscode-uri';
|
||||
import { TextDocument, CompletionList, CompletionItemKind } from 'vscode-languageserver-types';
|
||||
import { getLanguageModes } from '../modes/languageModes';
|
||||
import { getPathCompletionParticipant } from '../modes/pathCompletion';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver';
|
||||
|
||||
export interface ItemDescription {
|
||||
@@ -22,7 +21,7 @@ export interface ItemDescription {
|
||||
notAvailable?: boolean;
|
||||
}
|
||||
|
||||
export function assertCompletion (completions: CompletionList, expected: ItemDescription, document: TextDocument, offset: number) {
|
||||
export function assertCompletion(completions: CompletionList, expected: ItemDescription, document: TextDocument, offset: number) {
|
||||
let matches = completions.items.filter(completion => {
|
||||
return completion.label === expected.label;
|
||||
});
|
||||
@@ -49,32 +48,22 @@ export function assertCompletion (completions: CompletionList, expected: ItemDes
|
||||
|
||||
const testUri = 'test://test/test.html';
|
||||
|
||||
export function testCompletionFor(
|
||||
value: string,
|
||||
expected: { count?: number, items?: ItemDescription[] },
|
||||
uri = testUri,
|
||||
workspaceFolders?: WorkspaceFolder[]
|
||||
): void {
|
||||
export function testCompletionFor(value: string, expected: { count?: number, items?: ItemDescription[] }, uri = testUri, workspaceFolders?: WorkspaceFolder[]): void {
|
||||
let offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
let workspace = {
|
||||
settings: {},
|
||||
folders: workspaceFolders || [{ name: 'x', uri: uri.substr(0, uri.lastIndexOf('/')) }]
|
||||
};
|
||||
|
||||
let document = TextDocument.create(uri, 'html', 0, value);
|
||||
let position = document.positionAt(offset);
|
||||
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true });
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true }, workspace);
|
||||
var mode = languageModes.getModeAtPosition(document, position)!;
|
||||
|
||||
if (!workspaceFolders) {
|
||||
workspaceFolders = [{ name: 'x', uri: path.dirname(uri) }];
|
||||
}
|
||||
|
||||
let participantResult = CompletionList.create([]);
|
||||
if (mode.setCompletionParticipants) {
|
||||
mode.setCompletionParticipants([getPathCompletionParticipant(document, workspaceFolders, participantResult)]);
|
||||
}
|
||||
|
||||
let list = mode.doComplete!(document, position)!;
|
||||
list.items = list.items.concat(participantResult.items);
|
||||
let list = mode.doComplete!(document, position);
|
||||
|
||||
if (expected.count) {
|
||||
assert.equal(list.items, expected.count);
|
||||
@@ -107,10 +96,10 @@ suite('HTML Path Completion', () => {
|
||||
command: 'editor.action.triggerSuggest'
|
||||
};
|
||||
|
||||
const fixtureRoot = path.resolve(__dirname, 'pathcompletionfixtures');
|
||||
const fixtureWorkspace = { name: 'fixture', uri: fixtureRoot };
|
||||
const indexHtmlUri = path.resolve(fixtureRoot, 'index.html');
|
||||
const aboutHtmlUri = path.resolve(fixtureRoot, 'about/about.html');
|
||||
const fixtureRoot = path.resolve(__dirname, 'pathCompletionFixtures');
|
||||
const fixtureWorkspace = { name: 'fixture', uri: Uri.file(fixtureRoot).toString() };
|
||||
const indexHtmlUri = Uri.file(path.resolve(fixtureRoot, 'index.html')).toString();
|
||||
const aboutHtmlUri = Uri.file(path.resolve(fixtureRoot, 'about/about.html')).toString();
|
||||
|
||||
test('Basics - Correct label/kind/result/command', () => {
|
||||
testCompletionFor('<script src="./|">', {
|
||||
|
||||
@@ -23,25 +23,30 @@ suite('HTML Emmet Support', () => {
|
||||
const offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
const workspace = {
|
||||
settings: {},
|
||||
folders: [{ name: 'test', uri: 'test://test' }]
|
||||
};
|
||||
|
||||
const document = TextDocument.create('test://test/test.' + syntax, syntax, 0, value);
|
||||
const position = document.positionAt(offset);
|
||||
const documentRegions = getLanguageModelCache<embeddedSupport.HTMLDocumentRegions>(10, 60, document => embeddedSupport.getDocumentRegions(htmlLanguageService, document));
|
||||
const mode = syntax === 'html' ? getHTMLMode(htmlLanguageService) : getCSSMode(documentRegions);
|
||||
const mode = syntax === 'html' ? getHTMLMode(htmlLanguageService, workspace) : getCSSMode(documentRegions, workspace);
|
||||
|
||||
const emmetCompletionList = CompletionList.create([], false);
|
||||
mode.setCompletionParticipants!([getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList)]);
|
||||
const emmetParticipant = getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList);
|
||||
|
||||
const list = mode.doComplete!(document, position);
|
||||
const list = mode.doComplete!(document, position, {}, [emmetParticipant]);
|
||||
assert.ok(list);
|
||||
assert.ok(emmetCompletionList);
|
||||
|
||||
let actualLabels = emmetCompletionList.items.map(c => c.label).sort();
|
||||
let actualDocs = emmetCompletionList.items.map(c => c.documentation).sort();
|
||||
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(', '));
|
||||
assert.ok(actualLabels.indexOf(expectedProposal) !== -1, value + ': Not found:' + expectedProposal + ' is ' + actualLabels.join(', '));
|
||||
assert.ok(actualDocs.indexOf(expectedProposalDoc) !== -1, value + ': Not found:' + expectedProposalDoc + ' is ' + actualDocs.join(', '));
|
||||
} else {
|
||||
assert.ok(!emmetCompletionList.items.length && !emmetCompletionList.isIncomplete);
|
||||
assert.ok(!emmetCompletionList.items.length && !emmetCompletionList.isIncomplete, value + ': No proposals expected, but was ' + actualLabels.join(', '));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,8 +62,8 @@ suite('HTML Emmet Support', () => {
|
||||
test('Css Emmet Completions', function (): any {
|
||||
assertCompletions('css', '<style>.foo { display: none; m10| }</style>', 'margin: 10px;', 'margin: 10px;');
|
||||
assertCompletions('css', '<style>foo { display: none; pos:f| }</style>', 'position: fixed;', 'position: fixed;');
|
||||
assertCompletions('css', '<style>foo { display: none; margin: a| }</style>', null, null);
|
||||
assertCompletions('css', '<style>foo| { display: none; }</style>', null, null);
|
||||
// assertCompletions('css', '<style>foo { display: none; margin: a| }</style>', null, null); // disabled for #29113
|
||||
// assertCompletions('css', '<style>foo| { display: none; }</style>', null, null); // disabled for #29113
|
||||
assertCompletions('css', '<style>foo {| display: none; }</style>', null, null);
|
||||
assertCompletions('css', '<style>foo { display: none;| }</style>', null, null);
|
||||
assertCompletions('css', '<style>foo { display: none|; }</style>', null, null);
|
||||
|
||||
@@ -19,7 +19,11 @@ interface ExpectedIndentRange {
|
||||
|
||||
function assertRanges(lines: string[], expected: ExpectedIndentRange[], message?: string, nRanges?: number): void {
|
||||
let document = TextDocument.create('test://foo/bar.json', 'json', 1, lines.join('\n'));
|
||||
let languageModes = getLanguageModes({ css: true, javascript: true });
|
||||
let workspace = {
|
||||
settings: {},
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
let languageModes = getLanguageModes({ css: true, javascript: true }, workspace);
|
||||
let actual = getFoldingRegions(languageModes, document, nRanges, null)!.ranges;
|
||||
|
||||
let actualRanges = [];
|
||||
|
||||
@@ -17,10 +17,11 @@ import { format } from '../modes/formatting';
|
||||
suite('HTML Embedded Formatting', () => {
|
||||
|
||||
function assertFormat(value: string, expected: string, options?: any, formatOptions?: FormattingOptions, message?: string): void {
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true });
|
||||
if (options) {
|
||||
languageModes.getAllModes().forEach(m => m.configure!(options));
|
||||
}
|
||||
let workspace = {
|
||||
settings: options,
|
||||
folders: [{ name: 'foo', uri: 'test://foo' }]
|
||||
};
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true }, workspace);
|
||||
|
||||
let rangeStartOffset = value.indexOf('|');
|
||||
let rangeEndOffset;
|
||||
|
||||
Reference in New Issue
Block a user