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


TypeScript IConnection.onDocumentRangeFormatting方法代码示例

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


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

示例1: format

connection.onSignatureHelp(signatureHelpParms => {
	let document = documents.get(signatureHelpParms.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, signatureHelpParms.position);
	if (mode && mode.doSignatureHelp) {
		return mode.doSignatureHelp(document, signatureHelpParms.position);
	}
	return null;
});

connection.onDocumentRangeFormatting(async formatParams => {
	let document = documents.get(formatParams.textDocument.uri);
	let settings = await getDocumentSettings(document, () => true);
	if (!settings) {
		settings = globalSettings;
	}
	let unformattedTags: string = settings && settings.html && settings.html.format && settings.html.format.unformatted || '';
	let enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/) };

	return format(languageModes, document, formatParams.range, formatParams.options, settings, enabledModes);
});

connection.onDocumentLinks(documentLinkParam => {
	let document = documents.get(documentLinkParam.textDocument.uri);
	let documentContext: DocumentContext = {
		resolveReference: (ref, base) => {
			if (base) {
				ref = url.resolve(base, ref);
			}
			if (workspacePath && ref[0] === '/') {
				return uri.file(path.join(workspacePath, ref)).toString();
开发者ID:armanio123,项目名称:vscode,代码行数:30,代码来源:htmlServerMain.ts

示例2:

	let document = documents.get(signatureHelpParms.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, signatureHelpParms.position);
	if (mode && mode.doSignatureHelp) {
		return mode.doSignatureHelp(document, signatureHelpParms.position);
	}
	return null;
});

connection.onDocumentRangeFormatting(formatParams => {
	let document = documents.get(formatParams.textDocument.uri);
	let ranges = languageModes.getModesInRange(document, formatParams.range);
	let result: TextEdit[] = [];
	let unformattedTags: string = settings && settings.html && settings.html.format && settings.html.format.unformatted || '';
	let enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/), html: true };
	ranges.forEach(r => {
		let mode = r.mode;
		if (mode && mode.format && enabledModes[mode.getId()] && !r.attributeValue) {
			let edits = mode.format(document, r, formatParams.options);
			pushAll(result, edits);
		}
	});
	return result;
});

connection.onDocumentLinks(documentLinkParam => {
	let document = documents.get(documentLinkParam.textDocument.uri);
	let documentContext: DocumentContext = {
		resolveReference: ref => {
			if (workspacePath && ref[0] === '/') {
				return uri.file(path.join(workspacePath, ref)).toString();
			}
开发者ID:StateFarmIns,项目名称:vscode,代码行数:31,代码来源:htmlServerMain.ts

示例3:

});

connection.onSignatureHelp(signatureHelpParms => {
	let document = documents.get(signatureHelpParms.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, signatureHelpParms.position);
	if (mode && mode.doSignatureHelp) {
		return mode.doSignatureHelp(document, signatureHelpParms.position);
	}
	return null;
});

connection.onDocumentRangeFormatting(formatParams => {
	let document = documents.get(formatParams.textDocument.uri);
	let startMode = languageModes.getModeAtPosition(document, formatParams.range.start);
	let endMode = languageModes.getModeAtPosition(document, formatParams.range.end);
	if (startMode && startMode === endMode && startMode.format) {
		return startMode.format(document, formatParams.range, formatParams.options);
	}
	return null;
});

connection.onDocumentLinks(documentLinkParam => {
	let document = documents.get(documentLinkParam.textDocument.uri);
	let documentContext: DocumentContext = {
		resolveReference: ref => {
			if (workspacePath && ref[0] === '/') {
				return uri.file(path.join(workspacePath, ref)).toString();
			}
			return url.resolve(document.uri, ref);
		}
	};
开发者ID:,项目名称:,代码行数:31,代码来源:

示例4: format

	return [];
});

connection.onSignatureHelp(signatureHelpParms => {
	let document = documents.get(signatureHelpParms.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, signatureHelpParms.position);
	if (mode && mode.doSignatureHelp) {
		return mode.doSignatureHelp(document, signatureHelpParms.position);
	}
	return null;
});

connection.onDocumentRangeFormatting(formatParams => {
	let document = documents.get(formatParams.textDocument.uri);

	let unformattedTags: string = settings && settings.html && settings.html.format && settings.html.format.unformatted || '';
	let enabledModes = { css: !unformattedTags.match(/\bstyle\b/), javascript: !unformattedTags.match(/\bscript\b/) };

	return format(languageModes, document, formatParams.range, formatParams.options, enabledModes);
});

connection.onDocumentLinks(documentLinkParam => {
	let document = documents.get(documentLinkParam.textDocument.uri);
	let documentContext: DocumentContext = {
		resolveReference: ref => {
			if (workspacePath && ref[0] === '/') {
				return uri.file(path.join(workspacePath, ref)).toString();
			}
			return url.resolve(document.uri, ref);
		}
	};
	let links: DocumentLink[] = [];
开发者ID:diarmaidm,项目名称:vscode,代码行数:32,代码来源:htmlServerMain.ts


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