mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
[html] add css support to html extension as library
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
import * as assert from 'assert';
|
||||
import * as embeddedSupport from '../embeddedSupport';
|
||||
import {TextDocument} from 'vscode-languageserver-types';
|
||||
|
||||
import { getLanguageService } from 'vscode-html-languageservice';
|
||||
import { getLanguageService} from 'vscode-html-languageservice';
|
||||
|
||||
suite('HTML Embedded Support', () => {
|
||||
|
||||
var htmlLanguageService = getLanguageService();
|
||||
|
||||
function assertEmbeddedLanguageId(value: string, expectedLanguageId: string): void {
|
||||
let offset = value.indexOf('|');
|
||||
@@ -23,7 +23,7 @@ suite('HTML Embedded Support', () => {
|
||||
let ls = getLanguageService();
|
||||
let htmlDoc = ls.parseHTMLDocument(document);
|
||||
|
||||
let languageId = embeddedSupport.getEmbeddedLanguageAtPosition(ls, document, htmlDoc, position);
|
||||
let languageId = embeddedSupport.getEmbeddedLanguageAtPosition(htmlLanguageService, document, htmlDoc, position);
|
||||
assert.equal(languageId, expectedLanguageId);
|
||||
}
|
||||
|
||||
@@ -34,18 +34,18 @@ suite('HTML Embedded Support', () => {
|
||||
let ls = getLanguageService();
|
||||
let htmlDoc = ls.parseHTMLDocument(document);
|
||||
|
||||
let content = embeddedSupport.getEmbeddedContent(ls, document, htmlDoc, languageId);
|
||||
assert.equal(content, expectedContent);
|
||||
let content = embeddedSupport.getEmbeddedDocument(ls, document, htmlDoc, languageId);
|
||||
assert.equal(content.getText(), expectedContent);
|
||||
}
|
||||
|
||||
test('Styles', function (): any {
|
||||
assertEmbeddedLanguageId('|<html><style>foo { }</style></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html|><style>foo { }</style></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html><st|yle>foo { }</style></html>', void 0);
|
||||
assertEmbeddedLanguageId('|<html><style>foo { }</style></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html|><style>foo { }</style></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html><st|yle>foo { }</style></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html><style>|foo { }</style></html>', 'css');
|
||||
assertEmbeddedLanguageId('<html><style>foo| { }</style></html>', 'css');
|
||||
assertEmbeddedLanguageId('<html><style>foo { }|</style></html>', 'css');
|
||||
assertEmbeddedLanguageId('<html><style>foo { }</sty|le></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html><style>foo { }</sty|le></html>', 'html');
|
||||
});
|
||||
|
||||
test('Style content', function (): any {
|
||||
@@ -57,19 +57,19 @@ suite('HTML Embedded Support', () => {
|
||||
});
|
||||
|
||||
test('Scripts', function (): any {
|
||||
assertEmbeddedLanguageId('|<html><script>var i = 0;</script></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html|><script>var i = 0;</script></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html><scr|ipt>var i = 0;</script></html>', void 0);
|
||||
assertEmbeddedLanguageId('|<html><script>var i = 0;</script></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html|><script>var i = 0;</script></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html><scr|ipt>var i = 0;</script></html>', 'html');
|
||||
assertEmbeddedLanguageId('<html><script>|var i = 0;</script></html>', 'javascript');
|
||||
assertEmbeddedLanguageId('<html><script>var| i = 0;</script></html>', 'javascript');
|
||||
assertEmbeddedLanguageId('<html><script>var i = 0;|</script></html>', 'javascript');
|
||||
assertEmbeddedLanguageId('<html><script>var i = 0;</scr|ipt></html>', void 0);
|
||||
assertEmbeddedLanguageId('<html><script>var i = 0;</scr|ipt></html>', 'html');
|
||||
|
||||
assertEmbeddedLanguageId('<script type="text/javascript">var| i = 0;</script>', 'javascript');
|
||||
assertEmbeddedLanguageId('<script type="text/ecmascript">var| i = 0;</script>', 'javascript');
|
||||
assertEmbeddedLanguageId('<script type="application/javascript">var| i = 0;</script>', 'javascript');
|
||||
assertEmbeddedLanguageId('<script type="application/ecmascript">var| i = 0;</script>', 'javascript');
|
||||
assertEmbeddedLanguageId('<script type="application/typescript">var| i = 0;</script>', void 0);
|
||||
assertEmbeddedLanguageId('<script type="application/typescript">var| i = 0;</script>', 'html');
|
||||
assertEmbeddedLanguageId('<script type=\'text/javascript\'>var| i = 0;</script>', 'javascript');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,27 +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 * as assert from 'assert';
|
||||
import {getEmbeddedContentUri, getEmbeddedLanguageId, getHostDocumentUri, isEmbeddedContentUri} from './embeddedContentUri';
|
||||
|
||||
suite('Embedded URI', () => {
|
||||
|
||||
test('URI', function (): any {
|
||||
let resourceUri1 = 'file:///c%3A/workspaces/samples/foo.html';
|
||||
let resourceUri2 = 'file://Users/joe/samples/foo.html';
|
||||
|
||||
let uri = getEmbeddedContentUri(resourceUri1, 'css');
|
||||
assert(isEmbeddedContentUri(uri));
|
||||
assert.equal(getEmbeddedLanguageId(uri), 'css');
|
||||
assert.equal(getHostDocumentUri(uri), resourceUri1);
|
||||
|
||||
let uri2 = getEmbeddedContentUri(resourceUri2, 'css');
|
||||
assert(isEmbeddedContentUri(uri2));
|
||||
assert.equal(getEmbeddedLanguageId(uri2), 'css');
|
||||
assert.equal(getHostDocumentUri(uri2), resourceUri2);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,27 +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 Uri from 'vscode-uri';
|
||||
|
||||
export const EMBEDDED_CONTENT_SCHEME = 'embedded-content';
|
||||
|
||||
export function isEmbeddedContentUri(virtualDocumentUri: Uri): boolean {
|
||||
return virtualDocumentUri.scheme === EMBEDDED_CONTENT_SCHEME;
|
||||
}
|
||||
|
||||
export function getEmbeddedContentUri(parentDocumentUri: string, embeddedLanguageId: string): Uri {
|
||||
return Uri.from({ scheme: EMBEDDED_CONTENT_SCHEME, authority: embeddedLanguageId, path: '/' + encodeURIComponent(parentDocumentUri) + '.' + embeddedLanguageId });
|
||||
};
|
||||
|
||||
export function getHostDocumentUri(virtualDocumentUri: Uri): string {
|
||||
let languageId = virtualDocumentUri.authority;
|
||||
let path = virtualDocumentUri.path.substring(1, virtualDocumentUri.path.length - languageId.length - 1); // remove leading '/' and new file extension
|
||||
return decodeURIComponent(path);
|
||||
};
|
||||
|
||||
export function getEmbeddedLanguageId(virtualDocumentUri: Uri): string {
|
||||
return virtualDocumentUri.authority;
|
||||
}
|
||||
Reference in New Issue
Block a user