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


TypeScript TextDocument.create方法代码示例

本文整理汇总了TypeScript中vscode-languageserver-types.TextDocument.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocument.create方法的具体用法?TypeScript TextDocument.create怎么用?TypeScript TextDocument.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode-languageserver-types.TextDocument的用法示例。


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

示例1: getEmbeddedDocumentByType

function getEmbeddedDocumentByType(
  document: TextDocument,
  contents: EmbeddedRegion[],
  type: EmbeddedType
): TextDocument {
  const oldContent = document.getText();
  let result = '';
  for (const c of contents) {
    if (c.type === type) {
      result = oldContent.substring(0, c.start).replace(/./g, ' ');
      result += oldContent.substring(c.start, c.end);
      return TextDocument.create(document.uri, c.languageId, document.version, result);
    }
  }
  return TextDocument.create(document.uri, defaultType[type], document.version, result);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:16,代码来源:embeddedSupport.ts

示例2: assertFormat

	function assertFormat(value: string, expected: string, options?: any): void {
		var languageModes = getLanguageModes({ css: true, javascript: true });
		if (options) {
			languageModes.getAllModes().forEach(m => m.configure(options));
		}

		let rangeStartOffset = value.indexOf('|');
		let rangeEndOffset;
		if (rangeStartOffset !== -1) {
			value = value.substr(0, rangeStartOffset) + value.substr(rangeStartOffset + 1);

			rangeEndOffset = value.indexOf('|');
			value = value.substr(0, rangeEndOffset) + value.substr(rangeEndOffset + 1);
		} else {
			rangeStartOffset = 0;
			rangeEndOffset = value.length;
		}
		let document = TextDocument.create('test://test/test.html', 'html', 0, value);
		let range = Range.create(document.positionAt(rangeStartOffset), document.positionAt(rangeEndOffset));
		let formatOptions = FormattingOptions.create(2, true);

		let ranges = languageModes.getModesInRange(document, range);
		let result: TextEdit[] = [];
		ranges.forEach(r => {
			let mode = r.mode;
			if (mode && mode.format) {
				let edits = mode.format(document, r, formatOptions);
				pushAll(result, edits);
			}
		});
		let actual = applyEdits(document, result);
		assert.equal(actual, expected);
	}
开发者ID:StateFarmIns,项目名称:vscode,代码行数:33,代码来源:formatting.test.ts

示例3: assertCompletions

	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);
			}
		}
	}
开发者ID:sameer-coder,项目名称:vscode,代码行数:31,代码来源:completions.test.ts

示例4: testCompletionFor

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 }, workspace);
	var mode = languageModes.getModeAtPosition(document, position)!;

	let list = mode.doComplete!(document, position);

	if (expected.count) {
		assert.equal(list.items, expected.count);
	}
	if (expected.items) {
		for (let item of expected.items) {
			assertCompletion(list, item, document, offset);
		}
	}
}
开发者ID:AllureFer,项目名称:vscode,代码行数:26,代码来源:completions.test.ts

示例5: assertFontFace

function assertFontFace(input: string, ...rules: Rule[]): void {
	let p = new SCSSParser();
	let document = TextDocument.create('test://test/test.scss', 'scss', 0, input);
	let node = p.internalParse(input, p._parseFontFace);

	assertEntries(node, document, rules);
}
开发者ID:Microsoft,项目名称:vscode-css-languageservice,代码行数:7,代码来源:lint.test.ts

示例6: assertEmbeddedLanguageContent

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

示例7: assertCompletions

	function assertCompletions(value: string, expected: { count?: number, items?: ItemDescription[] }, testUri: string, workspaceFolders?: WorkspaceFolder[], lang: string = 'css'): void {
		const offset = value.indexOf('|');
		value = value.substr(0, offset) + value.substr(offset + 1);

		const document = TextDocument.create(testUri, lang, 0, value);
		const position = document.positionAt(offset);

		if (!workspaceFolders) {
			workspaceFolders = [{ name: 'x', uri: testUri.substr(0, testUri.lastIndexOf('/')) }];
		}

		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);
			}
		}
	}
开发者ID:developers23,项目名称:vscode,代码行数:27,代码来源:completion.test.ts

示例8: assertCompletions

	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(', '));
		}

	}
开发者ID:costincaraivan,项目名称:vscode,代码行数:31,代码来源:emmet.test.ts

示例9: test

	test('inserts', function (): any {
		let input = TextDocument.create('foo://bar/f', 'html', 0, '012345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 0), 'Hello')]), 'Hello012345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 1), 'Hello')]), '0Hello12345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 1), 'Hello'), TextEdit.insert(Position.create(0, 1), 'World')]), '0HelloWorld12345678901234567890123456789');
		assert.equal(applyEdits(input, [TextEdit.insert(Position.create(0, 2), 'One'), TextEdit.insert(Position.create(0, 1), 'Hello'), TextEdit.insert(Position.create(0, 1), 'World'), TextEdit.insert(Position.create(0, 2), 'Two'), TextEdit.insert(Position.create(0, 2), 'Three')]), '0HelloWorld1OneTwoThree2345678901234567890123456789');
	});
开发者ID:sameer-coder,项目名称:vscode,代码行数:7,代码来源:utils.test.ts

示例10: assertCompletions

	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);
		}

	}
开发者ID:sameer-coder,项目名称:vscode,代码行数:29,代码来源:emmet.test.ts


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