当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vscode-html-languageservice.getLanguageService函数代码示例

本文整理汇总了TypeScript中vscode-html-languageservice.getLanguageService函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getLanguageService函数的具体用法?TypeScript getLanguageService怎么用?TypeScript getLanguageService使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getLanguageService函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: suite

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']);
	});
});
开发者ID:armanio123,项目名称:vscode,代码行数:30,代码来源:javascriptMode.test.ts

示例2: assertEmbeddedLanguageContent

	function assertEmbeddedLanguageContent(value: string, languageId: string, expectedContent: string): void {

		let document = TextDocument.create('test://test/test.html', 'html', 0, value);

		let ls = getLanguageService();
		let htmlDoc = ls.parseHTMLDocument(document);

		let content = embeddedSupport.getEmbeddedContent(ls, document, htmlDoc, languageId);
		assert.equal(content, expectedContent);
	}
开发者ID:elemongw,项目名称:vscode,代码行数:10,代码来源:embedded.test.ts

示例3: suite

suite('HTML Emmet Support', () => {

	const htmlLanguageService = getLanguageService();

	function assertCompletions(syntax: string, value: string, expectedProposal: string | null, expectedProposalDoc: string | null): void {
		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, workspace) : getCSSMode(documentRegions, workspace);

		const emmetCompletionList = CompletionList.create([], false);
		const emmetParticipant = getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList);

		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) {
			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, value + ': No proposals expected, but was ' + actualLabels.join(', '));
		}

	}

	test('Html Emmet Completions', function (): any {
		assertCompletions('html', 'ul|', 'ul', '<ul>|</ul>');
		assertCompletions('html', '<ul|', null, null);
		assertCompletions('html', '<html>ul|</html>', 'ul', '<ul>|</ul>');
		assertCompletions('html', '<img src=|', null, null);
		assertCompletions('html', '<div class=|/>', null, null);
	});

	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); // 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);
		assertCompletions('css', '<style>.foo { display: none; -m-m10| }</style>', 'margin: 10px;', '-moz-margin: 10px;\nmargin: 10px;');
	});
});
开发者ID:costincaraivan,项目名称:vscode,代码行数:55,代码来源:emmet.test.ts

示例4: suite

suite('Emmet Support', () => {

	const htmlLanguageService = getLanguageService();

	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 documentRegions = getLanguageModelCache<embeddedSupport.HTMLDocumentRegions>(10, 60, document => embeddedSupport.getDocumentRegions(htmlLanguageService, document));
		const mode = syntax == 'html' ? getHTMLMode(htmlLanguageService) : getCSSMode(documentRegions);
		const emmetCompletionList: CompletionList = {
			isIncomplete: true,
			items: undefined
		}
		mode.setCompletionParticipants([getEmmetCompletionParticipants(document, position, document.languageId, {}, emmetCompletionList)])

		const list = mode.doComplete!(document, position);
		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('Html Emmet Completions', function (): any {
		assertCompletions('html', 'ul|', 'ul', '<ul>|</ul>');
		assertCompletions('html', '<ul|', null, null);
		assertCompletions('html', '<html>ul|</html>', 'ul', '<ul>|</ul>');
		assertCompletions('html', '<img src=|', null, null);
		assertCompletions('html', '<div class=|/>', null, null);
	});

	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; }</style>', null, null);
		assertCompletions('css', '<style>foo { display: none;| }</style>', null, null);
		assertCompletions('css', '<style>foo { display: none|; }</style>', null, null);
		assertCompletions('css', '<style>.foo { display: none; -m-m10| }</style>', 'margin: 10px;', '-moz-margin: 10px;\nmargin: 10px;');
	});
});
开发者ID:sameer-coder,项目名称:vscode,代码行数:53,代码来源:emmet.test.ts

示例5: assertEmbeddedLanguageId

	function assertEmbeddedLanguageId(value: string, expectedLanguageId: 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 position = document.positionAt(offset);
		let ls = getLanguageService();
		let htmlDoc = ls.parseHTMLDocument(document);

		let languageId = embeddedSupport.getEmbeddedLanguageAtPosition(ls, document, htmlDoc, position);
		assert.equal(languageId, expectedLanguageId);
	}
开发者ID:elemongw,项目名称:vscode,代码行数:13,代码来源:embedded.test.ts

示例6: activate

export function activate(context: vscode.ExtensionContext) {

    // create and keep html language service
    const service = html.getLanguageService();

    vscode.languages.registerCompletionItemProvider(['typescript', 'javascript'], {
        provideCompletionItems(doc, pos) {

            const offset = doc.offsetAt(pos);
            const source = ts.createSourceFile(doc.fileName, doc.getText(), ts.ScriptTarget.Latest, true);

            let token = (ts as any).getTokenAtPosition(source, offset)
            let template: ts.TaggedTemplateExpression;
            while (token) {
                if (token.kind === ts.SyntaxKind.TaggedTemplateExpression) {
                    template = token;
                    break;
                }
                token = token.parent;
            }

            if (!template
                || template.tag.getText() !== 'html'
                || (offset < template.template.pos && offset > template.template.end)
            ) {
                return;
            }

            const content = template.template.getText().slice(1, -1);
            const embeddedDoc = TextDocument.create(doc.uri.with({ scheme: 'html-fake' }).toString(), 'html', doc.version, content);
            const htmlDoc = service.parseHTMLDocument(embeddedDoc);

            const list = service.doComplete(embeddedDoc, Position.create(0, offset - template.template.pos - 1), htmlDoc);

            return list.items.map(item => {
                // translate to vscode items
                return new vscode.CompletionItem(item.label);
            })
        }
    });
}
开发者ID:voodoos,项目名称:vscode-extension-samples,代码行数:41,代码来源:extension.ts

示例7: suite

suite('HTML Embedded Support', () => {

	var htmlLanguageService = getLanguageService();

	function assertLanguageId(value: string, expectedLanguageId: string | undefined): 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 position = document.positionAt(offset);

		let docRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
		let languageId = docRegions.getLanguageAtPosition(position);

		assert.equal(languageId, expectedLanguageId);
	}

	function assertEmbeddedLanguageContent(value: string, languageId: string, expectedContent: string): void {
		let document = TextDocument.create('test://test/test.html', 'html', 0, value);

		let docRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
		let content = docRegions.getEmbeddedDocument(languageId);
		assert.equal(content.getText(), expectedContent);
	}

	test('Styles', function (): any {
		assertLanguageId('|<html><style>foo { }</style></html>', 'html');
		assertLanguageId('<html|><style>foo { }</style></html>', 'html');
		assertLanguageId('<html><st|yle>foo { }</style></html>', 'html');
		assertLanguageId('<html><style>|foo { }</style></html>', 'css');
		assertLanguageId('<html><style>foo| { }</style></html>', 'css');
		assertLanguageId('<html><style>foo { }|</style></html>', 'css');
		assertLanguageId('<html><style>foo { }</sty|le></html>', 'html');
	});

	test('Styles - Incomplete HTML', function (): any {
		assertLanguageId('|<html><style>foo { }', 'html');
		assertLanguageId('<html><style>fo|o { }', 'css');
		assertLanguageId('<html><style>foo { }|', 'css');
	});

	test('Style in attribute', function (): any {
		assertLanguageId('<div id="xy" |style="color: red"/>', 'html');
		assertLanguageId('<div id="xy" styl|e="color: red"/>', 'html');
		assertLanguageId('<div id="xy" style=|"color: red"/>', 'html');
		assertLanguageId('<div id="xy" style="|color: red"/>', 'css');
		assertLanguageId('<div id="xy" style="color|: red"/>', 'css');
		assertLanguageId('<div id="xy" style="color: red|"/>', 'css');
		assertLanguageId('<div id="xy" style="color: red"|/>', 'html');
		assertLanguageId('<div id="xy" style=\'color: r|ed\'/>', 'css');
		assertLanguageId('<div id="xy" style|=color:red/>', 'html');
		assertLanguageId('<div id="xy" style=|color:red/>', 'css');
		assertLanguageId('<div id="xy" style=color:r|ed/>', 'css');
		assertLanguageId('<div id="xy" style=color:red|/>', 'css');
		assertLanguageId('<div id="xy" style=color:red/|>', 'html');
	});

	test('Style content', function (): any {
		assertEmbeddedLanguageContent('<html><style>foo { }</style></html>', 'css', '             foo { }               ');
		assertEmbeddedLanguageContent('<html><script>var i = 0;</script></html>', 'css', '                                        ');
		assertEmbeddedLanguageContent('<html><style>foo { }</style>Hello<style>foo { }</style></html>', 'css', '             foo { }                    foo { }               ');
		assertEmbeddedLanguageContent('<html>\n  <style>\n    foo { }  \n  </style>\n</html>\n', 'css', '\n         \n    foo { }  \n  \n\n');

		assertEmbeddedLanguageContent('<div style="color: red"></div>', 'css', '         __{color: red}       ');
		assertEmbeddedLanguageContent('<div style=color:red></div>', 'css', '        __{color:red}      ');
	});

	test('Scripts', function (): any {
		assertLanguageId('|<html><script>var i = 0;</script></html>', 'html');
		assertLanguageId('<html|><script>var i = 0;</script></html>', 'html');
		assertLanguageId('<html><scr|ipt>var i = 0;</script></html>', 'html');
		assertLanguageId('<html><script>|var i = 0;</script></html>', 'javascript');
		assertLanguageId('<html><script>var| i = 0;</script></html>', 'javascript');
		assertLanguageId('<html><script>var i = 0;|</script></html>', 'javascript');
		assertLanguageId('<html><script>var i = 0;</scr|ipt></html>', 'html');

		assertLanguageId('<script type="text/javascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="text/ecmascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/javascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/ecmascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/typescript">var| i = 0;</script>', void 0);
		assertLanguageId('<script type=\'text/javascript\'>var| i = 0;</script>', 'javascript');
	});

	test('Scripts in attribute', function (): any {
		assertLanguageId('<div |onKeyUp="foo()" onkeydown=\'bar()\'/>', 'html');
		assertLanguageId('<div onKeyUp=|"foo()" onkeydown=\'bar()\'/>', 'html');
		assertLanguageId('<div onKeyUp="|foo()" onkeydown=\'bar()\'/>', 'javascript');
		assertLanguageId('<div onKeyUp="foo(|)" onkeydown=\'bar()\'/>', 'javascript');
		assertLanguageId('<div onKeyUp="foo()|" onkeydown=\'bar()\'/>', 'javascript');
		assertLanguageId('<div onKeyUp="foo()"| onkeydown=\'bar()\'/>', 'html');
		assertLanguageId('<div onKeyUp="foo()" onkeydown=|\'bar()\'/>', 'html');
		assertLanguageId('<div onKeyUp="foo()" onkeydown=\'|bar()\'/>', 'javascript');
		assertLanguageId('<div onKeyUp="foo()" onkeydown=\'bar()|\'/>', 'javascript');
		assertLanguageId('<div onKeyUp="foo()" onkeydown=\'bar()\'|/>', 'html');

		assertLanguageId('<DIV ONKEYUP|=foo()</DIV>', 'html');
		assertLanguageId('<DIV ONKEYUP=|foo()</DIV>', 'javascript');
		assertLanguageId('<DIV ONKEYUP=f|oo()</DIV>', 'javascript');
//.........这里部分代码省略.........
开发者ID:AllureFer,项目名称:vscode,代码行数:101,代码来源:embedded.test.ts

示例8: suite

suite('HTML Embedded Support', () => {

	var htmlLanguageService = getLanguageService();

	function assertLanguageId(value: string, expectedLanguageId: 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 position = document.positionAt(offset);
		let ls = getLanguageService();
		let htmlDoc = ls.parseHTMLDocument(document);

		let languageId = embeddedSupport.getLanguageAtPosition(htmlLanguageService, document, htmlDoc, position);
		assert.equal(languageId, expectedLanguageId);
	}

	function assertEmbeddedLanguageContent(value: string, languageId: string, expectedContent: string): void {

		let document = TextDocument.create('test://test/test.html', 'html', 0, value);

		let ls = getLanguageService();
		let htmlDoc = ls.parseHTMLDocument(document);

		let content = embeddedSupport.getEmbeddedDocument(ls, document, htmlDoc, languageId);
		assert.equal(content.getText(), expectedContent);
	}

	test('Styles', function (): any {
		assertLanguageId('|<html><style>foo { }</style></html>', 'html');
		assertLanguageId('<html|><style>foo { }</style></html>', 'html');
		assertLanguageId('<html><st|yle>foo { }</style></html>', 'html');
		assertLanguageId('<html><style>|foo { }</style></html>', 'css');
		assertLanguageId('<html><style>foo| { }</style></html>', 'css');
		assertLanguageId('<html><style>foo { }|</style></html>', 'css');
		assertLanguageId('<html><style>foo { }</sty|le></html>', 'html');
	});

	test('Style content', function (): any {
		assertEmbeddedLanguageContent('<html><style>foo { }</style></html>', 'css', '             foo { }               ');
		assertEmbeddedLanguageContent('<html><script>var i = 0;</script></html>', 'css', '                                        ');
		assertEmbeddedLanguageContent('<html><style>foo { }</style>Hello<style>foo { }</style></html>', 'css', '             foo { }                    foo { }               ');
		assertEmbeddedLanguageContent('<html>\n  <style>\n    foo { }  \n  </style>\n</html>\n', 'css', '\n         \n    foo { }  \n  \n\n');

	});

	test('Scripts', function (): any {
		assertLanguageId('|<html><script>var i = 0;</script></html>', 'html');
		assertLanguageId('<html|><script>var i = 0;</script></html>', 'html');
		assertLanguageId('<html><scr|ipt>var i = 0;</script></html>', 'html');
		assertLanguageId('<html><script>|var i = 0;</script></html>', 'javascript');
		assertLanguageId('<html><script>var| i = 0;</script></html>', 'javascript');
		assertLanguageId('<html><script>var i = 0;|</script></html>', 'javascript');
		assertLanguageId('<html><script>var i = 0;</scr|ipt></html>', 'html');

		assertLanguageId('<script type="text/javascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="text/ecmascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/javascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/ecmascript">var| i = 0;</script>', 'javascript');
		assertLanguageId('<script type="application/typescript">var| i = 0;</script>', void 0);
		assertLanguageId('<script type=\'text/javascript\'>var| i = 0;</script>', 'javascript');
	});

	test('Script content', function (): any {
		assertEmbeddedLanguageContent('<html><script>var i = 0;</script></html>', 'javascript', '              var i = 0;                ');
		assertEmbeddedLanguageContent('<script type="text/javascript">var i = 0;</script>', 'javascript', '                               var i = 0;         ');
	});

});
开发者ID:,项目名称:,代码行数:70,代码来源:

示例9: provideFormattingEdits

import * as vscode from 'vscode';
import * as html from 'vscode-html-languageservice';
import * as lst from 'vscode-languageserver-types';
import { BladeFormatter, IBladeFormatterOptions } from "../services/BladeFormatter";

const service = html.getLanguageService()

export class BladeFormattingEditProvider implements vscode.DocumentFormattingEditProvider, vscode.DocumentRangeFormattingEditProvider 
{
    formatterOptions: IBladeFormatterOptions;
    
    provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
        let range = new vscode.Range(new vscode.Position(0, 0), new vscode.Position((document.lineCount - 1), Number.MAX_VALUE));
        return this.provideFormattingEdits(document, document.validateRange(range), options);
    }

    provideDocumentRangeFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {
        return this.provideFormattingEdits(document, range, options);
    }

    private provideFormattingEdits(document: vscode.TextDocument, range: vscode.Range, options: vscode.FormattingOptions): vscode.TextEdit[] {

        this.formatterOptions = {
            tabSize: options.tabSize,
            insertSpaces: options.insertSpaces
        };

        // format as html
        let doc = lst.TextDocument.create(document.uri.fsPath, 'html', 1, document.getText());
        let htmlTextEdit = service.format(doc, range, options);
开发者ID:onecentlin,项目名称:laravel-blade-snippets-vscode,代码行数:30,代码来源:BladeFormattingEditProvider.ts

示例10: getLanguageModes

export function getLanguageModes(supportedLanguages: { [languageId: string]: boolean; }): LanguageModes {

	var htmlLanguageService = getHTMLLanguageService();
	let htmlDocuments = getLanguageModelCache<HTMLDocument>(10, 60, document => htmlLanguageService.parseHTMLDocument(document));

	let modes = {
		'html': getHTMLMode(htmlLanguageService, htmlDocuments),
		'css': supportedLanguages['css'] && getCSSMode(htmlLanguageService, htmlDocuments),
		'javascript': supportedLanguages['javascript'] && getJavascriptMode(htmlLanguageService, htmlDocuments)
	};
	return {
		getModeAtPosition(document: TextDocument, position: Position): LanguageMode {
			let languageId = getLanguageAtPosition(htmlLanguageService, document, htmlDocuments.get(document), position);
			if (languageId) {
				return modes[languageId];
			}
			return null;
		},
		getAllModesInDocument(document: TextDocument): LanguageMode[] {
			let result = [];
			let languageIds = getLanguagesInContent(htmlLanguageService, document, htmlDocuments.get(document));
			for (let languageId of languageIds) {
				let mode = modes[languageId];
				if (mode) {
					result.push(mode);
				}
			}
			return result;
		},
		getAllModes(): LanguageMode[] {
			let result = [];
			for (let languageId in modes) {
				let mode = modes[languageId];
				if (mode) {
					result.push(mode);
				}
			}
			return result;
		},
		getMode(languageId: string): LanguageMode {
			return modes[languageId];
		}
	};
}
开发者ID:,项目名称:,代码行数:44,代码来源:


注:本文中的vscode-html-languageservice.getLanguageService函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。