當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Range.create方法代碼示例

本文整理匯總了TypeScript中vscode-languageserver-types.Range.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Range.create方法的具體用法?TypeScript Range.create怎麽用?TypeScript Range.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vscode-languageserver-types.Range的用法示例。


在下文中一共展示了Range.create方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: convertRange

function convertRange(document: TextDocument, span: { start: number, length: number }): Range {
	let startPosition = document.positionAt(span.start);
	let endPosition = document.positionAt(span.start + span.length);
	return Range.create(startPosition, endPosition);
}
開發者ID:,項目名稱:,代碼行數:5,代碼來源:

示例2: createDiagnostic

function createDiagnostic(msg: string, range?: Range): Diagnostic {
  range = range ? range : Range.create(0, 0, 0, 1)
  return Diagnostic.create(range, msg)
}
開發者ID:illarionvk,項目名稱:dotfiles,代碼行數:4,代碼來源:diagnosticCollection.test.ts

示例3: format

export function format(languageModes: LanguageModes, document: TextDocument, formatRange: Range, formattingOptions: FormattingOptions, settings: Settings, enabledModes: { [mode: string]: boolean }) {
	let result: TextEdit[] = [];

	let endPos = formatRange.end;
	let endOffset = document.offsetAt(endPos);
	let content = document.getText();
	if (endPos.character === 0 && endPos.line > 0 && endOffset !== content.length) {
		// if selection ends after a new line, exclude that new line
		let prevLineStart = document.offsetAt(Position.create(endPos.line - 1, 0));
		while (isEOL(content, endOffset - 1) && endOffset > prevLineStart) {
			endOffset--;
		}
		formatRange = Range.create(formatRange.start, document.positionAt(endOffset));
	}


	// run the html formatter on the full range and pass the result content to the embedded formatters.
	// from the final content create a single edit
	// advantages of this approach are
	//  - correct indents in the html document
	//  - correct initial indent for embedded formatters
	//  - no worrying of overlapping edits

	// make sure we start in html
	let allRanges = languageModes.getModesInRange(document, formatRange);
	let i = 0;
	let startPos = formatRange.start;
	while (i < allRanges.length && allRanges[i].mode.getId() !== 'html') {
		let range = allRanges[i];
		if (!range.attributeValue && range.mode.format) {
			let edits = range.mode.format(document, Range.create(startPos, range.end), formattingOptions, settings);
			pushAll(result, edits);
		}
		startPos = range.end;
		i++;
	}
	if (i === allRanges.length) {
		return result;
	}
	// modify the range
	formatRange = Range.create(startPos, formatRange.end);

	// perform a html format and apply changes to a new document
	let htmlMode = languageModes.getMode('html');
	let htmlEdits = htmlMode.format(document, formatRange, formattingOptions, settings);
	let htmlFormattedContent = applyEdits(document, htmlEdits);
	let newDocument = TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent);
	try {
		// run embedded formatters on html formatted content: - formatters see correct initial indent
		let afterFormatRangeLength = document.getText().length - document.offsetAt(formatRange.end); // length of unchanged content after replace range
		let newFormatRange = Range.create(formatRange.start, newDocument.positionAt(htmlFormattedContent.length - afterFormatRangeLength));
		let embeddedRanges = languageModes.getModesInRange(newDocument, newFormatRange);

		let embeddedEdits: TextEdit[] = [];

		for (let r of embeddedRanges) {
			let mode = r.mode;
			if (mode && mode.format && enabledModes[mode.getId()] && !r.attributeValue) {
				let edits = mode.format(newDocument, r, formattingOptions, settings);
				for (let edit of edits) {
					embeddedEdits.push(edit);
				}
			}
		};

		if (embeddedEdits.length === 0) {
			pushAll(result, htmlEdits);
			return result;
		}

		// apply all embedded format edits and create a single edit for all changes
		let resultContent = applyEdits(newDocument, embeddedEdits);
		let resultReplaceText = resultContent.substring(document.offsetAt(formatRange.start), resultContent.length - afterFormatRangeLength);

		result.push(TextEdit.replace(formatRange, resultReplaceText));
		return result;
	} finally {
		languageModes.onDocumentRemoved(newDocument);
	}

}
開發者ID:armanio123,項目名稱:vscode,代碼行數:81,代碼來源:formatting.ts

示例4: convertRange

function convertRange(document: TextDocument, span: ts.TextSpan): Range {
  const startPosition = document.positionAt(span.start);
  const endPosition = document.positionAt(span.start + span.length);
  return Range.create(startPosition, endPosition);
}
開發者ID:tiravata,項目名稱:vetur,代碼行數:5,代碼來源:javascript.ts

示例5: shiftRange

function shiftRange(range: Range, startOffset: number, endOffset: number): Range {
	const start = shiftPosition(range.start, startOffset);
	const end = shiftPosition(range.end, endOffset);
	return Range.create(start, end);
}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:5,代碼來源:pathCompletion.ts


注:本文中的vscode-languageserver-types.Range.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。