mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Add tests, update version
This commit is contained in:
parent
4eca3c3d89
commit
a9d90af1a7
|
@ -10,7 +10,7 @@
|
|||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.6",
|
||||
"vscode-emmet-helper": "^1.1.34",
|
||||
"vscode-html-languageservice": "^2.0.16",
|
||||
"vscode-html-languageservice": "^2.0.17-next.3",
|
||||
"vscode-languageserver": "^4.0.0-next.4",
|
||||
"vscode-languageserver-types": "^3.6.0-next.1",
|
||||
"vscode-nls": "^3.2.1",
|
||||
|
@ -27,6 +27,6 @@
|
|||
"install-service-local": "npm install ../../../../vscode-css-languageservice -f && npm install ../../../../vscode-html-languageservice -f",
|
||||
"install-server-next": "yarn add vscode-languageserver@next",
|
||||
"install-server-local": "npm install ../../../../vscode-languageserver-node/server -f",
|
||||
"test": "../../../node_modules/.bin/mocha"
|
||||
"test": "npm run compile && ../../../node_modules/.bin/mocha"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
'use strict';
|
||||
|
||||
import { TextDocument, CompletionList, CompletionItemKind, CompletionItem, TextEdit, Range, Position } from 'vscode-languageserver-types';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver-protocol/lib/protocol.workspaceFolders.proposed';
|
||||
import { Proposed } from 'vscode-languageserver-protocol';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import URI from 'vscode-uri';
|
||||
|
@ -15,7 +15,7 @@ import { contains } from '../utils/arrays';
|
|||
|
||||
export function getPathCompletionParticipant(
|
||||
document: TextDocument,
|
||||
workspaceFolders: WorkspaceFolder[] | undefined,
|
||||
workspaceFolders: Proposed.WorkspaceFolder[] | undefined,
|
||||
result: CompletionList
|
||||
): ICompletionParticipant {
|
||||
return {
|
||||
|
@ -90,7 +90,7 @@ const isDir = (p: string) => {
|
|||
return fs.statSync(p).isDirectory();
|
||||
};
|
||||
|
||||
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: WorkspaceFolder[]): string | undefined {
|
||||
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: Proposed.WorkspaceFolder[]): string | undefined {
|
||||
for (let i = 0; i < workspaceFolders.length; i++) {
|
||||
if (startsWith(activeDoc.uri, workspaceFolders[i].uri)) {
|
||||
return path.resolve(URI.parse(workspaceFolders[i].uri).fsPath);
|
||||
|
|
134
extensions/html/server/src/test/completions.test.ts
Normal file
134
extensions/html/server/src/test/completions.test.ts
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { TextDocument, CompletionList, CompletionItemKind, } from 'vscode-languageserver-types';
|
||||
import { getLanguageModes } from '../modes/languageModes';
|
||||
import { applyEdits } from '../utils/edits';
|
||||
import Uri from 'vscode-uri';
|
||||
import { getPathCompletionParticipant } from '../modes/pathCompletion';
|
||||
import { Proposed } from 'vscode-languageserver-protocol';
|
||||
|
||||
export interface ItemDescription {
|
||||
label: string;
|
||||
documentation?: string;
|
||||
kind?: CompletionItemKind;
|
||||
resultText?: string;
|
||||
notAvailable?: boolean;
|
||||
}
|
||||
|
||||
|
||||
suite('Completions', () => {
|
||||
|
||||
let assertCompletion = function (completions: CompletionList, expected: ItemDescription, document: TextDocument, offset: number) {
|
||||
let matches = completions.items.filter(completion => {
|
||||
return completion.label === expected.label;
|
||||
});
|
||||
if (expected.notAvailable) {
|
||||
assert.equal(matches.length, 0, `${expected.label} should not existing is results`);
|
||||
return;
|
||||
}
|
||||
|
||||
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.documentation) {
|
||||
assert.equal(match.documentation, expected.documentation);
|
||||
}
|
||||
if (expected.kind) {
|
||||
assert.equal(match.kind, expected.kind);
|
||||
}
|
||||
if (expected.resultText && match.textEdit) {
|
||||
assert.equal(applyEdits(document, [match.textEdit]), expected.resultText);
|
||||
}
|
||||
};
|
||||
|
||||
const testUri = 'test://test/test.html';
|
||||
|
||||
function assertCompletions(value: string, expected: { count?: number, items?: ItemDescription[] }, uri = testUri, workspaceFolders?: Proposed.WorkspaceFolder[]): void {
|
||||
let offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
let document = TextDocument.create(uri, 'html', 0, value);
|
||||
let position = document.positionAt(offset);
|
||||
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true });
|
||||
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);
|
||||
|
||||
if (expected.count) {
|
||||
assert.equal(list.items, expected.count);
|
||||
}
|
||||
if (expected.items) {
|
||||
for (let item of expected.items) {
|
||||
assertCompletion(list, item, document, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test('HTML Javascript Completions', function (): any {
|
||||
assertCompletions('<html><script>window.|</script></html>', {
|
||||
items: [
|
||||
{ label: 'location', resultText: '<html><script>window.location</script></html>' },
|
||||
]
|
||||
});
|
||||
assertCompletions('<html><script>$.|</script></html>', {
|
||||
items: [
|
||||
{ label: 'getJSON', resultText: '<html><script>$.getJSON</script></html>' },
|
||||
]
|
||||
});
|
||||
});
|
||||
/*
|
||||
test('Path completion', function (): any {
|
||||
let testUri = Uri.file(path.resolve(__dirname, '../../test/pathCompletionFixtures/foo.html')).fsPath;
|
||||
|
||||
assertCompletions('<div><a href="about/|">', {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions(`<div><a href=about/|>`, {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: `<div><a href=about/about.html>` }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions(`<div><a href='about/|'>`, {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: `<div><a href='about/about.html'>` }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions('<div><a href="about/about|.xml">', {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions('<div><a href="about/a|">', {
|
||||
items: [
|
||||
{ label: 'about.html', resultText: '<div><a href="about/about.html">' }
|
||||
]
|
||||
}, testUri);
|
||||
assertCompletions('<div><a href="|">', {
|
||||
items: [
|
||||
{ label: 'index.html', resultText: '<div><a href="index.html">' },
|
||||
{ label: 'about', resultText: '<div><a href="about/">' }
|
||||
]
|
||||
}, testUri);
|
||||
|
||||
});
|
||||
*/
|
||||
});
|
|
@ -1,45 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { getJavascriptMode } from '../modes/javascriptMode';
|
||||
import { TextDocument } from 'vscode-languageserver-types';
|
||||
import { getLanguageModelCache } from '../languageModelCache';
|
||||
|
||||
import { getLanguageService } from 'vscode-html-languageservice';
|
||||
import * as embeddedSupport from '../modes/embeddedSupport';
|
||||
|
||||
suite('HTML Javascript Support', () => {
|
||||
|
||||
var htmlLanguageService = getLanguageService();
|
||||
|
||||
function assertCompletions(value: string, expectedProposals: string[]): void {
|
||||
let offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
let document = TextDocument.create('test://test/test.html', 'html', 0, value);
|
||||
|
||||
let documentRegions = getLanguageModelCache<embeddedSupport.HTMLDocumentRegions>(10, 60, document => embeddedSupport.getDocumentRegions(htmlLanguageService, document));
|
||||
|
||||
var mode = getJavascriptMode(documentRegions);
|
||||
|
||||
let position = document.positionAt(offset);
|
||||
let list = mode.doComplete!(document, position);
|
||||
assert.ok(list);
|
||||
|
||||
let actualLabels = list!.items.map(c => c.label).sort();
|
||||
for (let expected of expectedProposals) {
|
||||
assert.ok(actualLabels.indexOf(expected) !== -1, 'Not found:' + expected + ' is ' + actualLabels.join(', '));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
test('Completions', function (): any {
|
||||
assertCompletions('<html><script>window.|</script></html>', ['location']);
|
||||
assertCompletions('<html><script>$.|</script></html>', ['getJSON']);
|
||||
});
|
||||
});
|
|
@ -33,9 +33,9 @@ vscode-emmet-helper@^1.1.34:
|
|||
jsonc-parser "^1.0.0"
|
||||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
|
||||
vscode-html-languageservice@^2.0.16:
|
||||
version "2.0.16"
|
||||
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.0.16.tgz#db5e8307caddedc1acdb5a1fffb919bb9a1184cb"
|
||||
vscode-html-languageservice@^2.0.17-next.3:
|
||||
version "2.0.17-next.3"
|
||||
resolved "https://registry.yarnpkg.com/vscode-html-languageservice/-/vscode-html-languageservice-2.0.17-next.3.tgz#dd5e90fac3073ffc2c624bd26daa9f27adfa50eb"
|
||||
dependencies:
|
||||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
vscode-nls "^2.0.2"
|
||||
|
|
Loading…
Reference in a new issue